diff options
author | brgayazov <bulat@ydb.tech> | 2023-02-14 16:46:14 +0300 |
---|---|---|
committer | brgayazov <bulat@ydb.tech> | 2023-02-14 16:46:14 +0300 |
commit | 4cb5e6b92c1cfdeb4ba2faf025885821c2005cfc (patch) | |
tree | 6ed79801de69991a175238ef4c05c41c5e6bbb67 | |
parent | 68fb62b3af9716c5055c7b2f44e109eaf71ec318 (diff) | |
download | ydb-4cb5e6b92c1cfdeb4ba2faf025885821c2005cfc.tar.gz |
Add parsing home directory in paths
-rw-r--r-- | ydb/public/lib/ydb_cli/commands/ydb_profile.cpp | 11 | ||||
-rw-r--r-- | ydb/public/lib/ydb_cli/commands/ydb_root_common.cpp | 6 | ||||
-rw-r--r-- | ydb/public/lib/ydb_cli/common/common.cpp | 5 | ||||
-rw-r--r-- | ydb/public/lib/ydb_cli/common/common.h | 13 |
4 files changed, 22 insertions, 13 deletions
diff --git a/ydb/public/lib/ydb_cli/commands/ydb_profile.cpp b/ydb/public/lib/ydb_cli/commands/ydb_profile.cpp index 5759e1169a3..3a03bd11a15 100644 --- a/ydb/public/lib/ydb_cli/commands/ydb_profile.cpp +++ b/ydb/public/lib/ydb_cli/commands/ydb_profile.cpp @@ -13,10 +13,6 @@ #include <cstdio> #if defined(_win32_) -#include <util/system/env.h> -#endif - -#if defined(_win32_) #include <io.h> #elif defined(_unix_) #include <unistd.h> @@ -26,13 +22,6 @@ namespace NYdb::NConsoleClient { namespace { -#if defined(_darwin_) - const TString HomeDir = GetHomeDir(); -#elif defined(_win32_) - const TString HomeDir = GetEnv("USERPROFILE"); -#else - const TString HomeDir = GetHomeDir(); -#endif bool IsStdinInteractive() { #if defined(_win32_) 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 98080d21b19..34743b9640f 100644 --- a/ydb/public/lib/ydb_cli/commands/ydb_root_common.cpp +++ b/ydb/public/lib/ydb_cli/commands/ydb_root_common.cpp @@ -448,7 +448,11 @@ bool TClientCommandRootCommon::GetCredentialsFromProfile(std::shared_ptr<IProfil if (IsVerbose()) { PrintSettingFromProfile("service account key file (sa-key-file)", profile, explicitOption); } - config.SaKeyFile = authData.as<TString>(); + TString filePath = authData.as<TString>(); + if (filePath.StartsWith("~")) { + filePath = HomeDir + filePath.substr(1); + } + config.SaKeyFile = filePath; } else if (authMethod == "ydb-token") { if (IsVerbose()) { PrintSettingFromProfile("OAuth token (ydb-token)", profile, explicitOption); diff --git a/ydb/public/lib/ydb_cli/common/common.cpp b/ydb/public/lib/ydb_cli/common/common.cpp index 0490fc76435..c7b13482cb6 100644 --- a/ydb/public/lib/ydb_cli/common/common.cpp +++ b/ydb/public/lib/ydb_cli/common/common.cpp @@ -4,7 +4,7 @@ #include <util/folder/path.h> #include <util/string/strip.h> -#ifdef _unix_ +#if defined(_unix_) #include <sys/ioctl.h> #include <termios.h> @@ -60,6 +60,9 @@ void TProfileConfig::ReadFromFile() { } bool ReadFromFileIfExists(TString& filePath, const TString& fileName, TString& output, bool allowEmpty) { + if (filePath.StartsWith("~")) { + filePath = HomeDir + filePath.substr(1); + } TFsPath fsPath(filePath); if (!fsPath.Exists()) { correctpath(filePath); diff --git a/ydb/public/lib/ydb_cli/common/common.h b/ydb/public/lib/ydb_cli/common/common.h index c11262ebdfe..f4a09a2f006 100644 --- a/ydb/public/lib/ydb_cli/common/common.h +++ b/ydb/public/lib/ydb_cli/common/common.h @@ -3,12 +3,25 @@ #include <util/stream/file.h> #include <util/string/builder.h> #include <util/generic/string.h> +#include <util/folder/dirut.h> #include <util/generic/yexception.h> #include <util/generic/map.h> +#if defined(_win32_) +#include <util/system/env.h> +#endif + namespace NYdb { namespace NConsoleClient { +#if defined(_darwin_) + const TString HomeDir = GetHomeDir(); +#elif defined(_win32_) + const TString HomeDir = GetEnv("USERPROFILE"); +#else + const TString HomeDir = GetHomeDir(); +#endif + class TMisuseException : public yexception {}; class TProfileConfig { |