|
22 | 22 | #include <unordered_set> |
23 | 23 |
|
24 | 24 | #include "iceberg/catalog/rest/auth/auth_manager_internal.h" |
| 25 | +#ifdef ICEBERG_BUILD_SIGV4 |
| 26 | +# include "iceberg/catalog/rest/auth/sigv4_auth_manager.h" |
| 27 | +#endif |
25 | 28 | #include "iceberg/catalog/rest/auth/auth_properties.h" |
26 | 29 | #include "iceberg/util/string_util.h" |
27 | 30 |
|
@@ -62,11 +65,15 @@ std::string InferAuthType( |
62 | 65 | } |
63 | 66 |
|
64 | 67 | AuthManagerRegistry CreateDefaultRegistry() { |
65 | | - return { |
| 68 | + AuthManagerRegistry registry = { |
66 | 69 | {AuthProperties::kAuthTypeNone, MakeNoopAuthManager}, |
67 | 70 | {AuthProperties::kAuthTypeBasic, MakeBasicAuthManager}, |
68 | 71 | {AuthProperties::kAuthTypeOAuth2, MakeOAuth2Manager}, |
69 | 72 | }; |
| 73 | +#ifdef ICEBERG_BUILD_SIGV4 |
| 74 | + registry[AuthProperties::kAuthTypeSigV4] = MakeSigV4AuthManager; |
| 75 | +#endif |
| 76 | + return registry; |
70 | 77 | } |
71 | 78 |
|
72 | 79 | // Get the global registry of auth manager factories. |
@@ -98,4 +105,28 @@ Result<std::unique_ptr<AuthManager>> AuthManagers::Load( |
98 | 105 | return it->second(name, properties); |
99 | 106 | } |
100 | 107 |
|
| 108 | +#ifdef ICEBERG_BUILD_SIGV4 |
| 109 | +Result<std::unique_ptr<AuthManager>> MakeSigV4AuthManager( |
| 110 | + std::string_view name, |
| 111 | + const std::unordered_map<std::string, std::string>& properties) { |
| 112 | + // Determine the delegate auth type. Default to OAuth2 if not specified. |
| 113 | + std::string delegate_type = AuthProperties::kAuthTypeOAuth2; |
| 114 | + auto it = properties.find(AuthProperties::kSigV4DelegateAuthType); |
| 115 | + if (it != properties.end() && !it->second.empty()) { |
| 116 | + delegate_type = StringUtils::ToLower(it->second); |
| 117 | + } |
| 118 | + |
| 119 | + // Prevent circular delegation (sigv4 -> sigv4 -> ...). |
| 120 | + ICEBERG_PRECHECK(delegate_type != AuthProperties::kAuthTypeSigV4, |
| 121 | + "Cannot delegate a SigV4 auth manager to another SigV4 auth manager"); |
| 122 | + |
| 123 | + // Load the delegate auth manager. |
| 124 | + auto delegate_props = properties; |
| 125 | + delegate_props[AuthProperties::kAuthType] = delegate_type; |
| 126 | + |
| 127 | + ICEBERG_ASSIGN_OR_RAISE(auto delegate, AuthManagers::Load(name, delegate_props)); |
| 128 | + return std::make_unique<SigV4AuthManager>(std::move(delegate)); |
| 129 | +} |
| 130 | +#endif |
| 131 | + |
101 | 132 | } // namespace iceberg::rest::auth |
0 commit comments