Skip to content

Commit 82b490a

Browse files
author
shuxu.li
committed
feat: add restcatalog authentication api
1 parent 06a1a59 commit 82b490a

File tree

6 files changed

+12
-16
lines changed

6 files changed

+12
-16
lines changed

src/iceberg/catalog/rest/auth/auth_manager.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ Result<std::shared_ptr<AuthSession>> AuthManager::InitSession(
3232

3333
Result<std::shared_ptr<AuthSession>> AuthManager::ContextualSession(
3434
[[maybe_unused]] const std::unordered_map<std::string, std::string>& context,
35-
const std::shared_ptr<AuthSession>& parent) {
35+
std::shared_ptr<AuthSession> parent) {
3636
// By default, return the parent session as-is
3737
return parent;
3838
}
3939

4040
Result<std::shared_ptr<AuthSession>> AuthManager::TableSession(
4141
[[maybe_unused]] const TableIdentifier& table,
4242
[[maybe_unused]] const std::unordered_map<std::string, std::string>& properties,
43-
const std::shared_ptr<AuthSession>& parent) {
43+
std::shared_ptr<AuthSession> parent) {
4444
// By default, return the parent session as-is
4545
return parent;
4646
}

src/iceberg/catalog/rest/auth/auth_manager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class ICEBERG_REST_EXPORT AuthManager {
7676
/// session is needed, or an error if session creation fails.
7777
virtual Result<std::shared_ptr<AuthSession>> ContextualSession(
7878
const std::unordered_map<std::string, std::string>& context,
79-
const std::shared_ptr<AuthSession>& parent);
79+
std::shared_ptr<AuthSession> parent);
8080

8181
/// \brief Create or reuse a session scoped to a single table/view.
8282
///
@@ -91,7 +91,7 @@ class ICEBERG_REST_EXPORT AuthManager {
9191
virtual Result<std::shared_ptr<AuthSession>> TableSession(
9292
const TableIdentifier& table,
9393
const std::unordered_map<std::string, std::string>& properties,
94-
const std::shared_ptr<AuthSession>& parent);
94+
std::shared_ptr<AuthSession> parent);
9595

9696
/// \brief Release resources held by the manager.
9797
///

src/iceberg/catalog/rest/auth/auth_managers.cc

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,7 @@ namespace {
3333
using AuthManagerRegistry =
3434
std::unordered_map<std::string, AuthManagerFactory, StringHash, StringEqual>;
3535

36-
/// \brief Infer the authentication type from properties.
37-
///
38-
/// If no explicit auth type is set, this function tries to infer it from
39-
/// other properties. If "credential" or "token" is present, it implies
40-
/// OAuth2 authentication. Otherwise, defaults to no authentication.
41-
///
42-
/// This behavior is consistent with Java Iceberg's AuthManagers.
36+
// Infer the authentication type from properties.
4337
std::string InferAuthType(
4438
const std::unordered_map<std::string, std::string>& properties) {
4539
auto it = properties.find(AuthProperties::kAuthType);
@@ -54,11 +48,10 @@ std::string InferAuthType(
5448
return AuthProperties::kAuthTypeOAuth2;
5549
}
5650

57-
// Default to no authentication
5851
return AuthProperties::kAuthTypeNone;
5952
}
6053

61-
/// \brief Get the global registry of auth manager factories.
54+
// Get the global registry of auth manager factories.
6255
AuthManagerRegistry& GetRegistry() {
6356
static AuthManagerRegistry registry;
6457
return registry;

src/iceberg/catalog/rest/auth/auth_managers.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class ICEBERG_REST_EXPORT AuthManagers {
5757

5858
/// \brief Register or override the factory for a given auth type.
5959
///
60+
/// This method is not thread-safe. All registrations should be done during
61+
/// application startup before any concurrent access to Load().
62+
///
6063
/// \param auth_type Case-insensitive type identifier (e.g., "basic").
6164
/// \param factory Factory function that produces the manager.
6265
static void Register(std::string_view auth_type, AuthManagerFactory factory);

src/iceberg/catalog/rest/auth/auth_session.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class DefaultAuthSession : public AuthSession {
4444

4545
} // namespace
4646

47-
std::shared_ptr<AuthSession> AuthSession::Make(
47+
std::shared_ptr<AuthSession> AuthSession::MakeDefault(
4848
std::unordered_map<std::string, std::string> headers) {
4949
return std::make_shared<DefaultAuthSession>(std::move(headers));
5050
}

src/iceberg/catalog/rest/auth/auth_session.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ class ICEBERG_REST_EXPORT AuthSession {
6060
/// \return Status indicating success or failure of closing the session.
6161
virtual Status Close() { return {}; }
6262

63-
/// \brief Create a session with static headers.
63+
/// \brief Create a default session with static headers.
6464
///
6565
/// This factory method creates a session that adds a fixed set of headers to each
6666
/// request. It is suitable for authentication methods that use static credentials,
6767
/// such as Basic auth or static bearer tokens.
6868
///
6969
/// \param headers The headers to add to each request for authentication.
7070
/// \return A new session that adds the given headers to requests.
71-
static std::shared_ptr<AuthSession> Make(
71+
static std::shared_ptr<AuthSession> MakeDefault(
7272
std::unordered_map<std::string, std::string> headers);
7373
};
7474

0 commit comments

Comments
 (0)