diff options
| author | ermolovd <[email protected]> | 2025-05-15 09:51:45 +0300 |
|---|---|---|
| committer | ermolovd <[email protected]> | 2025-05-15 10:27:38 +0300 |
| commit | 8dddd957785dee5dc7205c71faba7749e19b3ece (patch) | |
| tree | d19bb024c911213b10b78836bc8c05663c0a4cd0 | |
| parent | fd762fef44d3e2e9cf83efd5d77e99108684d18d (diff) | |
YT-24967: add get_current_user method
* Changelog entry
Type: feature
Component: proxy/rpc-proxy
Introduce get_current_user method in rpc and http proxies
commit_hash:af7e968e1d2bfbcf94f981b9d684a9f0d3d37d4b
| -rw-r--r-- | yt/yt/client/api/delegating_client.h | 4 | ||||
| -rw-r--r-- | yt/yt/client/api/public.h | 4 | ||||
| -rw-r--r-- | yt/yt/client/api/rpc_proxy/api_service_proxy.h | 1 | ||||
| -rw-r--r-- | yt/yt/client/api/rpc_proxy/client_impl.cpp | 14 | ||||
| -rw-r--r-- | yt/yt/client/api/rpc_proxy/client_impl.h | 3 | ||||
| -rw-r--r-- | yt/yt/client/api/security_client.cpp | 6 | ||||
| -rw-r--r-- | yt/yt/client/api/security_client.h | 20 | ||||
| -rw-r--r-- | yt/yt/client/driver/driver.cpp | 2 | ||||
| -rw-r--r-- | yt/yt/client/driver/etc_commands.cpp | 10 | ||||
| -rw-r--r-- | yt/yt/client/driver/etc_commands.h | 15 | ||||
| -rw-r--r-- | yt/yt/client/federated/client.cpp | 6 | ||||
| -rw-r--r-- | yt/yt/client/hedging/hedging.cpp | 1 | ||||
| -rw-r--r-- | yt/yt/client/unittests/mock/client.h | 4 | ||||
| -rw-r--r-- | yt/yt_proto/yt/client/api/rpc_proxy/proto/api_service.proto | 9 |
14 files changed, 97 insertions, 2 deletions
diff --git a/yt/yt/client/api/delegating_client.h b/yt/yt/client/api/delegating_client.h index 97844d8e53d..2523ad9c1b2 100644 --- a/yt/yt/client/api/delegating_client.h +++ b/yt/yt/client/api/delegating_client.h @@ -768,6 +768,10 @@ public: const TListUserTokensOptions& options), (user, passwordSha256, options)) + DELEGATE_METHOD(TFuture<TGetCurrentUserResultPtr>, GetCurrentUser, ( + const TGetCurrentUserOptions& options), + (options)) + // Query tracker DELEGATE_METHOD(TFuture<NQueryTrackerClient::TQueryId>, StartQuery, ( NQueryTrackerClient::EQueryEngine engine, diff --git a/yt/yt/client/api/public.h b/yt/yt/client/api/public.h index a215a385173..f8aafb33322 100644 --- a/yt/yt/client/api/public.h +++ b/yt/yt/client/api/public.h @@ -135,6 +135,8 @@ struct TTabletRangeOptions; struct TGetFileFromCacheResult; struct TPutFileToCacheResult; +struct TGetCurrentUserOptions; + DECLARE_REFCOUNTED_STRUCT(IConnection) DECLARE_REFCOUNTED_STRUCT(IClientBase) DECLARE_REFCOUNTED_STRUCT(IClient) @@ -198,6 +200,8 @@ DECLARE_REFCOUNTED_STRUCT(TListOperationsAccessFilter) DECLARE_REFCOUNTED_STRUCT(TShuffleHandle) +DECLARE_REFCOUNTED_STRUCT(TGetCurrentUserResult); + //////////////////////////////////////////////////////////////////////////////// inline const NYPath::TYPath ClusterNamePath("//sys/@cluster_name"); diff --git a/yt/yt/client/api/rpc_proxy/api_service_proxy.h b/yt/yt/client/api/rpc_proxy/api_service_proxy.h index baf3577fd4a..d42698b5dd2 100644 --- a/yt/yt/client/api/rpc_proxy/api_service_proxy.h +++ b/yt/yt/client/api/rpc_proxy/api_service_proxy.h @@ -181,6 +181,7 @@ public: DEFINE_RPC_PROXY_METHOD(NRpcProxy::NProto, RequestRestart); // Security + DEFINE_RPC_PROXY_METHOD(NRpcProxy::NProto, GetCurrentUser); DEFINE_RPC_PROXY_METHOD(NRpcProxy::NProto, AddMember); DEFINE_RPC_PROXY_METHOD(NRpcProxy::NProto, RemoveMember); DEFINE_RPC_PROXY_METHOD(NRpcProxy::NProto, CheckPermission); diff --git a/yt/yt/client/api/rpc_proxy/client_impl.cpp b/yt/yt/client/api/rpc_proxy/client_impl.cpp index c2ff601d4a6..0e6583641e7 100644 --- a/yt/yt/client/api/rpc_proxy/client_impl.cpp +++ b/yt/yt/client/api/rpc_proxy/client_impl.cpp @@ -967,6 +967,20 @@ TFuture<void> TClient::RemoveQueueProducerSession( return req->Invoke().AsVoid(); } +TFuture<TGetCurrentUserResultPtr> TClient::GetCurrentUser(const TGetCurrentUserOptions& options) +{ + auto proxy = CreateApiServiceProxy(); + + auto req = proxy.GetCurrentUser(); + SetTimeoutOptions(*req, options); + + return req->Invoke().Apply(BIND([] (const TApiServiceProxy::TRspGetCurrentUserPtr& rsp) { + auto response = New<TGetCurrentUserResult>(); + response->User = rsp->user(); + return response; + })); +} + TFuture<void> TClient::AddMember( const TString& group, const TString& member, diff --git a/yt/yt/client/api/rpc_proxy/client_impl.h b/yt/yt/client/api/rpc_proxy/client_impl.h index 5bff7eadd90..b4000a0cc4e 100644 --- a/yt/yt/client/api/rpc_proxy/client_impl.h +++ b/yt/yt/client/api/rpc_proxy/client_impl.h @@ -197,6 +197,9 @@ public: const NApi::TPutFileToCacheOptions& options) override; // Security. + TFuture<TGetCurrentUserResultPtr> GetCurrentUser( + const TGetCurrentUserOptions& options) override; + TFuture<void> AddMember( const TString& group, const TString& member, diff --git a/yt/yt/client/api/security_client.cpp b/yt/yt/client/api/security_client.cpp index f30a2886149..6a5258f0cc8 100644 --- a/yt/yt/client/api/security_client.cpp +++ b/yt/yt/client/api/security_client.cpp @@ -86,7 +86,11 @@ TError TCheckPermissionByAclResult::ToError(const std::string& user, EPermission } } +void TGetCurrentUserResult::Register(TRegistrar registrar) +{ + registrar.Parameter("user", &TThis::User); +} + //////////////////////////////////////////////////////////////////////////////// } // namespace NYT::NApi - diff --git a/yt/yt/client/api/security_client.h b/yt/yt/client/api/security_client.h index d2d4bccc011..23a37b1a428 100644 --- a/yt/yt/client/api/security_client.h +++ b/yt/yt/client/api/security_client.h @@ -115,12 +115,31 @@ struct TListUserTokensResult THashMap<TString, NYson::TYsonString> Metadata; }; +struct TGetCurrentUserOptions + : public TTimeoutOptions +{ }; + +struct TGetCurrentUserResult + : public NYTree::TYsonStruct +{ + std::string User; + + REGISTER_YSON_STRUCT(TGetCurrentUserResult); + static void Register(TRegistrar registrar); +}; + +DEFINE_REFCOUNTED_TYPE(TGetCurrentUserResult); + //////////////////////////////////////////////////////////////////////////////// struct ISecurityClient { virtual ~ISecurityClient() = default; + //! Return information about current user. + virtual TFuture<TGetCurrentUserResultPtr> GetCurrentUser( + const TGetCurrentUserOptions& options = {}) = 0; + virtual TFuture<void> AddMember( const TString& group, const TString& member, @@ -171,4 +190,3 @@ struct ISecurityClient //////////////////////////////////////////////////////////////////////////////// } // namespace NYT::NApi - diff --git a/yt/yt/client/driver/driver.cpp b/yt/yt/client/driver/driver.cpp index 72794540aa2..cae22f4dd0a 100644 --- a/yt/yt/client/driver/driver.cpp +++ b/yt/yt/client/driver/driver.cpp @@ -351,6 +351,8 @@ public: REGISTER_ALL(TResurrectChunkLocationsCommand, "resurrect_chunk_locations", Null, Structured, true, false); REGISTER_ALL(TRequestRestartCommand, "request_restart", Null, Structured, true, false); + REGISTER (TGetCurrentUserCommand, "get_current_user", Null, Structured, false, false, ApiVersion4); + REGISTER_ALL(TSetUserPasswordCommand, "set_user_password", Null, Structured, true, false); REGISTER_ALL(TIssueTokenCommand, "issue_token", Null, Structured, true, false); REGISTER_ALL(TRevokeTokenCommand, "revoke_token", Null, Structured, true, false); diff --git a/yt/yt/client/driver/etc_commands.cpp b/yt/yt/client/driver/etc_commands.cpp index f7097141def..b6f2e40ae04 100644 --- a/yt/yt/client/driver/etc_commands.cpp +++ b/yt/yt/client/driver/etc_commands.cpp @@ -29,6 +29,16 @@ using namespace NApi; //////////////////////////////////////////////////////////////////////////////// +void TGetCurrentUserCommand::DoExecute(ICommandContextPtr context) +{ + auto userInfo = WaitFor(context->GetClient()->GetCurrentUser()) + .ValueOrThrow(); + + context->ProduceOutputValue(ConvertToYsonString(userInfo)); +} + +//////////////////////////////////////////////////////////////////////////////// + void TAddMemberCommand::DoExecute(ICommandContextPtr context) { WaitFor(context->GetClient()->AddMember( diff --git a/yt/yt/client/driver/etc_commands.h b/yt/yt/client/driver/etc_commands.h index e6cbb4aa2de..a63ef6ea922 100644 --- a/yt/yt/client/driver/etc_commands.h +++ b/yt/yt/client/driver/etc_commands.h @@ -33,6 +33,21 @@ protected: //////////////////////////////////////////////////////////////////////////////// +class TGetCurrentUserCommand + : public TCommandBase +{ +public: + REGISTER_YSON_STRUCT_LITE(TGetCurrentUserCommand); + + static void Register(TRegistrar) + { } + +private: + void DoExecute(ICommandContextPtr context) override; +}; + +//////////////////////////////////////////////////////////////////////////////// + class TAddMemberCommand : public TUpdateMembershipCommand<NApi::TAddMemberOptions> { diff --git a/yt/yt/client/federated/client.cpp b/yt/yt/client/federated/client.cpp index 0102d3c39cf..9e7651eed9c 100644 --- a/yt/yt/client/federated/client.cpp +++ b/yt/yt/client/federated/client.cpp @@ -354,6 +354,12 @@ public: void Terminate() override { } + TFuture<TGetCurrentUserResultPtr> GetCurrentUser(const TGetCurrentUserOptions& options) override + { + auto [client, _] = GetActiveClient(); + return client->GetCurrentUser(options); + } + // IClientBase unsupported methods. UNIMPLEMENTED_METHOD(TFuture<void>, SetNode, (const NYPath::TYPath&, const NYson::TYsonString&, const TSetNodeOptions&)); UNIMPLEMENTED_METHOD(TFuture<void>, MultisetAttributesNode, (const NYPath::TYPath&, const NYTree::IMapNodePtr&, const TMultisetAttributesNodeOptions&)); diff --git a/yt/yt/client/hedging/hedging.cpp b/yt/yt/client/hedging/hedging.cpp index e6631702bf6..2226775a728 100644 --- a/yt/yt/client/hedging/hedging.cpp +++ b/yt/yt/client/hedging/hedging.cpp @@ -149,6 +149,7 @@ public: UNSUPPORTED_METHOD(TFuture<void>, TruncateJournal, (const TYPath&, i64, const TTruncateJournalOptions&)); UNSUPPORTED_METHOD(TFuture<TGetFileFromCacheResult>, GetFileFromCache, (const TString&, const TGetFileFromCacheOptions&)); UNSUPPORTED_METHOD(TFuture<TPutFileToCacheResult>, PutFileToCache, (const TYPath&, const TString&, const TPutFileToCacheOptions&)); + UNSUPPORTED_METHOD(TFuture<TGetCurrentUserResultPtr>, GetCurrentUser, (const TGetCurrentUserOptions&)); UNSUPPORTED_METHOD(TFuture<void>, AddMember, (const TString&, const TString&, const TAddMemberOptions&)); UNSUPPORTED_METHOD(TFuture<void>, RemoveMember, (const TString&, const TString&, const TRemoveMemberOptions&)); UNSUPPORTED_METHOD(TFuture<TCheckPermissionResponse>, CheckPermission, (const std::string&, const TYPath&, NYTree::EPermission, const TCheckPermissionOptions&)); diff --git a/yt/yt/client/unittests/mock/client.h b/yt/yt/client/unittests/mock/client.h index 22accc2ed1c..0ce8f14023f 100644 --- a/yt/yt/client/unittests/mock/client.h +++ b/yt/yt/client/unittests/mock/client.h @@ -545,6 +545,10 @@ public: const TPutFileToCacheOptions& options), (override)); + MOCK_METHOD(TFuture<TGetCurrentUserResultPtr>, GetCurrentUser, ( + const TGetCurrentUserOptions& options), + (override)); + MOCK_METHOD(TFuture<void>, AddMember, ( const TString& group, const TString& member, diff --git a/yt/yt_proto/yt/client/api/rpc_proxy/proto/api_service.proto b/yt/yt_proto/yt/client/api/rpc_proxy/proto/api_service.proto index b8130a8b7a5..bdd3bbd4c41 100644 --- a/yt/yt_proto/yt/client/api/rpc_proxy/proto/api_service.proto +++ b/yt/yt_proto/yt/client/api/rpc_proxy/proto/api_service.proto @@ -2828,6 +2828,15 @@ message TRspGetJobInput // ETC //////////////////////////////////////////////////////////////////////////////// +message TReqGetCurrentUser +{ +} + +message TRspGetCurrentUser +{ + required string user = 1; +} + message TReqAddMember { required string group = 1; |
