Couchbase C++ SDK 1.3.1 (rev. fb3f860)
Loading...
Searching...
No Matches
cluster_options.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright 2020-Present Couchbase, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19
26#include <couchbase/error.hxx>
36
37#include <functional>
38#include <stdexcept>
39#include <string>
40#include <system_error>
41#include <vector>
42
43namespace couchbase
44{
45#ifndef COUCHBASE_CXX_CLIENT_DOXYGEN
46namespace crypto
47{
48class manager;
49} // namespace crypto
50#endif
52{
53public:
62 cluster_options(std::string username, std::string password)
63 : username_{ std::move(username) }
64 , password_{ std::move(password) }
65 {
66 }
67
76 : username_{ std::move(authenticator.username_) }
77 , password_{ std::move(authenticator.password_) }
78 {
79 if (authenticator.ldap_compatible_) {
80 sasl_mechanisms_ = { { "PLAIN" } };
81 }
82 }
83
92 : certificate_path_{ std::move(authenticator.certificate_path_) }
93 , key_path_{ std::move(authenticator.key_path_) }
94 {
95 }
96
104 explicit cluster_options(jwt_authenticator authenticator)
105 : jwt_token_{ std::move(authenticator.token_) }
106 {
107 }
108
122 void apply_profile(const std::string& profile_name)
123 {
125 }
126
135 [[nodiscard]] auto compression() -> compression_options&
136 {
137 return compression_;
138 }
139
148 [[nodiscard]] auto timeouts() -> timeout_options&
149 {
150 return timeouts_;
151 }
152
161 [[nodiscard]] auto dns() -> dns_options&
162 {
163 return dns_;
164 }
165
174 [[nodiscard]] auto security() -> security_options&
175 {
176 return security_;
177 }
178
187 [[nodiscard]] auto network() -> network_options&
188 {
189 return network_;
190 }
191
200 [[nodiscard]] auto metrics() -> metrics_options&
201 {
202 return metrics_;
203 }
204
213 [[nodiscard]] auto tracing() -> tracing_options&
214 {
215 return tracing_;
216 }
217
226 [[nodiscard]] auto behavior() -> behavior_options&
227 {
228 return behavior_;
229 }
230
240 {
241 return transactions_;
242 }
243
253 {
254 return application_telemetry_;
255 }
256
265 auto default_retry_strategy(std::shared_ptr<retry_strategy> strategy) -> cluster_options&
266 {
267 if (strategy == nullptr) {
268 throw std::invalid_argument("retry strategy cannot be null");
269 }
270 default_retry_strategy_ = std::move(strategy);
271 return *this;
272 }
273
274 auto crypto_manager(std::shared_ptr<crypto::manager> crypto_manager) -> cluster_options&
275 {
276 if (crypto_manager == nullptr) {
277 throw std::invalid_argument("crypto manager cannot be null");
278 }
279 crypto_manager_ = std::move(crypto_manager);
280 return *this;
281 }
282
303
304 [[nodiscard]] auto build() const -> built
305 {
306 return {
307 username_,
308 password_,
309 certificate_path_,
310 key_path_,
311 jwt_token_,
312 sasl_mechanisms_,
313 compression_.build(),
314 timeouts_.build(),
315 dns_.build(),
316 security_.build(),
317 network_.build(),
318 metrics_.build(),
319 tracing_.build(),
320 behavior_.build(),
321 transactions_.build(),
322 default_retry_strategy_,
323 application_telemetry_.build(),
324 crypto_manager_,
325 };
326 }
327
328private:
329 std::string username_{};
330 std::string password_{};
331 std::string certificate_path_{};
332 std::string key_path_{};
333 std::string jwt_token_{};
334 std::optional<std::vector<std::string>> sasl_mechanisms_{};
335
336 compression_options compression_{};
337 timeout_options timeouts_{};
338 dns_options dns_{};
339 security_options security_{};
340 network_options network_{};
341 metrics_options metrics_{};
342 tracing_options tracing_{};
343 behavior_options behavior_{};
344 transactions::transactions_config transactions_{};
345 std::shared_ptr<retry_strategy> default_retry_strategy_{ nullptr };
346 application_telemetry_options application_telemetry_{};
347 std::shared_ptr<crypto::manager> crypto_manager_{};
348};
349
350#ifndef COUCHBASE_CXX_CLIENT_DOXYGEN
351class cluster;
352#endif
353
360using cluster_connect_handler = std::function<void(error, cluster)>;
361} // namespace couchbase
Definition application_telemetry_options.hxx:27
Definition behavior_options.hxx:25
Definition certificate_authenticator.hxx:25
cluster_options(jwt_authenticator authenticator)
Definition cluster_options.hxx:104
auto behavior() -> behavior_options &
Returns misc options that affects cluster behavior.
Definition cluster_options.hxx:226
cluster_options(password_authenticator authenticator)
Definition cluster_options.hxx:75
cluster_options(certificate_authenticator authenticator)
Definition cluster_options.hxx:91
cluster_options(std::string username, std::string password)
Definition cluster_options.hxx:62
auto application_telemetry() -> application_telemetry_options &
Returns the Application Telemetry options.
Definition cluster_options.hxx:252
auto tracing() -> tracing_options &
Returns tracing options.
Definition cluster_options.hxx:213
auto build() const -> built
Definition cluster_options.hxx:304
auto default_retry_strategy(std::shared_ptr< retry_strategy > strategy) -> cluster_options &
Override default retry strategy.
Definition cluster_options.hxx:265
auto security() -> security_options &
Returns security options (including TLS).
Definition cluster_options.hxx:174
void apply_profile(const std::string &profile_name)
Apply settings profile by name.
Definition cluster_options.hxx:122
auto network() -> network_options &
Returns network options.
Definition cluster_options.hxx:187
auto dns() -> dns_options &
Returns options for DNS-SRV bootstrap.
Definition cluster_options.hxx:161
auto compression() -> compression_options &
Returns compression options.
Definition cluster_options.hxx:135
auto crypto_manager(std::shared_ptr< crypto::manager > crypto_manager) -> cluster_options &
Definition cluster_options.hxx:274
auto timeouts() -> timeout_options &
Returns various timeout options.
Definition cluster_options.hxx:148
auto transactions() -> transactions::transactions_config &
Returns the transactions options which effect the transactions behavior.
Definition cluster_options.hxx:239
auto metrics() -> metrics_options &
Returns metrics and observability options.
Definition cluster_options.hxx:200
The cluster is the main entry point when connecting to a Couchbase cluster.
Definition cluster.hxx:60
Definition compression_options.hxx:25
static void apply_profile(const std::string &name, couchbase::cluster_options &options)
Apply a profile to an instance of cluster_options.
Definition dns_options.hxx:28
Definition error.hxx:30
A JWT authenticator which uses a JSON Web Token (JWT) to authenticate with the cluster.
Definition jwt_authenticator.hxx:31
Definition metrics_options.hxx:29
Definition network_options.hxx:30
Definition password_authenticator.hxx:25
Definition security_options.hxx:28
Definition timeout_options.hxx:26
Definition tracing_options.hxx:29
Configuration parameters for transactions.
Definition transactions_config.hxx:43
Definition internal.hxx:27
Represents a single item from the result of scan().
Definition allow_querying_search_index_options.hxx:28
std::function< void(error, cluster)> cluster_connect_handler
The signature for the handler of the connect().
Definition cluster_options.hxx:360
Definition application_telemetry_options.hxx:102
Definition behavior_options.hxx:76
Definition cluster_options.hxx:283
std::string password
Definition cluster_options.hxx:285
metrics_options::built metrics
Definition cluster_options.hxx:295
network_options::built network
Definition cluster_options.hxx:294
compression_options::built compression
Definition cluster_options.hxx:290
std::shared_ptr< retry_strategy > default_retry_strategy
Definition cluster_options.hxx:299
security_options::built security
Definition cluster_options.hxx:293
std::string username
Definition cluster_options.hxx:284
timeout_options::built timeouts
Definition cluster_options.hxx:291
transactions::transactions_config::built transactions
Definition cluster_options.hxx:298
std::optional< std::vector< std::string > > allowed_sasl_mechanisms
Definition cluster_options.hxx:289
std::string certificate_path
Definition cluster_options.hxx:286
std::string key_path
Definition cluster_options.hxx:287
tracing_options::built tracing
Definition cluster_options.hxx:296
std::string jwt_token
Definition cluster_options.hxx:288
std::shared_ptr< crypto::manager > crypto_manager
Definition cluster_options.hxx:301
behavior_options::built behavior
Definition cluster_options.hxx:297
dns_options::built dns
Definition cluster_options.hxx:292
application_telemetry_options::built application_telemetry
Definition cluster_options.hxx:300
Definition compression_options.hxx:45
Definition dns_options.hxx:45
Definition metrics_options.hxx:51
Definition network_options.hxx:133
Definition security_options.hxx:54
Definition timeout_options.hxx:119
Definition tracing_options.hxx:127