aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxenoxeno <xeno@ydb.tech>2022-12-08 11:28:30 +0300
committerxenoxeno <xeno@ydb.tech>2022-12-08 11:28:30 +0300
commiteed92b7f0e540b51866213f2e2e044305591b747 (patch)
treef98bc55b77e8466814661ccb97b7c981b86b2b06
parentf514d7d71c5789e348ba1a693f74c89d28b08fea (diff)
downloadydb-eed92b7f0e540b51866213f2e2e044305591b747.tar.gz
add auth support to tenant (database) commands
-rw-r--r--ydb/core/driver_lib/cli_base/cli_grpc.h32
-rw-r--r--ydb/core/driver_lib/cli_utils/cli_cmds_tenant.cpp7
2 files changed, 39 insertions, 0 deletions
diff --git a/ydb/core/driver_lib/cli_base/cli_grpc.h b/ydb/core/driver_lib/cli_base/cli_grpc.h
index f042a6399cc..2ee13a32e72 100644
--- a/ydb/core/driver_lib/cli_base/cli_grpc.h
+++ b/ydb/core/driver_lib/cli_base/cli_grpc.h
@@ -7,6 +7,7 @@
#include <library/cpp/grpc/client/grpc_client_low.h>
#include <ydb/public/api/protos/ydb_operation.pb.h>
#include <ydb/public/api/grpc/ydb_operation_v1.grpc.pb.h>
+#include <ydb/public/api/grpc/ydb_auth_v1.grpc.pb.h>
#include <util/string/split.h>
#include <util/string/type.h>
@@ -95,11 +96,42 @@ public:
ClientConfig.SslCredentials.pem_root_certs = CommandConfig.ClientConfig.SslCredentials.pem_root_certs;
}
+ static int PrepareConfigCredentials(NGRpcProxy::TGRpcClientConfig clientConfig, TConfig& commandConfig) {
+ int res = 0;
+
+ if (!commandConfig.StaticCredentials.User.empty()) {
+ Ydb::Auth::LoginRequest request;
+ Ydb::Operations::Operation response;
+ request.set_user(commandConfig.StaticCredentials.User);
+ request.set_password(commandConfig.StaticCredentials.Password);
+ res = DoGRpcRequest<Ydb::Auth::V1::AuthService,
+ Ydb::Auth::LoginRequest,
+ Ydb::Auth::LoginResponse>(clientConfig, request, response, &Ydb::Auth::V1::AuthService::Stub::AsyncLogin, {});
+ if (res == 0 && response.status() == Ydb::StatusIds::SUCCESS) {
+ Ydb::Auth::LoginResult result;
+ if (response.result().UnpackTo(&result)) {
+ commandConfig.SecurityToken = result.token();
+ }
+ } else {
+ Cerr << response.status() << Endl;
+ for (auto &issue : response.issues()) {
+ Cerr << issue.message() << Endl;
+ }
+ }
+ }
+ return res;
+ }
+
int Run(TConfig& config) override
{
Ydb::Operations::Operation response;
int res;
+ res = PrepareConfigCredentials(ClientConfig, config);
+ if (!res) {
+ return res;
+ }
+
res = DoGRpcRequest<TService, TRequest, TResponse, TFunction>
(ClientConfig, GRpcRequest, response, function, config.SecurityToken);
diff --git a/ydb/core/driver_lib/cli_utils/cli_cmds_tenant.cpp b/ydb/core/driver_lib/cli_utils/cli_cmds_tenant.cpp
index bdfe9316c57..1ed1a8fbf5d 100644
--- a/ydb/core/driver_lib/cli_utils/cli_cmds_tenant.cpp
+++ b/ydb/core/driver_lib/cli_utils/cli_cmds_tenant.cpp
@@ -6,6 +6,7 @@
#include <ydb/public/sdk/cpp/client/resources/ydb_resources.h>
#include <ydb/public/api/grpc/ydb_operation_v1.grpc.pb.h>
+#include <ydb/public/api/grpc/ydb_auth_v1.grpc.pb.h>
#include <ydb/public/api/grpc/ydb_cms_v1.grpc.pb.h>
#include <util/string/split.h>
@@ -147,6 +148,12 @@ public:
Ydb::Operations::Operation response;
int res;
+ res = TClientGRpcCommand<TService, TRequest, TResponse, TFunction, function>::PrepareConfigCredentials(ClientConfig, config);
+
+ if (!res) {
+ return res;
+ }
+
res = DoGRpcRequest<TService, TRequest, TResponse, TFunction>
(ClientConfig, GRpcRequest, response, function, config.SecurityToken);