aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrgayazov <bulat@ydb.tech>2023-03-01 20:39:22 +0300
committerbrgayazov <bulat@ydb.tech>2023-03-01 20:39:22 +0300
commit789192585f1d3f02af4b1002f4e23499a0168eb7 (patch)
tree390b6697bccac3960db3476cf83e7c647771126a
parent4217c0e360c22b33763317089141ab196386c21b (diff)
downloadydb-789192585f1d3f02af4b1002f4e23499a0168eb7.tar.gz
Add option '--profile-file' and recanonized tests
-rw-r--r--ydb/public/lib/ydb_cli/commands/ydb_profile.cpp22
-rw-r--r--ydb/public/lib/ydb_cli/commands/ydb_profile.h2
-rw-r--r--ydb/public/lib/ydb_cli/commands/ydb_root_common.cpp18
-rw-r--r--ydb/public/lib/ydb_cli/commands/ydb_root_common.h1
-rw-r--r--ydb/public/lib/ydb_cli/common/command.h2
-rw-r--r--ydb/tests/functional/ydb_cli/canondata/test_ydb_scripting.TestScriptingServiceHelp.test_help/result.output2
-rw-r--r--ydb/tests/functional/ydb_cli/canondata/test_ydb_scripting.TestScriptingServiceHelp.test_help_ex/result.output2
7 files changed, 26 insertions, 23 deletions
diff --git a/ydb/public/lib/ydb_cli/commands/ydb_profile.cpp b/ydb/public/lib/ydb_cli/commands/ydb_profile.cpp
index 2a44a0e3c2..0d8bc79aab 100644
--- a/ydb/public/lib/ydb_cli/commands/ydb_profile.cpp
+++ b/ydb/public/lib/ydb_cli/commands/ydb_profile.cpp
@@ -35,10 +35,6 @@ namespace {
const TString AuthNode = "authentication";
-std::shared_ptr<IProfileManager> CreateYdbProfileManager(const TString& ydbDir) {
- return CreateProfileManager(TStringBuilder() << HomeDir << '/' << ydbDir << "/config/config.yaml");
-}
-
TCommandConfig::TCommandConfig()
: TClientCommandTree("config", {}, "Manage YDB CLI configuration")
{
@@ -270,7 +266,7 @@ void TCommandInit::Config(TConfig& config) {
int TCommandInit::Run(TConfig& config) {
//Y_UNUSED(config);
Cout << "Welcome! This command will take you through the configuration process." << Endl;
- auto profileManager = CreateYdbProfileManager(config.YdbDir);
+ auto profileManager = CreateProfileManager(config.ProfileFile);
TString profileName;
SetupProfileName(profileName, profileManager);
ConfigureProfile(profileName, profileManager, config, true, false);
@@ -651,7 +647,7 @@ int TCommandCreateProfile::Run(TConfig& config) {
// Y_UNUSED(config);
TString profileName = ProfileName;
Interactive = (!AnyProfileOptionInCommandLine() || !profileName) && IsStdinInteractive();
- auto profileManager = CreateYdbProfileManager(config.YdbDir);
+ auto profileManager = CreateProfileManager(config.ProfileFile);
if (Interactive) {
Cout << "Welcome! This command will take you through configuration profile creation process." << Endl;
}
@@ -696,7 +692,7 @@ void TCommandDeleteProfile::Parse(TConfig& config) {
int TCommandDeleteProfile::Run(TConfig& config) {
Y_UNUSED(config);
- auto profileManager = CreateYdbProfileManager(config.YdbDir);
+ auto profileManager = CreateProfileManager(config.ProfileFile);
const auto profileNames = profileManager->ListProfiles();
if (ProfileName) {
if (find(profileNames.begin(), profileNames.end(), ProfileName) == profileNames.end()) {
@@ -777,7 +773,7 @@ void TCommandActivateProfile::Parse(TConfig& config) {
}
int TCommandActivateProfile::Run(TConfig& config) {
- auto profileManager = CreateYdbProfileManager(config.YdbDir);
+ auto profileManager = CreateProfileManager(config.ProfileFile);
const auto profileNames = profileManager->ListProfiles();
if (ProfileName) {
if (find(profileNames.begin(), profileNames.end(), ProfileName) == profileNames.end()) {
@@ -853,7 +849,7 @@ void TCommandDeactivateProfile::Config(TConfig& config) {
}
int TCommandDeactivateProfile::Run(TConfig& config) {
- auto profileManager = CreateYdbProfileManager(config.YdbDir);
+ auto profileManager = CreateProfileManager(config.ProfileFile);
TString currentActiveProfileName = profileManager->GetActiveProfileName();
if (currentActiveProfileName) {
profileManager->DeactivateProfile();
@@ -879,7 +875,7 @@ void TCommandListProfiles::Config(TConfig& config) {
int TCommandListProfiles::Run(TConfig& config) {
Y_UNUSED(config);
- auto profileManager = CreateYdbProfileManager(config.YdbDir);
+ auto profileManager = CreateProfileManager(config.ProfileFile);
const auto profileNames = profileManager->ListProfiles();
TString activeProfileName = profileManager->GetActiveProfileName();
for (const auto& profileName : profileNames) {
@@ -918,7 +914,7 @@ void TCommandGetProfile::Parse(TConfig& config) {
int TCommandGetProfile::Run(TConfig& config) {
Y_UNUSED(config);
- auto profileManager = CreateYdbProfileManager(config.YdbDir);
+ auto profileManager = CreateProfileManager(config.ProfileFile);
const auto profileNames = profileManager->ListProfiles();
if (ProfileName) {
if (find(profileNames.begin(), profileNames.end(), ProfileName) == profileNames.end()) {
@@ -1024,7 +1020,7 @@ void TCommandUpdateProfile::Parse(TConfig& config) {
}
int TCommandUpdateProfile::Run(TConfig& config) {
- auto profileManager = CreateYdbProfileManager(config.YdbDir);
+ auto profileManager = CreateProfileManager(config.ProfileFile);
if (!profileManager->HasProfile(ProfileName)) {
Cerr << "No existing profile \"" << ProfileName << "\". "
<< "Run \"ydb config profile list\" without arguments to see existing profiles" << Endl;
@@ -1054,7 +1050,7 @@ void TCommandReplaceProfile::Parse(TConfig& config) {
}
int TCommandReplaceProfile::Run(TConfig& config) {
- auto profileManager = CreateYdbProfileManager(config.YdbDir);
+ auto profileManager = CreateProfileManager(config.ProfileFile);
profileManager->RemoveProfile(ProfileName);
profileManager->CreateProfile(ProfileName);
ConfigureProfile(ProfileName, profileManager, config, false, true);
diff --git a/ydb/public/lib/ydb_cli/commands/ydb_profile.h b/ydb/public/lib/ydb_cli/commands/ydb_profile.h
index 01b1aa5013..5e73d6c33c 100644
--- a/ydb/public/lib/ydb_cli/commands/ydb_profile.h
+++ b/ydb/public/lib/ydb_cli/commands/ydb_profile.h
@@ -6,8 +6,6 @@
namespace NYdb {
namespace NConsoleClient {
-std::shared_ptr<IProfileManager> CreateYdbProfileManager(const TString& ydbDir);
-
class TCommandConfig : public TClientCommandTree {
public:
TCommandConfig();
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 e0da10be1a..fa0edf069b 100644
--- a/ydb/public/lib/ydb_cli/commands/ydb_root_common.cpp
+++ b/ydb/public/lib/ydb_cli/commands/ydb_root_common.cpp
@@ -69,7 +69,6 @@ void TClientCommandRootCommon::ValidateSettings() {
}
void TClientCommandRootCommon::FillConfig(TConfig& config) {
- config.YdbDir = Settings.YdbDir;
config.UseOAuthToken = Settings.UseOAuthToken.GetRef();
config.UseIamAuth = Settings.UseIamAuth.GetRef();
config.UseStaticCredentials = Settings.UseStaticCredentials.GetRef();
@@ -121,7 +120,8 @@ void TClientCommandRootCommon::Config(TConfig& config) {
.Optional().NoArgument().Handler0([&](){
VerbosityLevel++;
});
-
+ opts.AddLongOption('p', "profile", "Profile name to use configuration parameters from.")
+ .RequiredArgument("NAME").StoreResult(&ProfileName);
TClientCommandRootBase::Config(config);
if (config.UseIamAuth) {
@@ -217,8 +217,8 @@ void TClientCommandRootCommon::Config(TConfig& config) {
.StoreResult(&IamEndpoint);
}
- opts.AddLongOption('p', "profile", "Profile name to use configuration parameters from.")
- .RequiredArgument("NAME").StoreResult(&ProfileName);
+ opts.AddLongOption("profile-file", "Path to config file with profile data in yaml format")
+ .RequiredArgument("PATH").StoreResult(&ProfileFile);
TStringStream stream;
NColorizer::TColors colors = NColorizer::AutoColors(Cout);
@@ -232,7 +232,15 @@ void TClientCommandRootCommon::Config(TConfig& config) {
}
void TClientCommandRootCommon::Parse(TConfig& config) {
- ProfileManager = CreateYdbProfileManager(Settings.YdbDir);
+ if (ProfileFile.empty()) {
+ config.ProfileFile = TStringBuilder() << HomeDir << '/' << Settings.YdbDir << "/config/config.yaml";
+ } else {
+ config.ProfileFile = TFsPath(ProfileFile).RealLocation().GetPath();
+ }
+ if (TFsPath(config.ProfileFile).Exists() && !TFsPath(config.ProfileFile).IsFile()) {
+ throw TMisuseException() << "\'" << config.ProfileFile << "\' is not a file";
+ }
+ ProfileManager = CreateProfileManager(config.ProfileFile);
ParseProfile();
TClientCommandRootBase::Parse(config);
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 0449516607..f1d9eb1500 100644
--- a/ydb/public/lib/ydb_cli/commands/ydb_root_common.h
+++ b/ydb/public/lib/ydb_cli/commands/ydb_root_common.h
@@ -54,6 +54,7 @@ private:
}
TString ProfileName;
+ TString ProfileFile;
std::shared_ptr<IProfile> Profile;
std::shared_ptr<IProfileManager> ProfileManager;
diff --git a/ydb/public/lib/ydb_cli/common/command.h b/ydb/public/lib/ydb_cli/common/command.h
index 80a0d5b774..c3c02ba86c 100644
--- a/ydb/public/lib/ydb_cli/common/command.h
+++ b/ydb/public/lib/ydb_cli/common/command.h
@@ -106,7 +106,7 @@ public:
TString IamEndpoint;
TString YScope;
- TString YdbDir;
+ TString ProfileFile;
bool UseOAuthToken = true;
bool UseIamAuth = false;
bool UseStaticCredentials = false;
diff --git a/ydb/tests/functional/ydb_cli/canondata/test_ydb_scripting.TestScriptingServiceHelp.test_help/result.output b/ydb/tests/functional/ydb_cli/canondata/test_ydb_scripting.TestScriptingServiceHelp.test_help/result.output
index 71010f4e5f..55c3c2ace1 100644
--- a/ydb/tests/functional/ydb_cli/canondata/test_ydb_scripting.TestScriptingServiceHelp.test_help/result.output
+++ b/ydb/tests/functional/ydb_cli/canondata/test_ydb_scripting.TestScriptingServiceHelp.test_help/result.output
@@ -3,7 +3,7 @@ Usage: ydb [global options...] scripting yql [options...]
Description: Execute YQL script
Global options:
- {-e|--endpoint}, {-d|--database}, {-v|--verbose}, --ca-file, --iam-token-file, --yc-token-file, --use-metadata-credentials, --sa-key-file, --token-file, --user, --password-file, --no-password, --iam-endpoint, {-p|--profile}
+ {-e|--endpoint}, {-d|--database}, {-v|--verbose}, {-p|--profile}, --ca-file, --iam-token-file, --yc-token-file, --use-metadata-credentials, --sa-key-file, --token-file, --user, --password-file, --no-password, --iam-endpoint, --profile-file
To get full description of these options run 'ydb --help'.
Options:
diff --git a/ydb/tests/functional/ydb_cli/canondata/test_ydb_scripting.TestScriptingServiceHelp.test_help_ex/result.output b/ydb/tests/functional/ydb_cli/canondata/test_ydb_scripting.TestScriptingServiceHelp.test_help_ex/result.output
index 8a0e9e70c7..fd143ce076 100644
--- a/ydb/tests/functional/ydb_cli/canondata/test_ydb_scripting.TestScriptingServiceHelp.test_help_ex/result.output
+++ b/ydb/tests/functional/ydb_cli/canondata/test_ydb_scripting.TestScriptingServiceHelp.test_help_ex/result.output
@@ -3,7 +3,7 @@ Usage: ydb [global options...] scripting yql [options...]
Description: Execute YQL script
Global options:
- {-e|--endpoint}, {-d|--database}, {-v|--verbose}, --ca-file, --iam-token-file, --yc-token-file, --use-metadata-credentials, --sa-key-file, --token-file, --user, --password-file, --no-password, --iam-endpoint, {-p|--profile}
+ {-e|--endpoint}, {-d|--database}, {-v|--verbose}, {-p|--profile}, --ca-file, --iam-token-file, --yc-token-file, --use-metadata-credentials, --sa-key-file, --token-file, --user, --password-file, --no-password, --iam-endpoint, --profile-file
To get full description of these options run 'ydb --help'.
Options: