|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +#pragma once |
| 21 | + |
| 22 | +#include <memory> |
| 23 | +#include <string> |
| 24 | +#include <unordered_map> |
| 25 | + |
| 26 | +#include "iceberg/catalog/rest/iceberg_rest_export.h" |
| 27 | +#include "iceberg/catalog/rest/type_fwd.h" |
| 28 | +#include "iceberg/result.h" |
| 29 | +#include "iceberg/type_fwd.h" |
| 30 | + |
| 31 | +/// \file iceberg/catalog/rest/auth/auth_manager.h |
| 32 | +/// \brief Authentication manager interface for REST catalog. |
| 33 | + |
| 34 | +namespace iceberg::rest::auth { |
| 35 | + |
| 36 | +/// \brief Produces authentication sessions for catalog and table requests. |
| 37 | +class ICEBERG_REST_EXPORT AuthManager { |
| 38 | + public: |
| 39 | + virtual ~AuthManager() = default; |
| 40 | + |
| 41 | + /// \brief Create a short-lived session used to contact the configuration endpoint. |
| 42 | + /// |
| 43 | + /// This session is used only during catalog initialization to fetch server |
| 44 | + /// configuration and perform initial authentication. It is typically discarded after |
| 45 | + /// initialization. |
| 46 | + /// |
| 47 | + /// \param init_client HTTP client used for initialization requests. |
| 48 | + /// \param properties Client configuration supplied by the catalog. |
| 49 | + /// \return Session for initialization or an error if credentials cannot be acquired. |
| 50 | + virtual Result<std::shared_ptr<AuthSession>> InitSession( |
| 51 | + HttpClient& init_client, |
| 52 | + const std::unordered_map<std::string, std::string>& properties); |
| 53 | + |
| 54 | + /// \brief Create the long-lived catalog session that acts as the parent session. |
| 55 | + /// |
| 56 | + /// This session is used for all catalog-level operations (list namespaces, list tables, |
| 57 | + /// etc.) and serves as the parent session for contextual and table-specific sessions. |
| 58 | + /// It is owned by the catalog and reused throughout the catalog's lifetime. |
| 59 | + /// |
| 60 | + /// \param shared_client HTTP client owned by the catalog and reused for auth calls. |
| 61 | + /// \param properties Catalog properties (client config + server defaults). |
| 62 | + /// \return Session for catalog operations or an error if authentication cannot be set |
| 63 | + /// up. |
| 64 | + virtual Result<std::shared_ptr<AuthSession>> CatalogSession( |
| 65 | + HttpClient& shared_client, |
| 66 | + const std::unordered_map<std::string, std::string>& properties) = 0; |
| 67 | + |
| 68 | + /// \brief Create or reuse a session for a specific context. |
| 69 | + /// |
| 70 | + /// This method is used by SessionCatalog to create sessions for different contexts |
| 71 | + /// (e.g., different users or tenants). |
| 72 | + /// |
| 73 | + /// \param context Context properties (e.g., user credentials, tenant info). |
| 74 | + /// \param parent Catalog session to inherit from or return as-is. |
| 75 | + /// \return A context-specific session, or the parent session if no context-specific |
| 76 | + /// session is needed, or an error if session creation fails. |
| 77 | + virtual Result<std::shared_ptr<AuthSession>> ContextualSession( |
| 78 | + const std::unordered_map<std::string, std::string>& context, |
| 79 | + std::shared_ptr<AuthSession> parent); |
| 80 | + |
| 81 | + /// \brief Create or reuse a session scoped to a single table/view. |
| 82 | + /// |
| 83 | + /// This method is called when loading a table that may have table-specific auth |
| 84 | + /// properties returned by the server. |
| 85 | + /// |
| 86 | + /// \param table Target table identifier. |
| 87 | + /// \param properties Table-specific auth properties returned by the server. |
| 88 | + /// \param parent Catalog or contextual session to inherit from or return as-is. |
| 89 | + /// \return A table-specific session, or the parent session if no table-specific |
| 90 | + /// session is needed, or an error if session creation fails. |
| 91 | + virtual Result<std::shared_ptr<AuthSession>> TableSession( |
| 92 | + const TableIdentifier& table, |
| 93 | + const std::unordered_map<std::string, std::string>& properties, |
| 94 | + std::shared_ptr<AuthSession> parent); |
| 95 | + |
| 96 | + /// \brief Release resources held by the manager. |
| 97 | + /// |
| 98 | + /// \return Status of the close operation. |
| 99 | + virtual Status Close() { return {}; } |
| 100 | +}; |
| 101 | + |
| 102 | +} // namespace iceberg::rest::auth |
0 commit comments