Skip to content

Commit a8a77a8

Browse files
Import YDB C++ SDK 22 (#550)
1 parent 94535ac commit a8a77a8

File tree

22 files changed

+405
-237
lines changed

22 files changed

+405
-237
lines changed

.github/import_generation.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
22
1+
23

.github/last_commit.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a1abe1a8139be6a6188d79503a63aa2e5068c6c1
1+
9563c7b171619687436257273b34ceba261903ed

examples/auth/ssa_delegation/main.cpp

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#include <ydb-cpp-sdk/client/query/client.h>
2+
#include <ydb-cpp-sdk/client/iam/iam.h>
3+
#include <ydb-cpp-sdk/client/iam_private/iam.h>
4+
5+
#include <library/cpp/getopt/last_getopt.h>
6+
7+
8+
int main(int argc, char** argv) {
9+
std::string endpoint;
10+
std::string database;
11+
std::string serviceId;
12+
std::string microserviceId;
13+
std::string targetServiceAccountId;
14+
std::string resourceId;
15+
std::string resourceType;
16+
std::string iamEndpoint;
17+
bool useSsl = false;
18+
NLastGetopt::TOpts opts = NLastGetopt::TOpts::Default();
19+
20+
opts.AddLongOption('e', "endpoint", "YDB endpoint").Required().RequiredArgument("HOST:PORT").StoreResult(&endpoint);
21+
opts.AddLongOption('d', "database", "YDB database").Required().RequiredArgument("PATH").StoreResult(&database);
22+
23+
opts.AddLongOption("ssl", "Use SSL").NoArgument().SetFlag(&useSsl);
24+
25+
opts.AddLongOption("target-service-account-id", "Target service account id")
26+
.Required()
27+
.RequiredArgument("ID")
28+
.StoreResult(&targetServiceAccountId);
29+
30+
opts.AddLongOption("service-id", "Service id")
31+
.RequiredArgument("ID")
32+
.DefaultValue("ydb")
33+
.StoreResult(&serviceId);
34+
35+
opts.AddLongOption("microservice-id", "Microservice id")
36+
.RequiredArgument("ID")
37+
.DefaultValue("control-plane")
38+
.StoreResult(&microserviceId);
39+
40+
opts.AddLongOption("resource-id", "Resource id")
41+
.Required()
42+
.RequiredArgument("ID")
43+
.StoreResult(&resourceId);
44+
45+
opts.AddLongOption("iam-endpoint", "IAM endpoint")
46+
.RequiredArgument("HOST")
47+
.DefaultValue("iam.api.cloud.yandex.net")
48+
.StoreResult(&iamEndpoint);
49+
50+
opts.AddLongOption("resource-type", "Resource type")
51+
.RequiredArgument("STRING")
52+
.DefaultValue("resource-manager.cloud")
53+
.StoreResult(&resourceType);
54+
55+
opts.SetFreeArgsMin(0);
56+
57+
NLastGetopt::TOptsParseResult optsResult(&opts, argc, argv);
58+
59+
NYdb::TIamServiceParams iamParams{
60+
.SystemServiceAccountCredentials = NYdb::CreateIamCredentialsProviderFactory(),
61+
.ServiceId = serviceId,
62+
.MicroserviceId = microserviceId,
63+
.ResourceId = resourceId,
64+
.ResourceType = resourceType,
65+
.TargetServiceAccountId = targetServiceAccountId,
66+
};
67+
68+
iamParams.Endpoint = iamEndpoint;
69+
70+
auto config = NYdb::TDriverConfig()
71+
.SetEndpoint(endpoint)
72+
.SetDatabase(database)
73+
.SetCredentialsProviderFactory(NYdb::CreateIamServiceCredentialsProviderFactory(iamParams));
74+
75+
if (useSsl) {
76+
config.UseSecureConnection();
77+
}
78+
79+
NYdb::TDriver driver(config);
80+
NYdb::NQuery::TQueryClient client(driver);
81+
82+
auto result = client.ExecuteQuery("SELECT 1", NYdb::NQuery::TTxControl::NoTx()).ExtractValueSync();
83+
if (!result.IsSuccess()) {
84+
std::cerr << ToString(static_cast<NYdb::TStatus>(result)) << std::endl;
85+
return 1;
86+
}
87+
88+
auto parser = result.GetResultSetParser(0);
89+
while (parser.TryNextRow()) {
90+
std::cout << parser.ColumnParser(0).GetInt32() << std::endl;
91+
}
92+
93+
return 0;
94+
}

include/ydb-cpp-sdk/client/arrow/accessor.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

include/ydb-cpp-sdk/client/iam/common/generic_provider.h

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ class TGrpcIamCredentialsProvider : public ICredentialsProvider {
2929
private:
3030
class TImpl : public std::enable_shared_from_this<TGrpcIamCredentialsProvider<TRequest, TResponse, TService>::TImpl> {
3131
public:
32-
TImpl(const TIamEndpoint& iamEndpoint, const TRequestFiller& requestFiller, TAsyncRpc rpc)
32+
TImpl(const TIamEndpoint& iamEndpoint,
33+
const TRequestFiller& requestFiller,
34+
TAsyncRpc rpc,
35+
TCredentialsProviderPtr authTokenProvider = nullptr)
3336
: Rpc_(rpc)
3437
, Ticket_("")
3538
, NextTicketUpdate_(TInstant::Zero())
@@ -40,6 +43,7 @@ class TGrpcIamCredentialsProvider : public ICredentialsProvider {
4043
, NeedStop_(false)
4144
, BackoffTimeout_(BACKOFF_START)
4245
, Lock_()
46+
, AuthTokenProvider_(authTokenProvider)
4347
{
4448
std::shared_ptr<grpc::ChannelCredentials> creds = nullptr;
4549
if (IamEndpoint_.EnableSsl) {
@@ -82,15 +86,18 @@ class TGrpcIamCredentialsProvider : public ICredentialsProvider {
8286

8387
RequestFiller_(req);
8488

85-
grpc::ClientContext context;
89+
Context_ = std::make_unique<grpc::ClientContext>();
8690

8791
auto deadline = gpr_time_add(
8892
gpr_now(GPR_CLOCK_MONOTONIC),
8993
gpr_time_from_micros(IamEndpoint_.RequestTimeout.MicroSeconds(), GPR_TIMESPAN));
9094

91-
context.set_deadline(deadline);
95+
Context_->set_deadline(deadline);
96+
if (AuthTokenProvider_) {
97+
Context_->AddMetadata("authorization", "Bearer " + AuthTokenProvider_->GetAuthInfo());
98+
}
9299

93-
(Stub_->async()->*Rpc_)(&context, &req, response.get(), std::move(cb));
100+
(Stub_->async()->*Rpc_)(Context_.get(), &req, response.get(), std::move(cb));
94101

95102
if (sync) {
96103
resultPromise.GetFuture().Wait(2 * IamEndpoint_.RequestTimeout);
@@ -125,6 +132,7 @@ class TGrpcIamCredentialsProvider : public ICredentialsProvider {
125132

126133
private:
127134
void ProcessIamResponse(grpc::Status&& status, TResponse&& result, bool sync) {
135+
Context_.reset();
128136
if (!status.ok()) {
129137
TDuration sleepDuration;
130138
{
@@ -163,6 +171,8 @@ class TGrpcIamCredentialsProvider : public ICredentialsProvider {
163171
std::shared_ptr<grpc::Channel> Channel_;
164172
std::shared_ptr<typename TService::Stub> Stub_;
165173
TAsyncRpc Rpc_;
174+
std::unique_ptr<grpc::ClientContext> Context_;
175+
166176
std::string Ticket_;
167177
TInstant NextTicketUpdate_;
168178
const TIamEndpoint IamEndpoint_;
@@ -172,11 +182,15 @@ class TGrpcIamCredentialsProvider : public ICredentialsProvider {
172182
bool NeedStop_;
173183
TDuration BackoffTimeout_;
174184
TAdaptiveLock Lock_;
185+
TCredentialsProviderPtr AuthTokenProvider_;
175186
};
176187

177188
public:
178-
TGrpcIamCredentialsProvider(const TIamEndpoint& endpoint, const TRequestFiller& requestFiller, TAsyncRpc rpc)
179-
: Impl_(std::make_shared<TImpl>(endpoint, requestFiller, rpc))
189+
TGrpcIamCredentialsProvider(const TIamEndpoint& endpoint,
190+
const TRequestFiller& requestFiller,
191+
TAsyncRpc rpc,
192+
TCredentialsProviderPtr authTokenProvider = nullptr)
193+
: Impl_(std::make_shared<TImpl>(endpoint, requestFiller, rpc, authTokenProvider))
180194
{
181195
Impl_->UpdateTicket(true);
182196
}

include/ydb-cpp-sdk/client/iam/common/types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <fstream>
99
#include <string>
1010

11-
namespace NYdb {
11+
namespace NYdb::inline V3 {
1212
namespace NIam {
1313

1414
constexpr std::string_view DEFAULT_ENDPOINT = "iam.api.cloud.yandex.net";

include/ydb-cpp-sdk/client/iam_private/common/types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace NYdb::inline V3 {
66

77
struct TIamServiceParams : TIamEndpoint {
8+
TCredentialsProviderFactoryPtr SystemServiceAccountCredentials;
9+
810
std::string ServiceId;
911
std::string MicroserviceId;
1012
std::string ResourceId;

include/ydb-cpp-sdk/client/scheme/scheme.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ enum class ESchemeEntryType : i32 {
5252
ResourcePool = 21,
5353
SysView = 22,
5454
Transfer = 23,
55+
StreamingQuery = 24,
5556
};
5657

5758
struct TVirtualTimestamp {

include/ydb-cpp-sdk/client/table/table.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ class TColumnFamilyDescription {
652652
const std::string& GetName() const;
653653
std::optional<std::string> GetData() const;
654654
std::optional<EColumnFamilyCompression> GetCompression() const;
655+
std::optional<EColumnFamilyCacheMode> GetCacheMode() const;
655656
std::optional<bool> GetKeepInMemory() const;
656657

657658
private:
@@ -829,6 +830,7 @@ class TColumnFamilyBuilder {
829830

830831
TColumnFamilyBuilder& SetData(const std::string& media);
831832
TColumnFamilyBuilder& SetCompression(EColumnFamilyCompression compression);
833+
TColumnFamilyBuilder& SetCacheMode(EColumnFamilyCacheMode cacheMode);
832834
TColumnFamilyBuilder& SetKeepInMemory(bool enabled);
833835

834836
TColumnFamilyDescription Build() const;
@@ -895,6 +897,11 @@ class TTableColumnFamilyBuilder {
895897
return *this;
896898
}
897899

900+
TTableColumnFamilyBuilder& SetCacheMode(EColumnFamilyCacheMode cacheMode) {
901+
Builder_.SetCacheMode(cacheMode);
902+
return *this;
903+
}
904+
898905
TTableColumnFamilyBuilder& SetKeepInMemory(bool enabled) {
899906
Builder_.SetKeepInMemory(enabled);
900907
return *this;
@@ -1519,6 +1526,11 @@ class TAlterColumnFamilyBuilder {
15191526
return *this;
15201527
}
15211528

1529+
TAlterColumnFamilyBuilder& SetCacheMode(EColumnFamilyCacheMode cacheMode) {
1530+
Builder_.SetCacheMode(cacheMode);
1531+
return *this;
1532+
}
1533+
15221534
TAlterColumnFamilyBuilder& SetKeepInMemory(bool enabled) {
15231535
Builder_.SetKeepInMemory(enabled);
15241536
return *this;

include/ydb-cpp-sdk/client/table/table_enum.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ enum class EColumnFamilyCompression {
1111
LZ4,
1212
};
1313

14+
//! Column family cache mode
15+
enum class EColumnFamilyCacheMode {
16+
Regular,
17+
InMemory,
18+
};
19+
1420
//! State of build index operation
1521
enum class EBuildIndexState {
1622
Unspecified = 0,

0 commit comments

Comments
 (0)