Skip to content

Commit 78678ee

Browse files
authored
Remove grpc dependency leak through iam headers (#338)
1 parent 07e05c9 commit 78678ee

File tree

25 files changed

+212
-211
lines changed

25 files changed

+212
-211
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ endif()
5151
add_subdirectory(tools)
5252
add_subdirectory(contrib/libs)
5353
add_subdirectory(library/cpp)
54+
add_subdirectory(include/ydb-cpp-sdk/client)
5455
add_subdirectory(src)
5556
add_subdirectory(util)
5657

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(iam/common)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
_ydb_sdk_add_library(client-iam-types INTERFACE)
2+
3+
target_link_libraries(client-iam-types
4+
INTERFACE
5+
client-ydb_types-credentials
6+
library-jwt
7+
yutil
8+
)
9+
10+
_ydb_sdk_install_targets(client-iam-types)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#pragma once
2+
3+
#include <ydb-cpp-sdk/client/types/credentials/credentials.h>
4+
#include <ydb-cpp-sdk/library/jwt/jwt.h>
5+
6+
#include <util/datetime/base.h>
7+
8+
#include <fstream>
9+
#include <string>
10+
11+
namespace NYdb {
12+
13+
namespace NIam {
14+
15+
constexpr std::string_view DEFAULT_ENDPOINT = "iam.api.cloud.yandex.net";
16+
constexpr bool DEFAULT_ENABLE_SSL = true;
17+
18+
constexpr std::string_view DEFAULT_HOST = "169.254.169.254";
19+
constexpr uint32_t DEFAULT_PORT = 80;
20+
21+
constexpr TDuration DEFAULT_REFRESH_PERIOD = TDuration::Hours(1);
22+
constexpr TDuration DEFAULT_REQUEST_TIMEOUT = TDuration::Seconds(10);
23+
24+
}
25+
26+
struct TIamHost {
27+
std::string Host = std::string(NIam::DEFAULT_HOST);
28+
uint32_t Port = NIam::DEFAULT_PORT;
29+
TDuration RefreshPeriod = NIam::DEFAULT_REFRESH_PERIOD;
30+
};
31+
32+
struct TIamEndpoint {
33+
std::string Endpoint = std::string(NIam::DEFAULT_ENDPOINT);
34+
TDuration RefreshPeriod = NIam::DEFAULT_REFRESH_PERIOD;
35+
TDuration RequestTimeout = NIam::DEFAULT_REQUEST_TIMEOUT;
36+
bool EnableSsl = NIam::DEFAULT_ENABLE_SSL;
37+
};
38+
39+
struct TIamJwtFilename : TIamEndpoint { std::string JwtFilename; };
40+
41+
struct TIamJwtContent : TIamEndpoint { std::string JwtContent; };
42+
43+
struct TIamJwtParams : TIamEndpoint { TJwtParams JwtParams; };
44+
45+
struct TIamOAuth : TIamEndpoint { std::string OAuthToken; };
46+
47+
48+
inline TJwtParams ReadJwtKeyFile(const std::string& filename) {
49+
std::ifstream input(filename, std::ios::in);
50+
return ParseJwtParams({std::istreambuf_iterator<char>(input), std::istreambuf_iterator<char>()});
51+
}
52+
53+
}

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
11
#pragma once
22

3-
#include "common/iam.h"
3+
#include "common/types.h"
4+
5+
namespace NYdb {
6+
7+
/// Acquire an IAM token using a local metadata service on a virtual machine.
8+
TCredentialsProviderFactoryPtr CreateIamCredentialsProviderFactory(const TIamHost& params = {});
9+
10+
/// Acquire an IAM token using a JSON Web Token (JWT) file name.
11+
TCredentialsProviderFactoryPtr CreateIamJwtFileCredentialsProviderFactory(const TIamJwtFilename& params);
12+
13+
/// Acquire an IAM token using JSON Web Token (JWT) contents.
14+
TCredentialsProviderFactoryPtr CreateIamJwtParamsCredentialsProviderFactory(const TIamJwtContent& param);
15+
16+
// Acquire an IAM token using a user OAuth token.
17+
TCredentialsProviderFactoryPtr CreateIamOAuthCredentialsProviderFactory(const TIamOAuth& params);
18+
19+
}

include/ydb-cpp-sdk/client/iam_private/iam.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <ydb-cpp-sdk/client/iam/common/iam.h>
3+
#include <ydb-cpp-sdk/client/iam/common/types.h>
44

55
namespace NYdb {
66

src/client/helpers/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ target_link_libraries(client-helpers
44
PUBLIC
55
yutil
66
client-ydb_types-credentials-oauth2
7-
client-iam-common
7+
client-iam
88
client-ydb_types-credentials
99
)
1010

src/client/helpers/helpers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <ydb-cpp-sdk/client/helpers/helpers.h>
22

3-
#include <ydb-cpp-sdk/client/iam/common/iam.h>
3+
#include <ydb-cpp-sdk/client/iam/iam.h>
44
#include <ydb-cpp-sdk/client/resources/ydb_ca.h>
55
#include <ydb-cpp-sdk/client/types/credentials/oauth2_token_exchange/from_file.h>
66

src/client/iam/CMakeLists.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ add_subdirectory(common)
22

33
_ydb_sdk_add_library(client-iam)
44

5-
target_link_libraries(client-iam PUBLIC
6-
yutil
7-
api-client-yc_public
8-
client-iam-common
5+
target_link_libraries(client-iam
6+
PUBLIC
7+
client-iam-types
8+
yutil
9+
PRIVATE
10+
api-client-yc_public
11+
client-iam-common
12+
json
13+
http-simple
914
)
1015

11-
_ydb_sdk_install_targets(TARGETS client-iam)
12-
1316
target_sources(client-iam PRIVATE
1417
iam.cpp
1518
)
19+
20+
_ydb_sdk_make_client_component(Iam client-iam)

src/client/iam/common/CMakeLists.txt

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
_ydb_sdk_add_library(client-iam-common)
1+
_ydb_sdk_add_library(client-iam-common INTERFACE)
22

3-
target_link_libraries(client-iam-common PUBLIC
4-
yutil
5-
grpc-client
6-
http-simple
7-
json
8-
library-jwt
9-
client-ydb_types-credentials
10-
api-client-yc_public
3+
target_link_libraries(client-iam-common
4+
INTERFACE
5+
client-iam-types
6+
grpc-client
7+
threading-future
8+
yutil
119
)
1210

13-
target_sources(client-iam-common PRIVATE
14-
iam.cpp
15-
)
16-
17-
_ydb_sdk_make_client_component(Iam client-iam-common)
11+
_ydb_sdk_install_targets(client-iam-common)

src/client/iam/common/iam.cpp

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

include/ydb-cpp-sdk/client/iam/common/iam.h renamed to src/client/iam/common/iam.h

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,16 @@
11
#pragma once
22

3-
#include <ydb-cpp-sdk/client/types/credentials/credentials.h>
3+
#include <ydb-cpp-sdk/client/iam/common/types.h>
44

5-
#include <ydb-cpp-sdk/library/grpc/client/grpc_client_low.h>
6-
#include <library/cpp/threading/future/future.h>
5+
#include <src/library/grpc/client/grpc_client_low.h>
76

8-
#include <ydb-cpp-sdk/library/jwt/jwt.h>
9-
#include <util/datetime/base.h>
7+
#include <library/cpp/threading/future/future.h>
108

11-
#include <util/system/spinlock.h>
129
#include <util/string/builder.h>
13-
14-
#include <fstream>
10+
#include <util/system/spinlock.h>
1511

1612
namespace NYdb {
1713

18-
namespace NIam {
19-
constexpr std::string_view DEFAULT_ENDPOINT = "iam.api.cloud.yandex.net";
20-
constexpr bool DEFAULT_ENABLE_SSL = true;
21-
22-
constexpr std::string_view DEFAULT_HOST = "169.254.169.254";
23-
constexpr uint32_t DEFAULT_PORT = 80;
24-
25-
constexpr TDuration DEFAULT_REFRESH_PERIOD = TDuration::Hours(1);
26-
constexpr TDuration DEFAULT_REQUEST_TIMEOUT = TDuration::Seconds(10);
27-
}
28-
29-
struct TIamHost {
30-
std::string Host = std::string(NIam::DEFAULT_HOST);
31-
uint32_t Port = NIam::DEFAULT_PORT;
32-
TDuration RefreshPeriod = NIam::DEFAULT_REFRESH_PERIOD;
33-
};
34-
35-
struct TIamEndpoint {
36-
std::string Endpoint = std::string(NIam::DEFAULT_ENDPOINT);
37-
TDuration RefreshPeriod = NIam::DEFAULT_REFRESH_PERIOD;
38-
TDuration RequestTimeout = NIam::DEFAULT_REQUEST_TIMEOUT;
39-
bool EnableSsl = NIam::DEFAULT_ENABLE_SSL;
40-
};
41-
42-
struct TIamJwtFilename : TIamEndpoint { std::string JwtFilename; };
43-
44-
struct TIamJwtContent : TIamEndpoint { std::string JwtContent; };
45-
46-
struct TIamJwtParams : TIamEndpoint { TJwtParams JwtParams; };
47-
48-
inline TJwtParams ReadJwtKeyFile(const std::string& filename) {
49-
std::ifstream input(filename, std::ios::in);
50-
return ParseJwtParams({std::istreambuf_iterator<char>(input), std::istreambuf_iterator<char>()});
51-
}
52-
53-
struct TIamOAuth : TIamEndpoint { std::string OAuthToken; };
54-
55-
/// Acquire an IAM token using a local metadata service on a virtual machine.
56-
TCredentialsProviderFactoryPtr CreateIamCredentialsProviderFactory(const TIamHost& params = {});
57-
58-
/// Acquire an IAM token using a JSON Web Token (JWT) file name.
59-
TCredentialsProviderFactoryPtr CreateIamJwtFileCredentialsProviderFactory(const TIamJwtFilename& params);
60-
61-
/// Acquire an IAM token using JSON Web Token (JWT) contents.
62-
TCredentialsProviderFactoryPtr CreateIamJwtParamsCredentialsProviderFactory(const TIamJwtContent& param);
63-
64-
// Acquire an IAM token using a user OAuth token.
65-
TCredentialsProviderFactoryPtr CreateIamOAuthCredentialsProviderFactory(const TIamOAuth& params);
66-
6714
constexpr TDuration BACKOFF_START = TDuration::MilliSeconds(50);
6815
constexpr TDuration BACKOFF_MAX = TDuration::Seconds(10);
6916

0 commit comments

Comments
 (0)