iceberg-cpp
Loading...
Searching...
No Matches
auth_properties.h
Go to the documentation of this file.
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 <cstdint>
23#include <optional>
24#include <string>
25#include <unordered_map>
26
27#include "iceberg/catalog/rest/iceberg_rest_export.h"
28#include "iceberg/result.h"
29#include "iceberg/util/config.h"
30
33
34namespace iceberg::rest::auth {
35
37class ICEBERG_REST_EXPORT AuthProperties : public ConfigBase<AuthProperties> {
38 public:
39 template <typename T>
40 using Entry = const ConfigBase<AuthProperties>::Entry<T>;
41
42 // ---- Authentication type constants (not Entry-based) ----
43
44 inline static const std::string kAuthType = "rest.auth.type";
45 inline static const std::string kAuthTypeNone = "none";
46 inline static const std::string kAuthTypeBasic = "basic";
47 inline static const std::string kAuthTypeOAuth2 = "oauth2";
48 inline static const std::string kAuthTypeSigV4 = "sigv4";
49
50 // ---- Basic auth entries ----
51
52 inline static const std::string kBasicUsername = "rest.auth.basic.username";
53 inline static const std::string kBasicPassword = "rest.auth.basic.password";
54
55 // ---- SigV4 entries ----
56
57 inline static const std::string kSigV4Region = "rest.auth.sigv4.region";
58 inline static const std::string kSigV4Service = "rest.auth.sigv4.service";
59 inline static const std::string kSigV4DelegateAuthType =
60 "rest.auth.sigv4.delegate-auth-type";
61
62 // ---- OAuth2 entries ----
63
64 inline static Entry<std::string> kToken{"token", ""};
65 inline static Entry<std::string> kCredential{"credential", ""};
66 inline static Entry<std::string> kScope{"scope", "catalog"};
67 inline static Entry<std::string> kOAuth2ServerUri{"oauth2-server-uri",
68 "v1/oauth/tokens"};
69 inline static Entry<bool> kKeepRefreshed{"token-refresh-enabled", true};
70 inline static Entry<bool> kExchangeEnabled{"token-exchange-enabled", true};
71 inline static Entry<std::string> kAudience{"audience", ""};
72 inline static Entry<std::string> kResource{"resource", ""};
73
75 static Result<AuthProperties> FromProperties(
76 const std::unordered_map<std::string, std::string>& properties);
77
79 std::string token() const { return Get(kToken); }
81 std::string credential() const { return Get(kCredential); }
83 std::string scope() const { return Get(kScope); }
85 std::string oauth2_server_uri() const { return Get(kOAuth2ServerUri); }
87 bool keep_refreshed() const { return Get(kKeepRefreshed); }
89 bool exchange_enabled() const { return Get(kExchangeEnabled); }
90
92 const std::string& client_id() const { return client_id_; }
94 const std::string& client_secret() const { return client_secret_; }
95
97 std::unordered_map<std::string, std::string> optional_oauth_params() const;
98
99 private:
100 std::string client_id_;
101 std::string client_secret_;
102 std::string token_type_;
103 std::optional<int64_t> expires_at_millis_;
104};
105
106} // namespace iceberg::rest::auth
Definition config.h:70
Definition config.h:67
Authentication properties.
Definition auth_properties.h:37
std::string credential() const
Get the raw credential string.
Definition auth_properties.h:81
std::string oauth2_server_uri() const
Get the token endpoint URI.
Definition auth_properties.h:85
bool exchange_enabled() const
Whether token exchange is enabled.
Definition auth_properties.h:89
const std::string & client_secret() const
Parsed client_secret from credential.
Definition auth_properties.h:94
std::string scope() const
Get the OAuth2 scope.
Definition auth_properties.h:83
std::string token() const
Get the bearer token.
Definition auth_properties.h:79
const std::string & client_id() const
Parsed client_id from credential (empty if no colon).
Definition auth_properties.h:92
bool keep_refreshed() const
Whether token refresh is enabled.
Definition auth_properties.h:87