diff options
author | ilnaz <ilnaz@ydb.tech> | 2022-10-27 16:57:27 +0300 |
---|---|---|
committer | ilnaz <ilnaz@ydb.tech> | 2022-10-27 16:57:27 +0300 |
commit | 7409037ca690d39e67c2601f0448c94fe3f54367 (patch) | |
tree | be37e04846bd3df3ce39c5518492619e7675b49c | |
parent | 2ab33806be812b8ef4d1260977673a64dc88d2cf (diff) | |
download | ydb-7409037ca690d39e67c2601f0448c94fe3f54367.tar.gz |
Support aws profiles
-rw-r--r-- | contrib/libs/CMakeLists.txt | 1 | ||||
-rw-r--r-- | contrib/libs/lua/CMakeLists.darwin.txt | 41 | ||||
-rw-r--r-- | contrib/libs/lua/CMakeLists.linux-aarch64.txt | 41 | ||||
-rw-r--r-- | contrib/libs/lua/CMakeLists.linux.txt | 41 | ||||
-rw-r--r-- | contrib/libs/lua/CMakeLists.txt | 15 | ||||
-rw-r--r-- | library/cpp/CMakeLists.darwin.txt | 2 | ||||
-rw-r--r-- | library/cpp/CMakeLists.linux-aarch64.txt | 2 | ||||
-rw-r--r-- | library/cpp/CMakeLists.linux.txt | 2 | ||||
-rw-r--r-- | library/cpp/config/CMakeLists.txt | 46 | ||||
-rw-r--r-- | library/cpp/lua/CMakeLists.txt | 22 | ||||
-rw-r--r-- | tools/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tools/archiver/CMakeLists.darwin.txt | 28 | ||||
-rw-r--r-- | tools/archiver/CMakeLists.linux-aarch64.txt | 32 | ||||
-rw-r--r-- | tools/archiver/CMakeLists.linux.txt | 34 | ||||
-rw-r--r-- | tools/archiver/CMakeLists.txt | 15 | ||||
-rw-r--r-- | ydb/public/lib/ydb_cli/commands/ydb_service_export.cpp | 9 | ||||
-rw-r--r-- | ydb/public/lib/ydb_cli/commands/ydb_service_import.cpp | 9 | ||||
-rw-r--r-- | ydb/public/lib/ydb_cli/common/CMakeLists.txt | 1 | ||||
-rw-r--r-- | ydb/public/lib/ydb_cli/common/aws.cpp | 60 | ||||
-rw-r--r-- | ydb/public/lib/ydb_cli/common/aws.h | 57 |
20 files changed, 393 insertions, 66 deletions
diff --git a/contrib/libs/CMakeLists.txt b/contrib/libs/CMakeLists.txt index c491c0a5b1..2c5a43d6f3 100644 --- a/contrib/libs/CMakeLists.txt +++ b/contrib/libs/CMakeLists.txt @@ -35,6 +35,7 @@ add_subdirectory(libunwind) add_subdirectory(libxml) add_subdirectory(linuxvdso) add_subdirectory(llvm12) +add_subdirectory(lua) add_subdirectory(lz4) add_subdirectory(lzma) add_subdirectory(lzmasdk) diff --git a/contrib/libs/lua/CMakeLists.darwin.txt b/contrib/libs/lua/CMakeLists.darwin.txt new file mode 100644 index 0000000000..9284089f16 --- /dev/null +++ b/contrib/libs/lua/CMakeLists.darwin.txt @@ -0,0 +1,41 @@ + +# This file was gererated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_library(contrib-libs-lua) +target_compile_options(contrib-libs-lua PRIVATE + -DLUA_USE_MACOSX + -Wno-everything +) +target_include_directories(contrib-libs-lua PUBLIC + ${CMAKE_BINARY_DIR}/contrib/libs/lua +) +target_include_directories(contrib-libs-lua PRIVATE + ${CMAKE_SOURCE_DIR}/contrib/libs/lua/lua-5.2.0/src +) +target_link_libraries(contrib-libs-lua PUBLIC + contrib-libs-cxxsupp + yutil + library-cpp-archive +) +target_sources(contrib-libs-lua PRIVATE + ${CMAKE_SOURCE_DIR}/contrib/libs/lua/lib.cpp +) +add_custom_command( + OUTPUT + ${CMAKE_BINARY_DIR}/contrib/libs/lua/common.inc + DEPENDS + ${CMAKE_SOURCE_DIR}/contrib/libs/lua/common/json.lua + COMMAND + ${TOOLS_ROOT}/tools/archiver/archiver + -q + ${CMAKE_SOURCE_DIR}/contrib/libs/lua/common/stdlib.lua + ${CMAKE_SOURCE_DIR}/contrib/libs/lua/common/json.lua: + -o + ${CMAKE_BINARY_DIR}/contrib/libs/lua/common.inc +) diff --git a/contrib/libs/lua/CMakeLists.linux-aarch64.txt b/contrib/libs/lua/CMakeLists.linux-aarch64.txt new file mode 100644 index 0000000000..74a9dac925 --- /dev/null +++ b/contrib/libs/lua/CMakeLists.linux-aarch64.txt @@ -0,0 +1,41 @@ + +# This file was gererated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_library(contrib-libs-lua) +target_compile_options(contrib-libs-lua PRIVATE + -DLUA_USE_LINUX + -Wno-everything +) +target_include_directories(contrib-libs-lua PUBLIC + ${CMAKE_BINARY_DIR}/contrib/libs/lua +) +target_include_directories(contrib-libs-lua PRIVATE + ${CMAKE_SOURCE_DIR}/contrib/libs/lua/lua-5.2.0/src +) +target_link_libraries(contrib-libs-lua PUBLIC + contrib-libs-cxxsupp + yutil + library-cpp-archive +) +target_sources(contrib-libs-lua PRIVATE + ${CMAKE_SOURCE_DIR}/contrib/libs/lua/lib.cpp +) +add_custom_command( + OUTPUT + ${CMAKE_BINARY_DIR}/contrib/libs/lua/common.inc + DEPENDS + ${CMAKE_SOURCE_DIR}/contrib/libs/lua/common/json.lua + COMMAND + ${TOOLS_ROOT}/tools/archiver/archiver + -q + ${CMAKE_SOURCE_DIR}/contrib/libs/lua/common/stdlib.lua + ${CMAKE_SOURCE_DIR}/contrib/libs/lua/common/json.lua: + -o + ${CMAKE_BINARY_DIR}/contrib/libs/lua/common.inc +) diff --git a/contrib/libs/lua/CMakeLists.linux.txt b/contrib/libs/lua/CMakeLists.linux.txt new file mode 100644 index 0000000000..74a9dac925 --- /dev/null +++ b/contrib/libs/lua/CMakeLists.linux.txt @@ -0,0 +1,41 @@ + +# This file was gererated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_library(contrib-libs-lua) +target_compile_options(contrib-libs-lua PRIVATE + -DLUA_USE_LINUX + -Wno-everything +) +target_include_directories(contrib-libs-lua PUBLIC + ${CMAKE_BINARY_DIR}/contrib/libs/lua +) +target_include_directories(contrib-libs-lua PRIVATE + ${CMAKE_SOURCE_DIR}/contrib/libs/lua/lua-5.2.0/src +) +target_link_libraries(contrib-libs-lua PUBLIC + contrib-libs-cxxsupp + yutil + library-cpp-archive +) +target_sources(contrib-libs-lua PRIVATE + ${CMAKE_SOURCE_DIR}/contrib/libs/lua/lib.cpp +) +add_custom_command( + OUTPUT + ${CMAKE_BINARY_DIR}/contrib/libs/lua/common.inc + DEPENDS + ${CMAKE_SOURCE_DIR}/contrib/libs/lua/common/json.lua + COMMAND + ${TOOLS_ROOT}/tools/archiver/archiver + -q + ${CMAKE_SOURCE_DIR}/contrib/libs/lua/common/stdlib.lua + ${CMAKE_SOURCE_DIR}/contrib/libs/lua/common/json.lua: + -o + ${CMAKE_BINARY_DIR}/contrib/libs/lua/common.inc +) diff --git a/contrib/libs/lua/CMakeLists.txt b/contrib/libs/lua/CMakeLists.txt new file mode 100644 index 0000000000..3e0811fb22 --- /dev/null +++ b/contrib/libs/lua/CMakeLists.txt @@ -0,0 +1,15 @@ + +# This file was gererated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + +if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" AND UNIX AND NOT APPLE AND NOT ANDROID) + include(CMakeLists.linux-aarch64.txt) +elseif (APPLE) + include(CMakeLists.darwin.txt) +elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND UNIX AND NOT APPLE AND NOT ANDROID) + include(CMakeLists.linux.txt) +endif() diff --git a/library/cpp/CMakeLists.darwin.txt b/library/cpp/CMakeLists.darwin.txt index a58afa12b2..74f3a1430a 100644 --- a/library/cpp/CMakeLists.darwin.txt +++ b/library/cpp/CMakeLists.darwin.txt @@ -23,6 +23,7 @@ add_subdirectory(codecs) add_subdirectory(colorizer) add_subdirectory(compproto) add_subdirectory(comptable) +add_subdirectory(config) add_subdirectory(containers) add_subdirectory(coroutine) add_subdirectory(cppparser) @@ -49,6 +50,7 @@ add_subdirectory(lcs) add_subdirectory(lfalloc) add_subdirectory(linear_regression) add_subdirectory(logger) +add_subdirectory(lua) add_subdirectory(lwtrace) add_subdirectory(malloc) add_subdirectory(messagebus) diff --git a/library/cpp/CMakeLists.linux-aarch64.txt b/library/cpp/CMakeLists.linux-aarch64.txt index d0f76a6815..7ccca0159a 100644 --- a/library/cpp/CMakeLists.linux-aarch64.txt +++ b/library/cpp/CMakeLists.linux-aarch64.txt @@ -23,6 +23,7 @@ add_subdirectory(codecs) add_subdirectory(colorizer) add_subdirectory(compproto) add_subdirectory(comptable) +add_subdirectory(config) add_subdirectory(containers) add_subdirectory(coroutine) add_subdirectory(cppparser) @@ -48,6 +49,7 @@ add_subdirectory(lcs) add_subdirectory(lfalloc) add_subdirectory(linear_regression) add_subdirectory(logger) +add_subdirectory(lua) add_subdirectory(lwtrace) add_subdirectory(malloc) add_subdirectory(messagebus) diff --git a/library/cpp/CMakeLists.linux.txt b/library/cpp/CMakeLists.linux.txt index a58afa12b2..74f3a1430a 100644 --- a/library/cpp/CMakeLists.linux.txt +++ b/library/cpp/CMakeLists.linux.txt @@ -23,6 +23,7 @@ add_subdirectory(codecs) add_subdirectory(colorizer) add_subdirectory(compproto) add_subdirectory(comptable) +add_subdirectory(config) add_subdirectory(containers) add_subdirectory(coroutine) add_subdirectory(cppparser) @@ -49,6 +50,7 @@ add_subdirectory(lcs) add_subdirectory(lfalloc) add_subdirectory(linear_regression) add_subdirectory(logger) +add_subdirectory(lua) add_subdirectory(lwtrace) add_subdirectory(malloc) add_subdirectory(messagebus) diff --git a/library/cpp/config/CMakeLists.txt b/library/cpp/config/CMakeLists.txt new file mode 100644 index 0000000000..ab72d69ca6 --- /dev/null +++ b/library/cpp/config/CMakeLists.txt @@ -0,0 +1,46 @@ + +# This file was gererated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_library(library-cpp-config) +target_include_directories(library-cpp-config PUBLIC + ${CMAKE_BINARY_DIR}/library/cpp/config +) +target_link_libraries(library-cpp-config PUBLIC + contrib-libs-cxxsupp + yutil + library-cpp-archive + library-cpp-json + library-cpp-lua + cpp-string_utils-relaxed_escaper +) +target_sources(library-cpp-config PRIVATE + ${CMAKE_SOURCE_DIR}/library/cpp/config/config.cpp + ${CMAKE_SOURCE_DIR}/library/cpp/config/sax.cpp + ${CMAKE_SOURCE_DIR}/library/cpp/config/value.cpp + ${CMAKE_SOURCE_DIR}/library/cpp/config/markup.cpp + ${CMAKE_SOURCE_DIR}/library/cpp/config/ini.cpp + ${CMAKE_SOURCE_DIR}/library/cpp/config/domscheme.cpp +) +add_custom_command( + OUTPUT + ${CMAKE_BINARY_DIR}/library/cpp/config/code.inc + DEPENDS + COMMAND + ${TOOLS_ROOT}/tools/archiver/archiver + -q + ${CMAKE_SOURCE_DIR}/library/cpp/config/support/pp.lua + : + -o + ${CMAKE_BINARY_DIR}/library/cpp/config/code.inc +) +target_ragel_lexers(library-cpp-config + PRIVATE + ${CMAKE_SOURCE_DIR}/library/cpp/config/markupfsm.h.rl6 + -CG2 +) diff --git a/library/cpp/lua/CMakeLists.txt b/library/cpp/lua/CMakeLists.txt new file mode 100644 index 0000000000..dfa77ac81d --- /dev/null +++ b/library/cpp/lua/CMakeLists.txt @@ -0,0 +1,22 @@ + +# This file was gererated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_library(library-cpp-lua) +target_link_libraries(library-cpp-lua PUBLIC + contrib-libs-cxxsupp + yutil + library-cpp-json + contrib-libs-lua + cpp-string_utils-ztstrbuf +) +target_sources(library-cpp-lua PRIVATE + ${CMAKE_SOURCE_DIR}/library/cpp/lua/eval.cpp + ${CMAKE_SOURCE_DIR}/library/cpp/lua/json.cpp + ${CMAKE_SOURCE_DIR}/library/cpp/lua/wrapper.cpp +) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index b0e6ac4979..89462519db 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -6,5 +6,6 @@ # original buildsystem will not be accepted. +add_subdirectory(archiver) add_subdirectory(enum_parser) add_subdirectory(rescompiler) diff --git a/tools/archiver/CMakeLists.darwin.txt b/tools/archiver/CMakeLists.darwin.txt new file mode 100644 index 0000000000..2b009ca5e1 --- /dev/null +++ b/tools/archiver/CMakeLists.darwin.txt @@ -0,0 +1,28 @@ + +# This file was gererated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_executable(archiver) +target_link_libraries(archiver PUBLIC + contrib-libs-cxxsupp + yutil + library-cpp-cpuid_check + library-cpp-archive + cpp-digest-md5 + cpp-getopt-small +) +target_link_options(archiver PRIVATE + -Wl,-no_deduplicate + -Wl,-sdk_version,10.15 + -fPIC + -fPIC +) +target_sources(archiver PRIVATE + ${CMAKE_SOURCE_DIR}/tools/archiver/main.cpp +) +vcs_info(archiver) diff --git a/tools/archiver/CMakeLists.linux-aarch64.txt b/tools/archiver/CMakeLists.linux-aarch64.txt new file mode 100644 index 0000000000..58061e88ce --- /dev/null +++ b/tools/archiver/CMakeLists.linux-aarch64.txt @@ -0,0 +1,32 @@ + +# This file was gererated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_executable(archiver) +target_link_libraries(archiver PUBLIC + contrib-libs-cxxsupp + yutil + library-cpp-lfalloc + library-cpp-archive + cpp-digest-md5 + cpp-getopt-small +) +target_link_options(archiver PRIVATE + -ldl + -lrt + -Wl,--no-as-needed + -fPIC + -fPIC + -lpthread + -lrt + -ldl +) +target_sources(archiver PRIVATE + ${CMAKE_SOURCE_DIR}/tools/archiver/main.cpp +) +vcs_info(archiver) diff --git a/tools/archiver/CMakeLists.linux.txt b/tools/archiver/CMakeLists.linux.txt new file mode 100644 index 0000000000..df98982aea --- /dev/null +++ b/tools/archiver/CMakeLists.linux.txt @@ -0,0 +1,34 @@ + +# This file was gererated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_executable(archiver) +target_link_libraries(archiver PUBLIC + contrib-libs-cxxsupp + yutil + cpp-malloc-tcmalloc + libs-tcmalloc-no_percpu_cache + library-cpp-cpuid_check + library-cpp-archive + cpp-digest-md5 + cpp-getopt-small +) +target_link_options(archiver PRIVATE + -ldl + -lrt + -Wl,--no-as-needed + -fPIC + -fPIC + -lpthread + -lrt + -ldl +) +target_sources(archiver PRIVATE + ${CMAKE_SOURCE_DIR}/tools/archiver/main.cpp +) +vcs_info(archiver) diff --git a/tools/archiver/CMakeLists.txt b/tools/archiver/CMakeLists.txt new file mode 100644 index 0000000000..3e0811fb22 --- /dev/null +++ b/tools/archiver/CMakeLists.txt @@ -0,0 +1,15 @@ + +# This file was gererated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + +if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" AND UNIX AND NOT APPLE AND NOT ANDROID) + include(CMakeLists.linux-aarch64.txt) +elseif (APPLE) + include(CMakeLists.darwin.txt) +elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND UNIX AND NOT APPLE AND NOT ANDROID) + include(CMakeLists.linux.txt) +endif() diff --git a/ydb/public/lib/ydb_cli/commands/ydb_service_export.cpp b/ydb/public/lib/ydb_cli/commands/ydb_service_export.cpp index f6bf872d63..47230af16b 100644 --- a/ydb/public/lib/ydb_cli/commands/ydb_service_export.cpp +++ b/ydb/public/lib/ydb_cli/commands/ydb_service_export.cpp @@ -244,6 +244,14 @@ void TCommandExportToS3::Config(TConfig& config) { config.Opts->AddLongOption("secret-key", secretKeyHelp) .RequiredArgument("STRING"); + TStringBuilder profileHelp; + profileHelp << "Named profile in \"" << AwsCredentialsFile << "\" file" << Endl + << " Search order:" << Endl + << " 1. This option" << Endl + << " 2. \"AWS_PROFILE\" environment variable"; + config.Opts->AddLongOption("aws-profile", profileHelp) + .RequiredArgument("STRING").DefaultValue(AwsDefaultProfileName); + TStringBuilder itemHelp; itemHelp << "[At least one] Item specification" << Endl << " Possible property names:" << Endl @@ -278,6 +286,7 @@ void TCommandExportToS3::Parse(TConfig& config) { TClientCommand::Parse(config); ParseFormats(); + ParseAwsProfile(config, "aws-profile"); ParseAwsAccessKey(config, "access-key"); ParseAwsSecretKey(config, "secret-key"); diff --git a/ydb/public/lib/ydb_cli/commands/ydb_service_import.cpp b/ydb/public/lib/ydb_cli/commands/ydb_service_import.cpp index 4a74452c62..63420950a2 100644 --- a/ydb/public/lib/ydb_cli/commands/ydb_service_import.cpp +++ b/ydb/public/lib/ydb_cli/commands/ydb_service_import.cpp @@ -59,6 +59,14 @@ void TCommandImportFromS3::Config(TConfig& config) { config.Opts->AddLongOption("secret-key", secretKeyHelp) .RequiredArgument("STRING"); + TStringBuilder profileHelp; + profileHelp << "Named profile in \"" << AwsCredentialsFile << "\" file" << Endl + << " Search order:" << Endl + << " 1. This option" << Endl + << " 2. \"AWS_PROFILE\" environment variable"; + config.Opts->AddLongOption("aws-profile", profileHelp) + .RequiredArgument("STRING").DefaultValue(AwsDefaultProfileName); + TStringBuilder itemHelp; itemHelp << "[At least one] Item specification" << Endl << " Possible property names:" << Endl @@ -81,6 +89,7 @@ void TCommandImportFromS3::Parse(TConfig& config) { TClientCommand::Parse(config); ParseFormats(); + ParseAwsProfile(config, "aws-profile"); ParseAwsAccessKey(config, "access-key"); ParseAwsSecretKey(config, "secret-key"); diff --git a/ydb/public/lib/ydb_cli/common/CMakeLists.txt b/ydb/public/lib/ydb_cli/common/CMakeLists.txt index caa40109b8..5085bc0b28 100644 --- a/ydb/public/lib/ydb_cli/common/CMakeLists.txt +++ b/ydb/public/lib/ydb_cli/common/CMakeLists.txt @@ -12,6 +12,7 @@ add_library(common) target_link_libraries(common PUBLIC contrib-libs-cxxsupp yutil + library-cpp-config library-cpp-getopt cpp-json-writer cpp-yaml-as diff --git a/ydb/public/lib/ydb_cli/common/aws.cpp b/ydb/public/lib/ydb_cli/common/aws.cpp index 2712c91954..9bda8812db 100644 --- a/ydb/public/lib/ydb_cli/common/aws.cpp +++ b/ydb/public/lib/ydb_cli/common/aws.cpp @@ -1,53 +1,37 @@ #include "aws.h" -namespace NYdb { -namespace NConsoleClient { +namespace NYdb::NConsoleClient { -const TString TCommandWithAwsCredentials::AwsCredentialsFile= "~/.aws/credentials"; +const TString TCommandWithAwsCredentials::AwsCredentialsFile = "~/.aws/credentials"; +const TString TCommandWithAwsCredentials::AwsDefaultProfileName = "default"; -const TString& TCommandWithAwsCredentials::ReadAwsCredentialsFile() { - if (!FileContent) { - TString credentialsFile = AwsCredentialsFile; - FileContent = ReadFromFile(credentialsFile, "AWS Credentials"); - } +TString TCommandWithAwsCredentials::ReadIniKey(const TString& iniKey) { + using namespace NConfig; - return FileContent.GetRef(); -} + const auto fileName = "AWS Credentials"; + const auto& profileName = AwsProfile.GetOrElse(AwsDefaultProfileName); -static bool IsSkipSymbol(char s) { - switch (s) { - case ' ': - case '\t': - case '=': - return true; - } - return false; -} + try { + if (!Config) { + TString filePath = AwsCredentialsFile; + const auto content = ReadFromFile(filePath, fileName); + Config.ConstructInPlace(TConfig::ReadIni(content)); + } -static TStringBuf GetKey(TStringBuf content, const TString& key) { - TStringBuf line; - while (content.ReadLine(line)) { - if (!line.SkipPrefix(key)) { - continue; + const auto& profiles = Config->Get<TDict>(); + if (!profiles.contains(profileName)) { + throw yexception() << fileName << " file does not contain a profile '" << profileName << "'"; } - while (!line.empty() && IsSkipSymbol(line.front())) { - line.Skip(1); + const auto& profile = profiles.At(profileName).Get<TDict>(); + if (!profile.contains(iniKey)) { + throw yexception() << "Invalid profile '" << profileName << "' in " << fileName << " file"; } - return line; + return profile.At(iniKey).As<TString>(); + } catch (const TConfigError& ex) { + throw yexception() << "Invalid " << fileName << " file: " << ex.what(); } - - throw TMisuseException() << "Cannot find \"" << key << "\" key"; } -void TCommandWithAwsCredentials::ReadAwsAccessKey() { - AwsAccessKey = GetKey(ReadAwsCredentialsFile(), "aws_access_key_id"); -} - -void TCommandWithAwsCredentials::ReadAwsSecretKey() { - AwsSecretKey = GetKey(ReadAwsCredentialsFile(), "aws_secret_access_key"); -} - -} } diff --git a/ydb/public/lib/ydb_cli/common/aws.h b/ydb/public/lib/ydb_cli/common/aws.h index 5d793b6b38..1fb12c83df 100644 --- a/ydb/public/lib/ydb_cli/common/aws.h +++ b/ydb/public/lib/ydb_cli/common/aws.h @@ -2,61 +2,62 @@ #include "command.h" +#include <library/cpp/config/config.h> + #include <util/generic/maybe.h> #include <util/system/env.h> -namespace NYdb { -namespace NConsoleClient { +namespace NYdb::NConsoleClient { class TCommandWithAwsCredentials { - template <typename TOpt, typename TReaderFunc> - static void Parse( - const TClientCommand::TConfig& config, - const TOpt opt, - const TString& envKey, - TString& parsed, - TReaderFunc readerFunc) { - + template <typename TOpt> + void Parse(const TClientCommand::TConfig& config, const TOpt opt, + const TString& envKey, const TString& iniKey, TString& value) + { if (config.ParseResult->Has(opt)) { - parsed = config.ParseResult->Get(opt); + value = config.ParseResult->Get(opt); } else { - TString fromEnv = GetEnv(envKey); - - if (!fromEnv.empty()) { - parsed = std::move(fromEnv); + if (auto fromEnv = GetEnv(envKey)) { + value = std::move(fromEnv); } else { - readerFunc(); + value = ReadIniKey(iniKey); } } } + TString ReadIniKey(const TString& iniKey); + protected: template <typename TOpt> + void ParseAwsProfile(const TClientCommand::TConfig& config, const TOpt opt) { + if (config.ParseResult->Has(opt)) { + AwsProfile = config.ParseResult->Get(opt); + } else { + if (auto fromEnv = GetEnv("AWS_PROFILE")) { + AwsProfile = std::move(fromEnv); + } + } + } + + template <typename TOpt> void ParseAwsAccessKey(const TClientCommand::TConfig& config, const TOpt opt) { - Parse(config, opt, "AWS_ACCESS_KEY_ID", AwsAccessKey, [this]() { - ReadAwsAccessKey(); - }); + Parse(config, opt, "AWS_ACCESS_KEY_ID", "aws_access_key_id", AwsAccessKey); } template <typename TOpt> void ParseAwsSecretKey(const TClientCommand::TConfig& config, const TOpt opt) { - Parse(config, opt, "AWS_SECRET_ACCESS_KEY", AwsSecretKey, [this]() { - ReadAwsSecretKey(); - }); + Parse(config, opt, "AWS_SECRET_ACCESS_KEY", "aws_secret_access_key", AwsSecretKey); } TString AwsAccessKey; TString AwsSecretKey; static const TString AwsCredentialsFile; + static const TString AwsDefaultProfileName; private: - const TString& ReadAwsCredentialsFile(); - void ReadAwsAccessKey(); - void ReadAwsSecretKey(); - - TMaybe<TString> FileContent; + TMaybe<NConfig::TConfig> Config; + TMaybe<TString> AwsProfile; }; } -} |