diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-09-09 13:35:56 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-09-09 13:46:15 +0300 |
commit | 4de36153bfd57bcb4877b408a4d11138c117fdfb (patch) | |
tree | f2497698cad7e0fb501ab157b2fa43dab5b7027b | |
parent | b71200a74b88aef430320231935d3bb2e394b24b (diff) | |
download | ydb-4de36153bfd57bcb4877b408a4d11138c117fdfb.tar.gz |
Intermediate changes
-rw-r--r-- | yt/yt/client/cache/cache.cpp | 26 | ||||
-rw-r--r-- | yt/yt/client/cache/cache.h | 5 | ||||
-rw-r--r-- | yt/yt/client/cache/config.cpp | 13 | ||||
-rw-r--r-- | yt/yt/client/cache/config.h | 16 | ||||
-rw-r--r-- | yt/yt/client/cache/public.h | 1 |
5 files changed, 53 insertions, 8 deletions
diff --git a/yt/yt/client/cache/cache.cpp b/yt/yt/client/cache/cache.cpp index 95a7386103..8e830ee9b0 100644 --- a/yt/yt/client/cache/cache.cpp +++ b/yt/yt/client/cache/cache.cpp @@ -46,10 +46,14 @@ TConnectionConfigPtr MakeClusterConfig( { auto [cluster, proxyRole] = ExtractClusterAndProxyRole(clusterUrl); auto it = clustersConfig->ClusterConfigs.find(GetNormalClusterName(cluster)); - auto config = (it != clustersConfig->ClusterConfigs.end()) ? it->second : clustersConfig->DefaultConfig; + const bool useDefaultConfig = (it == clustersConfig->ClusterConfigs.end()); + const auto& config = useDefaultConfig ? clustersConfig->DefaultConfig : it->second; auto newConfig = CloneYsonStruct(config, /*postprocess*/ false, /*setDefaults*/ false); - newConfig->ClusterUrl = ToString(cluster); + // Ignore cluster url from DefaultConfig, but use it from ClusterConfigs[_] if it is set. + if (useDefaultConfig || !newConfig->ClusterUrl.has_value() || newConfig->ClusterUrl->empty()) { + newConfig->ClusterUrl = ToString(cluster); + } newConfig->ClusterName = InferYTClusterFromClusterUrl(*newConfig->ClusterUrl); if (!proxyRole.empty()) { newConfig->ProxyRole = ToString(proxyRole); @@ -67,20 +71,21 @@ class TClientsCache : public TClientsCacheBase { public: - TClientsCache(const TClientsCacheConfigPtr& config, const NApi::TClientOptions& options) + TClientsCache(const TClientsCacheConfigPtr& config, const TClientsCacheAuthentificationOptionsPtr& clientsOptions) : ClustersConfig_(GetClustersConfigWithNormalClusterName(config)) - , Options_(options) + , ClientsOptions_(clientsOptions) { } protected: NApi::IClientPtr CreateClient(TStringBuf clusterUrl) override { - return NCache::CreateClient(MakeClusterConfig(ClustersConfig_, clusterUrl), Options_); + auto& options = ClientsOptions_->ClusterOptions.ValueRef(clusterUrl, ClientsOptions_->DefaultOptions); + return NCache::CreateClient(MakeClusterConfig(ClustersConfig_, clusterUrl), options); } private: const TClientsCacheConfigPtr ClustersConfig_; - const NApi::TClientOptions Options_; + const TClientsCacheAuthentificationOptionsPtr ClientsOptions_; }; //////////////////////////////////////////////////////////////////////////////// @@ -89,8 +94,15 @@ private: //////////////////////////////////////////////////////////////////////////////// -IClientsCachePtr CreateClientsCache(const TClientsCacheConfigPtr& config, const NApi::TClientOptions& options) +IClientsCachePtr CreateClientsCache(const TClientsCacheConfigPtr& config, const TClientsCacheAuthentificationOptionsPtr& options) +{ + return New<TClientsCache>(config, options); +} + +IClientsCachePtr CreateClientsCache(const TClientsCacheConfigPtr& config, const NApi::TClientOptions& defaultOptions) { + auto options = New<TClientsCacheAuthentificationOptions>(); + options->DefaultOptions = defaultOptions; return New<TClientsCache>(config, options); } diff --git a/yt/yt/client/cache/cache.h b/yt/yt/client/cache/cache.h index 98caf4e50b..4cc842d753 100644 --- a/yt/yt/client/cache/cache.h +++ b/yt/yt/client/cache/cache.h @@ -24,7 +24,10 @@ DEFINE_REFCOUNTED_TYPE(IClientsCache) //////////////////////////////////////////////////////////////////////////////// //! Creates clients cache which explicitly given config. Server name is always overwritten with requested. -IClientsCachePtr CreateClientsCache(const TClientsCacheConfigPtr& config, const NApi::TClientOptions& options); +IClientsCachePtr CreateClientsCache(const TClientsCacheConfigPtr& config, const TClientsCacheAuthentificationOptionsPtr& options); + +//! Creates clients cache which shares same options. +IClientsCachePtr CreateClientsCache(const TClientsCacheConfigPtr& config, const NApi::TClientOptions& defaultClientOptions); //! Creates clients cache which shares same config (except server name). IClientsCachePtr CreateClientsCache( diff --git a/yt/yt/client/cache/config.cpp b/yt/yt/client/cache/config.cpp index ad79cda00f..7ebaeed178 100644 --- a/yt/yt/client/cache/config.cpp +++ b/yt/yt/client/cache/config.cpp @@ -1,7 +1,11 @@ #include "config.h" +#include <yt/yt/client/api/options.h> + namespace NYT::NClient::NCache { +using namespace NApi; + //////////////////////////////////////////////////////////////////////////////// void TClientsCacheConfig::Register(TRegistrar registrar) @@ -14,4 +18,13 @@ void TClientsCacheConfig::Register(TRegistrar registrar) //////////////////////////////////////////////////////////////////////////////// +TClientsCacheAuthentificationOptionsPtr TClientsCacheAuthentificationOptions::GetFromEnvStatic() +{ + auto options = New<TClientsCacheAuthentificationOptions>(); + options->DefaultOptions = GetClientOptionsFromEnvStatic(); + return options; +} + +//////////////////////////////////////////////////////////////////////////////// + } // namespace NYT::NClient::NHedging::NRpc diff --git a/yt/yt/client/cache/config.h b/yt/yt/client/cache/config.h index f05fcdfd96..76d7d286b0 100644 --- a/yt/yt/client/cache/config.h +++ b/yt/yt/client/cache/config.h @@ -6,6 +6,9 @@ #include <yt/yt/core/ytree/yson_struct.h> +#include <yt/yt/library/auth/authentication_options.h> + +#include <util/generic/hash.h> #include <util/generic/vector.h> namespace NYT::NClient::NCache { @@ -28,4 +31,17 @@ DEFINE_REFCOUNTED_TYPE(TClientsCacheConfig) //////////////////////////////////////////////////////////////////////////////// +struct TClientsCacheAuthentificationOptions final +{ + // Get options with `DefaultOptions` filled from env. + static TClientsCacheAuthentificationOptionsPtr GetFromEnvStatic(); + + NAuth::TAuthenticationOptions DefaultOptions; + THashMap<TString, NAuth::TAuthenticationOptions> ClusterOptions; +}; + +DEFINE_REFCOUNTED_TYPE(TClientsCacheAuthentificationOptions) + +//////////////////////////////////////////////////////////////////////////////// + } // namespace NYT::NClient::NHedging::NRpc diff --git a/yt/yt/client/cache/public.h b/yt/yt/client/cache/public.h index 96667e2da8..c03e980325 100644 --- a/yt/yt/client/cache/public.h +++ b/yt/yt/client/cache/public.h @@ -8,6 +8,7 @@ namespace NYT::NClient::NCache { DECLARE_REFCOUNTED_STRUCT(IClientsCache) DECLARE_REFCOUNTED_STRUCT(TClientsCacheConfig) +DECLARE_REFCOUNTED_STRUCT(TClientsCacheAuthentificationOptions) //////////////////////////////////////////////////////////////////////////////// |