iceberg-cpp
Loading...
Searching...
No Matches
sigv4_auth_manager_internal.h
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
28#include "iceberg/catalog/rest/iceberg_rest_export.h"
29#include "iceberg/result.h"
30
31namespace Aws::Auth {
32class AWSCredentialsProvider;
33} // namespace Aws::Auth
34
35namespace Aws::Client {
36class AWSAuthV4Signer;
37} // namespace Aws::Client
38
39namespace iceberg::rest::auth {
40
46ICEBERG_REST_EXPORT Status InitializeAwsSdk();
47
51ICEBERG_REST_EXPORT Status FinalizeAwsSdk();
52
53ICEBERG_REST_EXPORT bool IsAwsSdkInitialized();
54ICEBERG_REST_EXPORT bool IsAwsSdkFinalized();
55
67class ICEBERG_REST_EXPORT SigV4AuthSession : public AuthSession {
68 public:
70 static constexpr std::string_view kEmptyBodySha256 =
71 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
72
74 static constexpr std::string_view kRelocatedHeaderPrefix = "Original-";
75
80 static Result<std::shared_ptr<SigV4AuthSession>> Make(
81 std::shared_ptr<AuthSession> delegate, std::string signing_region,
82 std::string signing_name,
83 std::shared_ptr<Aws::Auth::AWSCredentialsProvider> credentials_provider);
84
85 ~SigV4AuthSession() override;
86
87 Result<HttpRequest> Authenticate(HttpRequest request) override;
88
89 Status Close() override;
90
91 const std::shared_ptr<AuthSession>& delegate() const { return delegate_; }
92
95 const std::shared_ptr<Aws::Auth::AWSCredentialsProvider>& credentials_provider() const {
96 return credentials_provider_;
97 }
98
99 private:
101 std::shared_ptr<AuthSession> delegate, std::string signing_region,
102 std::string signing_name,
103 std::shared_ptr<Aws::Auth::AWSCredentialsProvider> credentials_provider);
104
105 std::shared_ptr<AuthSession> delegate_;
106 std::string signing_region_;
107 std::string signing_name_;
108 std::shared_ptr<Aws::Auth::AWSCredentialsProvider> credentials_provider_;
109 std::unique_ptr<Aws::Client::AWSAuthV4Signer> signer_;
110};
111
115class ICEBERG_REST_EXPORT SigV4AuthManager : public AuthManager {
116 public:
117 explicit SigV4AuthManager(std::unique_ptr<AuthManager> delegate);
118 ~SigV4AuthManager() override;
119
120 Result<std::shared_ptr<AuthSession>> InitSession(
121 HttpClient& init_client,
122 const std::unordered_map<std::string, std::string>& properties) override;
123
124 Result<std::shared_ptr<AuthSession>> CatalogSession(
125 HttpClient& shared_client,
126 const std::unordered_map<std::string, std::string>& properties) override;
127
128 Result<std::shared_ptr<AuthSession>> ContextualSession(
129 const SessionContext& context, std::shared_ptr<AuthSession> parent) override;
130
131 Result<std::shared_ptr<AuthSession>> TableSession(
132 const TableIdentifier& table,
133 const std::unordered_map<std::string, std::string>& properties,
134 std::shared_ptr<AuthSession> parent) override;
135
136 Status Close() override;
137
138 private:
139 Result<std::shared_ptr<AuthSession>> WrapSession(
140 std::shared_ptr<AuthSession> delegate_session,
141 const std::unordered_map<std::string, std::string>& properties,
142 std::shared_ptr<Aws::Auth::AWSCredentialsProvider> credentials_provider);
143
144 std::unique_ptr<AuthManager> delegate_;
145 std::unordered_map<std::string, std::string> catalog_properties_;
146};
147
148} // namespace iceberg::rest::auth
Authentication manager interface for REST catalog.
Authentication session interface for REST catalog.
HTTP client for making requests to Iceberg REST Catalog API.
Definition http_client.h:71
Produces authentication sessions for catalog and table requests.
Definition auth_manager.h:37
An authentication session that can authenticate outgoing HTTP requests.
Definition auth_session.h:37
An AuthManager that produces SigV4AuthSession instances.
Definition sigv4_auth_manager_internal.h:115
Result< std::shared_ptr< AuthSession > > InitSession(HttpClient &init_client, const std::unordered_map< std::string, std::string > &properties) override
Create a short-lived session used to contact the configuration endpoint.
Result< std::shared_ptr< AuthSession > > CatalogSession(HttpClient &shared_client, const std::unordered_map< std::string, std::string > &properties) override
Create the long-lived catalog session that acts as the parent session.
Status Close() override
Release resources held by the manager.
Result< std::shared_ptr< AuthSession > > TableSession(const TableIdentifier &table, const std::unordered_map< std::string, std::string > &properties, std::shared_ptr< AuthSession > parent) override
Create or reuse a session scoped to a single table/view.
Result< std::shared_ptr< AuthSession > > ContextualSession(const SessionContext &context, std::shared_ptr< AuthSession > parent) override
Create or reuse a session for a specific context.
An AuthSession that signs requests with AWS SigV4.
Definition sigv4_auth_manager_internal.h:67
Result< HttpRequest > Authenticate(HttpRequest request) override
Authenticate an outgoing HTTP request.
const std::shared_ptr< Aws::Auth::AWSCredentialsProvider > & credentials_provider() const
Definition sigv4_auth_manager_internal.h:95
Status Close() override
Close the session and release any resources.
static Result< std::shared_ptr< SigV4AuthSession > > Make(std::shared_ptr< AuthSession > delegate, std::string signing_region, std::string signing_name, std::shared_ptr< Aws::Auth::AWSCredentialsProvider > credentials_provider)
Creates a session registered with the AWS SDK lifecycle.
Session state used to bind catalog operations to a caller context.
Definition session_context.h:39
Identifies a table in iceberg catalog.
Definition table_identifier.h:46
An outgoing HTTP request. Mirrors Java's HttpRequest so signing implementations like SigV4 see method...
Definition http_request.h:86