diff options
author | brgayazov <brgayazov@yandex-team.com> | 2022-10-03 19:30:18 +0300 |
---|---|---|
committer | brgayazov <brgayazov@yandex-team.com> | 2022-10-03 19:30:18 +0300 |
commit | 35e59febbf72b218f8f31fa69361569aae598afa (patch) | |
tree | a654d6b807f014cc8bd82a17c0ca3c3f052e5bcd | |
parent | 7a517894979131b3fb6a8975d2858fa0eb0dd850 (diff) | |
download | ydb-35e59febbf72b218f8f31fa69361569aae598afa.tar.gz |
Added saving iam-endpoint to profile
-rw-r--r-- | ydb/public/lib/ydb_cli/commands/ydb_profile.cpp | 4 | ||||
-rw-r--r-- | ydb/public/lib/ydb_cli/commands/ydb_root_common.cpp | 13 | ||||
-rw-r--r-- | ydb/public/lib/ydb_cli/commands/ydb_root_common.h | 1 |
3 files changed, 15 insertions, 3 deletions
diff --git a/ydb/public/lib/ydb_cli/commands/ydb_profile.cpp b/ydb/public/lib/ydb_cli/commands/ydb_profile.cpp index 58dbd7c86fa..a6f344b4c20 100644 --- a/ydb/public/lib/ydb_cli/commands/ydb_profile.cpp +++ b/ydb/public/lib/ydb_cli/commands/ydb_profile.cpp @@ -242,7 +242,9 @@ namespace { } bool SetAuthFromCommandLine( std::shared_ptr<IProfile> profile, TClientCommand::TConfig& config) { - + if (config.ParseResult->Has("iam-endpoint")) { + profile->SetValue("iam-endpoint", config.ParseResult->Get("iam-endpoint")); + } if (config.ParseResult->Has("token-file")) { PutAuthMethod( profile, "token-file", config.ParseResult->Get("token-file")); } else if (config.ParseResult->Has("iam-token-file")) { diff --git a/ydb/public/lib/ydb_cli/commands/ydb_root_common.cpp b/ydb/public/lib/ydb_cli/commands/ydb_root_common.cpp index 00ce0358373..20505c92dc4 100644 --- a/ydb/public/lib/ydb_cli/commands/ydb_root_common.cpp +++ b/ydb/public/lib/ydb_cli/commands/ydb_root_common.cpp @@ -320,6 +320,12 @@ namespace { } } +void TClientCommandRootCommon::CheckForIamEndpoint(TConfig& config, std::shared_ptr<IProfile> profile) { + if (profile->Has("iam-endpoint")) { + config.IamEndpoint = profile->GetValue("iam-endpoint").as<TString>(); + } +} + bool TClientCommandRootCommon::GetCredentialsFromProfile(std::shared_ptr<IProfile> profile, TConfig& config, bool explicitOption) { if (!profile || !profile->Has("authentication")) { return false; @@ -340,7 +346,7 @@ bool TClientCommandRootCommon::GetCredentialsFromProfile(std::shared_ptr<IProfil } bool knownMethod = false; if (config.UseIamAuth) { - knownMethod |= (authMethod == "iam-token" || authMethod == "yc-token" || authMethod == "sa-key-file" || + knownMethod |= (authMethod == "iam-token" || authMethod == "yc-token" || authMethod == "sa-key-file" || authMethod == "token-file" || authMethod == "yc-token-file"); } if (config.UseOAuthToken) { @@ -374,17 +380,20 @@ bool TClientCommandRootCommon::GetCredentialsFromProfile(std::shared_ptr<IProfil PrintSettingFromProfile("Yandex.Cloud Passport token (yc-token)", profile, explicitOption); } config.YCToken = authData.as<TString>(); + CheckForIamEndpoint(config, profile); } else if (authMethod == "yc-token-file") { if (IsVerbose()) { PrintSettingFromProfile("Yandex.Cloud Passport token file (yc-token-file)", profile, explicitOption); } TString filename = authData.as<TString>(); config.YCToken = ReadFromFile(filename, "token"); + CheckForIamEndpoint(config, profile); } else if (authMethod == "sa-key-file") { if (IsVerbose()) { PrintSettingFromProfile("service account key file (sa-key-file)", profile, explicitOption); } config.SaKeyFile = authData.as<TString>(); + CheckForIamEndpoint(config, profile); } else if (authMethod == "ydb-token") { if (IsVerbose()) { PrintSettingFromProfile("OAuth token (ydb-token)", profile, explicitOption); @@ -589,7 +598,7 @@ void TClientCommandRootCommon::ParseCredentials(TConfig& config) { } } - if (config.UseIamAuth && IamEndpoint) { + if (!config.IamEndpoint && config.UseIamAuth && IamEndpoint) { config.IamEndpoint = IamEndpoint; } } diff --git a/ydb/public/lib/ydb_cli/commands/ydb_root_common.h b/ydb/public/lib/ydb_cli/commands/ydb_root_common.h index 41fba425f75..d3c29057255 100644 --- a/ydb/public/lib/ydb_cli/commands/ydb_root_common.h +++ b/ydb/public/lib/ydb_cli/commands/ydb_root_common.h @@ -44,6 +44,7 @@ private: void ParseProfile(); void ParseDatabase(TConfig& config); + void CheckForIamEndpoint(TConfig& config, std::shared_ptr<IProfile> profile); TString Database; |