|
23 | 23 | #include <string> |
24 | 24 | #include <unordered_map> |
25 | 25 |
|
26 | | -#include "iceberg/catalog/rest/auth/auth_session.h" |
27 | 26 | #include "iceberg/catalog/rest/iceberg_rest_export.h" |
| 27 | +#include "iceberg/catalog/rest/type_fwd.h" |
28 | 28 | #include "iceberg/result.h" |
29 | 29 | #include "iceberg/table_identifier.h" |
30 | 30 |
|
31 | 31 | /// \file iceberg/catalog/rest/auth/auth_manager.h |
32 | 32 | /// \brief Authentication manager interface for REST catalog. |
33 | 33 |
|
34 | | -namespace iceberg::rest { |
35 | | -class HttpClient; |
36 | | -} // namespace iceberg::rest |
37 | | - |
38 | 34 | namespace iceberg::rest::auth { |
39 | 35 |
|
40 | | -/// \brief Manager for authentication sessions. |
41 | | -/// |
42 | | -/// This interface is used to create sessions for the catalog, tables/views, |
43 | | -/// and any other context that requires authentication. |
44 | | -/// |
45 | | -/// Managers are typically stateful and may require initialization and cleanup. |
46 | | -/// The manager is created by the catalog and is closed when the catalog is closed. |
47 | | -/// |
48 | | -/// This interface is modeled after Java Iceberg's AuthManager interface. |
| 36 | +/// \brief Produces authentication sessions for catalog and table requests. |
49 | 37 | class ICEBERG_REST_EXPORT AuthManager { |
50 | 38 | public: |
51 | 39 | virtual ~AuthManager() = default; |
52 | 40 |
|
53 | | - /// \brief Return a temporary session for contacting the configuration endpoint. |
54 | | - /// |
55 | | - /// This session is used only during catalog initialization to fetch server |
56 | | - /// configuration. The returned session will be closed after the configuration |
57 | | - /// endpoint is contacted and should not be cached. |
58 | | - /// |
59 | | - /// The provided HTTP client is a short-lived client; it should only be used |
60 | | - /// to fetch initial credentials if required, and must be discarded after that. |
| 41 | + /// \brief Create a short-lived session used to contact the configuration endpoint. |
61 | 42 | /// |
62 | | - /// By default, it returns the catalog session. |
63 | | - /// |
64 | | - /// \param init_client A short-lived HTTP client for initialization. |
65 | | - /// \param properties Configuration properties. |
66 | | - /// \return A session for initialization, or an error if session creation fails. |
67 | | - virtual Result<std::shared_ptr<AuthSession>> InitSession( |
68 | | - HttpClient* init_client, |
| 43 | + /// \param init_client HTTP client used for initialization requests. |
| 44 | + /// \param properties Client configuration supplied by the catalog. |
| 45 | + /// \return Session for initialization or an error if credentials cannot be acquired. |
| 46 | + virtual Result<std::unique_ptr<AuthSession>> InitSession( |
| 47 | + HttpClient& init_client, |
69 | 48 | const std::unordered_map<std::string, std::string>& properties); |
70 | 49 |
|
71 | | - /// \brief Return a long-lived session for catalog operations. |
72 | | - /// |
73 | | - /// This session's lifetime is tied to the owning catalog. It serves as the |
74 | | - /// parent session for all other sessions (contextual and table-specific). |
75 | | - /// It is closed when the owning catalog is closed. |
| 50 | + /// \brief Create the long-lived catalog session that acts as the parent session. |
76 | 51 | /// |
77 | | - /// The provided HTTP client is a long-lived, shared client. Implementors may |
78 | | - /// store it and reuse it for subsequent requests to the authorization server |
79 | | - /// (e.g., for renewing or refreshing credentials). It is not necessary to |
80 | | - /// close it when Close() is called. |
81 | | - /// |
82 | | - /// It is not required to cache the returned session internally, as the catalog |
83 | | - /// will keep it alive for the lifetime of the catalog. |
84 | | - /// |
85 | | - /// \param shared_client A long-lived, shared HTTP client. |
86 | | - /// \param properties Configuration properties (merged with server config). |
87 | | - /// \return A session for catalog operations, or an error if session creation fails |
88 | | - /// (e.g., missing required credentials, network failure during token fetch). |
89 | | - virtual Result<std::shared_ptr<AuthSession>> CatalogSession( |
90 | | - HttpClient* shared_client, |
| 52 | + /// \param shared_client HTTP client owned by the catalog and reused for auth calls. |
| 53 | + /// \param properties Catalog properties (client config + server defaults). |
| 54 | + /// \return Session for catalog operations or an error if authentication cannot be set |
| 55 | + /// up. |
| 56 | + virtual Result<std::unique_ptr<AuthSession>> CatalogSession( |
| 57 | + HttpClient& shared_client, |
91 | 58 | const std::unordered_map<std::string, std::string>& properties) = 0; |
92 | 59 |
|
93 | | - /// \brief Return a session for a specific table or view. |
94 | | - /// |
95 | | - /// If the table or view requires a specific AuthSession (e.g., vended credentials), |
96 | | - /// this method should return a new AuthSession instance. Otherwise, it should |
97 | | - /// return the parent session. |
98 | | - /// |
99 | | - /// By default, it returns the parent session. |
| 60 | + /// \brief Create or reuse a session scoped to a single table/view. |
100 | 61 | /// |
101 | | - /// Implementors should cache table sessions internally, as the catalog will not |
102 | | - /// cache them. Also, the owning catalog never closes table sessions; implementations |
103 | | - /// should manage their lifecycle and close them when they are no longer needed. |
| 62 | + /// This method can return a new table-specific session or indicate that the parent |
| 63 | + /// catalog session should be reused by returning nullptr. |
104 | 64 | /// |
105 | | - /// \param table The table identifier. |
106 | | - /// \param properties Properties returned by the table/view endpoint. |
107 | | - /// \param parent The parent session (typically the catalog session). |
108 | | - /// \return A session for the table, or an error if session creation fails. |
109 | | - virtual Result<std::shared_ptr<AuthSession>> TableSession( |
| 65 | + /// \param table Target table identifier. |
| 66 | + /// \param properties Table-specific auth properties returned by the server. |
| 67 | + /// \param parent Catalog session to read information from. |
| 68 | + /// \return A new session for the table, nullptr to reuse parent, or an error. |
| 69 | + virtual Result<std::unique_ptr<AuthSession>> TableSession( |
110 | 70 | const TableIdentifier& table, |
111 | 71 | const std::unordered_map<std::string, std::string>& properties, |
112 | | - std::shared_ptr<AuthSession> parent); |
| 72 | + const AuthSession& parent); |
113 | 73 |
|
114 | | - /// \brief Close the manager and release any resources. |
| 74 | + /// \brief Release resources held by the manager. |
115 | 75 | /// |
116 | | - /// This method is called when the owning catalog is closed. Implementations |
117 | | - /// should release any resources held by the manager, such as cached sessions |
118 | | - /// or background threads. |
119 | | - virtual void Close() {} |
| 76 | + /// \return Status of the close operation. |
| 77 | + virtual Status Close() { return {}; } |
120 | 78 | }; |
121 | 79 |
|
122 | 80 | } // namespace iceberg::rest::auth |
0 commit comments