|
1 | 1 | #pragma once |
2 | 2 |
|
| 3 | +#include <ydb-cpp-sdk/client/iam/types.h> |
3 | 4 | #include <ydb-cpp-sdk/client/types/credentials/credentials.h> |
4 | | - |
5 | 5 | #include <ydb-cpp-sdk/library/grpc/client/grpc_client_low.h> |
6 | | -#include <library/cpp/threading/future/future.h> |
7 | 6 |
|
8 | | -#include <ydb-cpp-sdk/library/jwt/jwt.h> |
9 | | -#include <util/datetime/base.h> |
| 7 | +#include <library/cpp/threading/future/future.h> |
10 | 8 |
|
11 | | -#include <util/system/spinlock.h> |
12 | 9 | #include <util/string/builder.h> |
13 | | - |
14 | | -#include <fstream> |
| 10 | +#include <util/system/spinlock.h> |
15 | 11 |
|
16 | 12 | namespace NYdb { |
17 | 13 |
|
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 | | - |
67 | 14 | constexpr TDuration BACKOFF_START = TDuration::MilliSeconds(50); |
68 | 15 | constexpr TDuration BACKOFF_MAX = TDuration::Seconds(10); |
69 | 16 |
|
|
0 commit comments