|
19 | 19 |
|
20 | 20 | #pragma once |
21 | 21 |
|
| 22 | +#include <cstdint> |
| 23 | +#include <optional> |
22 | 24 | #include <string> |
23 | | -#include <string_view> |
| 25 | +#include <unordered_map> |
| 26 | + |
| 27 | +#include "iceberg/catalog/rest/iceberg_rest_export.h" |
| 28 | +#include "iceberg/result.h" |
| 29 | +#include "iceberg/util/config.h" |
24 | 30 |
|
25 | 31 | /// \file iceberg/catalog/rest/auth/auth_properties.h |
26 | | -/// \brief Property keys and constants for REST catalog authentication. |
| 32 | +/// \brief Property keys and configuration for REST catalog authentication. |
27 | 33 |
|
28 | 34 | namespace iceberg::rest::auth { |
29 | 35 |
|
30 | | -/// \brief Property keys and constants for authentication configuration. |
31 | | -/// |
32 | | -/// This struct defines all the property keys used to configure authentication |
33 | | -/// for the REST catalog. It follows the same naming conventions as Java Iceberg. |
34 | | -struct AuthProperties { |
35 | | - /// \brief Property key for specifying the authentication type. |
| 36 | +/// \brief Authentication properties |
| 37 | +class ICEBERG_REST_EXPORT AuthProperties : public ConfigBase<AuthProperties> { |
| 38 | + public: |
| 39 | + template <typename T> |
| 40 | + using Entry = const ConfigBase<AuthProperties>::Entry<T>; |
| 41 | + |
| 42 | + // ---- Authentication type constants (not Entry-based) ---- |
| 43 | + |
36 | 44 | inline static const std::string kAuthType = "rest.auth.type"; |
37 | | - /// \brief Authentication type: no authentication. |
38 | 45 | inline static const std::string kAuthTypeNone = "none"; |
39 | | - /// \brief Authentication type: HTTP Basic authentication. |
40 | 46 | inline static const std::string kAuthTypeBasic = "basic"; |
41 | | - /// \brief Authentication type: OAuth2 authentication. |
42 | 47 | inline static const std::string kAuthTypeOAuth2 = "oauth2"; |
43 | | - /// \brief Authentication type: AWS SigV4 authentication. |
44 | 48 | inline static const std::string kAuthTypeSigV4 = "sigv4"; |
45 | 49 |
|
46 | | - /// \brief Property key for Basic auth username. |
| 50 | + // ---- Basic auth entries ---- |
| 51 | + |
47 | 52 | inline static const std::string kBasicUsername = "rest.auth.basic.username"; |
48 | | - /// \brief Property key for Basic auth password. |
49 | 53 | inline static const std::string kBasicPassword = "rest.auth.basic.password"; |
50 | 54 |
|
51 | | - /// \brief Property key for OAuth2 token (bearer token). |
52 | | - inline static const std::string kOAuth2Token = "token"; |
53 | | - /// \brief Property key for OAuth2 credential (client_id:client_secret). |
54 | | - inline static const std::string kOAuth2Credential = "credential"; |
55 | | - /// \brief Property key for OAuth2 scope. |
56 | | - inline static const std::string kOAuth2Scope = "scope"; |
57 | | - /// \brief Property key for OAuth2 server URI. |
58 | | - inline static const std::string kOAuth2ServerUri = "oauth2-server-uri"; |
59 | | - /// \brief Property key for enabling token refresh. |
60 | | - inline static const std::string kOAuth2TokenRefreshEnabled = "token-refresh-enabled"; |
61 | | - /// \brief Default OAuth2 scope for catalog operations. |
62 | | - inline static const std::string kOAuth2DefaultScope = "catalog"; |
63 | | - |
64 | | - /// \brief Property key for SigV4 region. |
| 55 | + // ---- SigV4 entries ---- |
| 56 | + |
65 | 57 | inline static const std::string kSigV4Region = "rest.auth.sigv4.region"; |
66 | | - /// \brief Property key for SigV4 service name. |
67 | 58 | inline static const std::string kSigV4Service = "rest.auth.sigv4.service"; |
68 | | - /// \brief Property key for SigV4 delegate auth type. |
69 | 59 | inline static const std::string kSigV4DelegateAuthType = |
70 | 60 | "rest.auth.sigv4.delegate-auth-type"; |
| 61 | + |
| 62 | + // ---- OAuth2 entries ---- |
| 63 | + |
| 64 | + inline static Entry<std::string> kToken{"token", ""}; |
| 65 | + inline static Entry<std::string> kCredential{"credential", ""}; |
| 66 | + inline static Entry<std::string> kScope{"scope", "catalog"}; |
| 67 | + inline static Entry<std::string> kOAuth2ServerUri{"oauth2-server-uri", |
| 68 | + "v1/oauth/tokens"}; |
| 69 | + inline static Entry<bool> kKeepRefreshed{"token-refresh-enabled", true}; |
| 70 | + inline static Entry<bool> kExchangeEnabled{"token-exchange-enabled", true}; |
| 71 | + inline static Entry<std::string> kAudience{"audience", ""}; |
| 72 | + inline static Entry<std::string> kResource{"resource", ""}; |
| 73 | + |
| 74 | + /// \brief Build an AuthProperties from a properties map. |
| 75 | + static Result<AuthProperties> FromProperties( |
| 76 | + const std::unordered_map<std::string, std::string>& properties); |
| 77 | + |
| 78 | + /// \brief Get the bearer token. |
| 79 | + std::string token() const { return Get(kToken); } |
| 80 | + /// \brief Get the raw credential string. |
| 81 | + std::string credential() const { return Get(kCredential); } |
| 82 | + /// \brief Get the OAuth2 scope. |
| 83 | + std::string scope() const { return Get(kScope); } |
| 84 | + /// \brief Get the token endpoint URI. |
| 85 | + std::string oauth2_server_uri() const { return Get(kOAuth2ServerUri); } |
| 86 | + /// \brief Whether token refresh is enabled. |
| 87 | + bool keep_refreshed() const { return Get(kKeepRefreshed); } |
| 88 | + /// \brief Whether token exchange is enabled. |
| 89 | + bool exchange_enabled() const { return Get(kExchangeEnabled); } |
| 90 | + |
| 91 | + /// \brief Parsed client_id from credential (empty if no colon). |
| 92 | + const std::string& client_id() const { return client_id_; } |
| 93 | + /// \brief Parsed client_secret from credential. |
| 94 | + const std::string& client_secret() const { return client_secret_; } |
| 95 | + |
| 96 | + /// \brief Build optional OAuth params (audience, resource) from config. |
| 97 | + std::unordered_map<std::string, std::string> optional_oauth_params() const; |
| 98 | + |
| 99 | + private: |
| 100 | + std::string client_id_; |
| 101 | + std::string client_secret_; |
| 102 | + std::string token_type_; |
| 103 | + std::optional<int64_t> expires_at_millis_; |
71 | 104 | }; |
72 | 105 |
|
73 | 106 | } // namespace iceberg::rest::auth |
0 commit comments