aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordcherednik <dcherednik@ydb.tech>2023-07-20 10:50:21 +0300
committerdcherednik <dcherednik@ydb.tech>2023-07-20 10:50:21 +0300
commit9b31bd3e66b480b9b9e1582b27c43fb23b9f4b28 (patch)
tree3204c64b707a864e64151b593df14d0369281316
parent5271c8a1bc3b04c646a8b42829dc848382d17314 (diff)
downloadydb-9b31bd3e66b480b9b9e1582b27c43fb23b9f4b28.tar.gz
Move sdk helpers to ydb.
-rw-r--r--ydb/public/sdk/cpp/client/CMakeLists.txt1
-rw-r--r--ydb/public/sdk/cpp/client/helpers/CMakeLists.darwin-x86_64.txt20
-rw-r--r--ydb/public/sdk/cpp/client/helpers/CMakeLists.linux-aarch64.txt21
-rw-r--r--ydb/public/sdk/cpp/client/helpers/CMakeLists.linux-x86_64.txt21
-rw-r--r--ydb/public/sdk/cpp/client/helpers/CMakeLists.txt17
-rw-r--r--ydb/public/sdk/cpp/client/helpers/CMakeLists.windows-x86_64.txt20
-rw-r--r--ydb/public/sdk/cpp/client/helpers/helpers.cpp68
-rw-r--r--ydb/public/sdk/cpp/client/helpers/helpers.h18
-rw-r--r--ydb/public/sdk/cpp/client/helpers/ya.make13
-rw-r--r--ydb/public/sdk/cpp/ya.make3
10 files changed, 201 insertions, 1 deletions
diff --git a/ydb/public/sdk/cpp/client/CMakeLists.txt b/ydb/public/sdk/cpp/client/CMakeLists.txt
index d43922488ec..808d1188223 100644
--- a/ydb/public/sdk/cpp/client/CMakeLists.txt
+++ b/ydb/public/sdk/cpp/client/CMakeLists.txt
@@ -8,6 +8,7 @@
add_subdirectory(draft)
add_subdirectory(extensions)
+add_subdirectory(helpers)
add_subdirectory(iam)
add_subdirectory(iam_private)
add_subdirectory(impl)
diff --git a/ydb/public/sdk/cpp/client/helpers/CMakeLists.darwin-x86_64.txt b/ydb/public/sdk/cpp/client/helpers/CMakeLists.darwin-x86_64.txt
new file mode 100644
index 00000000000..75ca665dbd7
--- /dev/null
+++ b/ydb/public/sdk/cpp/client/helpers/CMakeLists.darwin-x86_64.txt
@@ -0,0 +1,20 @@
+
+# This file was generated 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(cpp-client-helpers)
+target_link_libraries(cpp-client-helpers PUBLIC
+ contrib-libs-cxxsupp
+ yutil
+ cpp-client-iam
+ client-ydb_types-credentials
+ public-issue-protos
+)
+target_sources(cpp-client-helpers PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/public/sdk/cpp/client/helpers/helpers.cpp
+)
diff --git a/ydb/public/sdk/cpp/client/helpers/CMakeLists.linux-aarch64.txt b/ydb/public/sdk/cpp/client/helpers/CMakeLists.linux-aarch64.txt
new file mode 100644
index 00000000000..ef82cd84d1a
--- /dev/null
+++ b/ydb/public/sdk/cpp/client/helpers/CMakeLists.linux-aarch64.txt
@@ -0,0 +1,21 @@
+
+# This file was generated 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(cpp-client-helpers)
+target_link_libraries(cpp-client-helpers PUBLIC
+ contrib-libs-linux-headers
+ contrib-libs-cxxsupp
+ yutil
+ cpp-client-iam
+ client-ydb_types-credentials
+ public-issue-protos
+)
+target_sources(cpp-client-helpers PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/public/sdk/cpp/client/helpers/helpers.cpp
+)
diff --git a/ydb/public/sdk/cpp/client/helpers/CMakeLists.linux-x86_64.txt b/ydb/public/sdk/cpp/client/helpers/CMakeLists.linux-x86_64.txt
new file mode 100644
index 00000000000..ef82cd84d1a
--- /dev/null
+++ b/ydb/public/sdk/cpp/client/helpers/CMakeLists.linux-x86_64.txt
@@ -0,0 +1,21 @@
+
+# This file was generated 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(cpp-client-helpers)
+target_link_libraries(cpp-client-helpers PUBLIC
+ contrib-libs-linux-headers
+ contrib-libs-cxxsupp
+ yutil
+ cpp-client-iam
+ client-ydb_types-credentials
+ public-issue-protos
+)
+target_sources(cpp-client-helpers PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/public/sdk/cpp/client/helpers/helpers.cpp
+)
diff --git a/ydb/public/sdk/cpp/client/helpers/CMakeLists.txt b/ydb/public/sdk/cpp/client/helpers/CMakeLists.txt
new file mode 100644
index 00000000000..f8b31df0c11
--- /dev/null
+++ b/ydb/public/sdk/cpp/client/helpers/CMakeLists.txt
@@ -0,0 +1,17 @@
+
+# This file was generated 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_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" AND NOT HAVE_CUDA)
+ include(CMakeLists.linux-aarch64.txt)
+elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
+ include(CMakeLists.darwin-x86_64.txt)
+elseif (WIN32 AND CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" AND NOT HAVE_CUDA)
+ include(CMakeLists.windows-x86_64.txt)
+elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT HAVE_CUDA)
+ include(CMakeLists.linux-x86_64.txt)
+endif()
diff --git a/ydb/public/sdk/cpp/client/helpers/CMakeLists.windows-x86_64.txt b/ydb/public/sdk/cpp/client/helpers/CMakeLists.windows-x86_64.txt
new file mode 100644
index 00000000000..75ca665dbd7
--- /dev/null
+++ b/ydb/public/sdk/cpp/client/helpers/CMakeLists.windows-x86_64.txt
@@ -0,0 +1,20 @@
+
+# This file was generated 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(cpp-client-helpers)
+target_link_libraries(cpp-client-helpers PUBLIC
+ contrib-libs-cxxsupp
+ yutil
+ cpp-client-iam
+ client-ydb_types-credentials
+ public-issue-protos
+)
+target_sources(cpp-client-helpers PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/public/sdk/cpp/client/helpers/helpers.cpp
+)
diff --git a/ydb/public/sdk/cpp/client/helpers/helpers.cpp b/ydb/public/sdk/cpp/client/helpers/helpers.cpp
new file mode 100644
index 00000000000..541b05fb3ac
--- /dev/null
+++ b/ydb/public/sdk/cpp/client/helpers/helpers.cpp
@@ -0,0 +1,68 @@
+#include "helpers.h"
+
+#include <ydb/public/sdk/cpp/client/iam/iam.h>
+#include <ydb/public/sdk/cpp/client/resources/ydb_ca.h>
+#include <ydb/public/sdk/cpp/client/impl/ydb_internal/common/parser.h>
+#include <ydb/public/sdk/cpp/client/impl/ydb_internal/common/getenv.h>
+#include <util/stream/file.h>
+
+namespace NYdb {
+
+TDriverConfig CreateFromEnvironment(const TStringType& connectionString) {
+ TDriverConfig driverConfig;
+ if (connectionString != "") {
+ auto connectionInfo = ParseConnectionString(connectionString);
+ driverConfig.SetEndpoint(connectionInfo.Endpoint);
+ driverConfig.SetDatabase(connectionInfo.Database);
+ if (connectionInfo.EnableSsl) {
+ TStringType rootCertsFile = GetStrFromEnv("YDB_SSL_ROOT_CERTIFICATES_FILE", "");
+ TStringType rootCerts = GetRootCertificate();
+ if (rootCertsFile != "") {
+ TFileInput in(rootCertsFile);
+ rootCerts += in.ReadAll();
+ }
+ driverConfig.UseSecureConnection(rootCerts);
+ }
+ }
+
+ TStringType saKeyFile = GetStrFromEnv("YDB_SERVICE_ACCOUNT_KEY_FILE_CREDENTIALS", "");
+ if (!saKeyFile.empty()) {
+ driverConfig.SetCredentialsProviderFactory(
+ CreateIamJwtFileCredentialsProviderFactory({.JwtFilename = saKeyFile}));
+ return driverConfig;
+ }
+ bool anonymousUsed = GetStrFromEnv("YDB_ANONYMOUS_CREDENTIALS", "0") == "1";
+ if (anonymousUsed) {
+ return driverConfig;
+ }
+
+ bool useMetadataCredentials = GetStrFromEnv("YDB_METADATA_CREDENTIALS", "0") == "1";
+ if (useMetadataCredentials){
+ auto factory = CreateIamCredentialsProviderFactory();
+ try {
+ factory->CreateProvider();
+ } catch (yexception& e) {
+ ythrow yexception() << "Unable to get token from metadata service: " << e.what();
+ }
+ driverConfig.SetCredentialsProviderFactory(factory);
+ return driverConfig;
+ }
+
+ TStringType accessToken = GetStrFromEnv("YDB_ACCESS_TOKEN_CREDENTIALS", "");
+ if (accessToken != ""){
+ driverConfig.SetAuthToken(accessToken);
+ return driverConfig;
+ }
+
+ ythrow yexception() << "Unable to create driver config from environment";
+}
+
+TDriverConfig CreateFromSaKeyFile(const TStringType& saKeyFile, const TStringType& connectionString) {
+ TDriverConfig driverConfig(connectionString);
+ driverConfig.SetCredentialsProviderFactory(
+ CreateIamJwtFileCredentialsProviderFactory({.JwtFilename = saKeyFile}));
+ return driverConfig;
+}
+
+} // namespace NYdb
+
diff --git a/ydb/public/sdk/cpp/client/helpers/helpers.h b/ydb/public/sdk/cpp/client/helpers/helpers.h
new file mode 100644
index 00000000000..9471ebf6631
--- /dev/null
+++ b/ydb/public/sdk/cpp/client/helpers/helpers.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include <ydb/public/sdk/cpp/client/ydb_driver/driver.h>
+
+namespace NYdb {
+
+//! Checks the following environment variables and creates TDriverConfig with the first appeared:
+//! YDB_SERVICE_ACCOUNT_KEY_FILE_CREDENTIALS=<path-to-file> — service account key file,
+//! YDB_ANONYMOUS_CREDENTIALS="1" — uses anonymous access (used for test installation),
+//! YDB_METADATA_CREDENTIALS="1" — uses metadata service,
+//! YDB_ACCESS_TOKEN_CREDENTIALS=<access-token> — access token (for example, IAM-token).
+//! If grpcs protocol is given in endpoint (or protocol is empty), enables SSL and uses
+//! certificate from resourses and user cert from env variable "YDB_SERVICE_ACCOUNT_KEY_FILE_CREDENTIALS"
+TDriverConfig CreateFromEnvironment(const TStringType& connectionString = "");
+//! Creates TDriverConfig from cloud service account key file
+TDriverConfig CreateFromSaKeyFile(const TStringType& saKeyFile, const TStringType& connectionString = "");
+
+}
diff --git a/ydb/public/sdk/cpp/client/helpers/ya.make b/ydb/public/sdk/cpp/client/helpers/ya.make
new file mode 100644
index 00000000000..2203edcf66c
--- /dev/null
+++ b/ydb/public/sdk/cpp/client/helpers/ya.make
@@ -0,0 +1,13 @@
+LIBRARY()
+
+SRCS(
+ helpers.cpp
+)
+
+PEERDIR(
+ ydb/public/sdk/cpp/client/iam
+ ydb/public/sdk/cpp/client/ydb_types/credentials
+ ydb/library/yql/public/issue/protos
+)
+
+END()
diff --git a/ydb/public/sdk/cpp/ya.make b/ydb/public/sdk/cpp/ya.make
index a72c89fc5c0..752050f35aa 100644
--- a/ydb/public/sdk/cpp/ya.make
+++ b/ydb/public/sdk/cpp/ya.make
@@ -1,4 +1,6 @@
RECURSE(
+ client/extensions
+ client/helpers
client/ydb_types/credentials
client/ydb_discovery
client/ydb_types/status
@@ -49,7 +51,6 @@ RECURSE(
client/impl/ydb_internal/plain_status
client/impl/ydb_internal/thread_pool
client/impl/ydb_endpoints/ut
- client/extensions
client/impl/ydb_internal/logger
client/impl/ydb_internal/make_request
client/resources