|
| 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 | +} |
0 commit comments