aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwhatsername <whatsername@yandex-team.com>2023-11-15 20:29:00 +0300
committerwhatsername <whatsername@yandex-team.com>2023-11-15 21:26:50 +0300
commitf2ed702991f7f223ce4e47c08976553dd9a3c6cc (patch)
tree1ca51d7f9f3dcca5f3a8acf42809abfc2caee939
parenta1fb0b04b1fc479321dcaf3b6528e58941cfb87f (diff)
downloadydb-f2ed702991f7f223ce4e47c08976553dd9a3c6cc.tar.gz
YT-20029: Support url schema for YT_PROXY
Example YT_PROXY=https://freud.yt.yandex.net
-rw-r--r--yt/cpp/mapreduce/client/client.cpp34
-rw-r--r--yt/cpp/mapreduce/interface/client_method_options.h2
2 files changed, 29 insertions, 7 deletions
diff --git a/yt/cpp/mapreduce/client/client.cpp b/yt/cpp/mapreduce/client/client.cpp
index 29d134ad3d..62eb1e0139 100644
--- a/yt/cpp/mapreduce/client/client.cpp
+++ b/yt/cpp/mapreduce/client/client.cpp
@@ -1295,25 +1295,47 @@ TClientPtr CreateClientImpl(
TClientContext context;
context.Config = options.Config_ ? options.Config_ : TConfig::Get();
context.TvmOnly = options.TvmOnly_;
- context.UseTLS = options.UseTLS_;
context.ProxyAddress = options.ProxyAddress_;
context.ServerName = serverName;
- if (serverName.find('.') == TString::npos &&
- serverName.find(':') == TString::npos)
+ if (context.ServerName.find('.') == TString::npos &&
+ context.ServerName.find(':') == TString::npos)
{
context.ServerName += ".yt.yandex.net";
}
- if (serverName.find(':') == TString::npos) {
+ static constexpr char httpUrlSchema[] = "http://";
+ static constexpr char httpsUrlSchema[] = "https://";
+ if (options.UseTLS_) {
+ context.UseTLS = *options.UseTLS_;
+ } else {
+ context.UseTLS = context.ServerName.StartsWith(httpsUrlSchema);
+ }
+
+ if (context.ServerName.StartsWith(httpUrlSchema)) {
+ if (context.UseTLS) {
+ ythrow TApiUsageError() << "URL schema doesn't match UseTLS option";
+ }
+
+ context.ServerName.erase(0, sizeof(httpUrlSchema) - 1);
+ }
+ if (context.ServerName.StartsWith(httpsUrlSchema)) {
+ if (!context.UseTLS) {
+ ythrow TApiUsageError() << "URL schema doesn't match UseTLS option";
+ }
+
+ context.ServerName.erase(0, sizeof(httpsUrlSchema) - 1);
+ }
+
+ if (context.ServerName.find(':') == TString::npos) {
context.ServerName = CreateHostNameWithPort(context.ServerName, context);
}
if (options.TvmOnly_) {
context.ServerName = Format("tvm.%v", context.ServerName);
}
- if (options.UseTLS_ || options.UseCoreHttpClient_) {
- context.HttpClient = NHttpClient::CreateCoreHttpClient(options.UseTLS_, context.Config);
+ if (context.UseTLS || options.UseCoreHttpClient_) {
+ context.HttpClient = NHttpClient::CreateCoreHttpClient(context.UseTLS, context.Config);
} else {
context.HttpClient = NHttpClient::CreateDefaultHttpClient();
}
diff --git a/yt/cpp/mapreduce/interface/client_method_options.h b/yt/cpp/mapreduce/interface/client_method_options.h
index d445784e16..80be6e35e7 100644
--- a/yt/cpp/mapreduce/interface/client_method_options.h
+++ b/yt/cpp/mapreduce/interface/client_method_options.h
@@ -1055,7 +1055,7 @@ struct TCreateClientOptions
/// @brief Use HTTPs (use HTTP client from yt/yt/core always).
///
/// @see UseCoreHttpClient
- FLUENT_FIELD_DEFAULT(bool, UseTLS, false);
+ FLUENT_FIELD_OPTION(bool, UseTLS);
/// @brief Use HTTP client from yt/yt/core.
FLUENT_FIELD_DEFAULT(bool, UseCoreHttpClient, false);