Google Cloud Storage C++ Client 2.13.0
A C++ Client Library for Google Cloud Storage
Loading...
Searching...
No Matches
client_options.h
1// Copyright 2018 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_CLIENT_OPTIONS_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_CLIENT_OPTIONS_H
17
18#include "google/cloud/storage/oauth2/credentials.h"
19#include "google/cloud/storage/options.h"
20#include "google/cloud/storage/version.h"
21#include "google/cloud/common_options.h"
22#include "google/cloud/options.h"
23#include <chrono>
24#include <memory>
25#include <string>
26
27namespace google {
28namespace cloud {
29namespace storage {
30GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
31class ClientOptions;
32namespace internal {
33std::string RestEndpoint(Options const&);
34std::string IamRestEndpoint(Options const&);
35std::string IamRestPath();
36std::string JsonEndpoint(Options const&);
37std::string JsonUploadEndpoint(Options const&);
38std::string XmlEndpoint(Options const&);
39std::string IamEndpoint(Options const&);
40
41Options MakeOptions(ClientOptions);
42
43ClientOptions MakeBackwardsCompatibleClientOptions(Options);
44
45Options ApplyPolicy(Options opts, RetryPolicy const& p);
46Options ApplyPolicy(Options opts, BackoffPolicy const& p);
47Options ApplyPolicy(Options opts, IdempotencyPolicy const& p);
48
49inline Options ApplyPolicies(Options opts) { return opts; }
50
51template <typename P, typename... Policies>
52Options ApplyPolicies(Options opts, P&& head, Policies&&... tail) {
53 opts = ApplyPolicy(std::move(opts), std::forward<P>(head));
54 return ApplyPolicies(std::move(opts), std::forward<Policies>(tail)...);
55}
56
57Options DefaultOptions(std::shared_ptr<oauth2::Credentials> credentials,
58 Options opts);
59Options DefaultOptionsWithCredentials(Options opts);
60
61} // namespace internal
62
63/**
64 * Describes the configuration for low-level connection features.
65 *
66 * Some applications may want to use a different SSL root of trust for their
67 * connections, for example, containerized applications might store the
68 * certificate authority certificates in a hard-coded location.
69 *
70 * This is a separate class, as it is used to configure both the normal
71 * connections to GCS and the connections used to obtain OAuth2 access
72 * tokens.
73 */
74class ChannelOptions {
75 public:
76 /// @deprecated Use google::cloud::Options and CAPathOption instead.
77 std::string ssl_root_path() const { return ssl_root_path_; }
78
79 /// @deprecated Use google::cloud::Options and CAPathOption instead.
80 ChannelOptions& set_ssl_root_path(std::string ssl_root_path) {
81 ssl_root_path_ = std::move(ssl_root_path);
82 return *this;
83 }
84
85 private:
86 std::string ssl_root_path_;
87};
88
89/**
90 * Describes the configuration for a `storage::Client` object.
91 *
92 * By default, several environment variables are read to configure the client:
93 *
94 * - `CLOUD_STORAGE_EMULATOR_ENDPOINT`: if set, use this http endpoint to
95 * make all http requests instead of the production GCS service. Also,
96 * if set, the `CreateDefaultClientOptions()` function will use an
97 * `AnonymousCredentials` object instead of loading Application Default
98 * %Credentials.
99 * - `CLOUD_STORAGE_ENABLE_CLOG`: if set, enable std::clog as a backend for
100 * `google::cloud::LogSink`.
101 * - `CLOUD_STORAGE_ENABLE_TRACING`: if set, this is the list of components that
102 * will have logging enabled, the component this is:
103 * - `http`: trace all http request / responses.
104 *
105 * @deprecated Please use google::cloud::Options instead.
106 */
107class ClientOptions {
108 public:
109 /**
110 * Constructor with channel options.
111 *
112 * @deprecated use google::cloud::Options instead.
113 *
114 * @param credentials how to authenticate to the client. Using a `nullptr` for
115 * @p credentials results in undefined behavior.
116 */
117 explicit ClientOptions(std::shared_ptr<oauth2::Credentials> credentials)
118 : ClientOptions(std::move(credentials), {}) {}
119
120 /**
121 * Constructor with channel options.
122 *
123 * @deprecated use google::cloud::Options instead.
124 *
125 * @param credentials how to authenticate to the client. Using a `nullptr` for
126 * @p credentials results in undefined behavior.
127 * @param channel_options the configuration for SSL certificate validation.
128 */
129 ClientOptions(std::shared_ptr<oauth2::Credentials> credentials,
130 ChannelOptions channel_options);
131
132 /**
133 * Creates a `ClientOptions` with Google Application Default %Credentials.
134 *
135 * If Application Default %Credentials could not be loaded, this returns a
136 * `Status` with failure details. If the `CLOUD_STORAGE_EMULATOR_ENDPOINT`
137 * environment variable is set, this function instead uses an
138 * `AnonymousCredentials` to configure the client.
139 *
140 * @deprecated Please use google::cloud::Options instead.
141 */
142 static StatusOr<ClientOptions> CreateDefaultClientOptions();
143 /// @deprecated Please use google::cloud::Options instead.
145 ChannelOptions const& channel_options);
146
147 /**
148 * @deprecated Use google::cloud::Options and Oauth2CredentialsOption instead.
149 */
150 std::shared_ptr<oauth2::Credentials> credentials() const {
152 }
153
154 /**
155 * @deprecated Use google::cloud::Options and Oauth2CredentialsOption instead.
156 */
157 ClientOptions& set_credentials(std::shared_ptr<oauth2::Credentials> c) {
158 opts_.set<Oauth2CredentialsOption>(std::move(c));
159 return *this;
160 }
161
162 /**
163 * @deprecated Use google::cloud::Options and RestEndpointOption instead.
164 */
165 std::string const& endpoint() const {
166 return opts_.get<RestEndpointOption>();
167 }
168
169 /**
170 * @deprecated Use google::cloud::Options and RestEndpointOption instead.
171 */
172 ClientOptions& set_endpoint(std::string endpoint) {
173 opts_.set<RestEndpointOption>(std::move(endpoint));
174 return *this;
175 }
176
177 /**
178 * @deprecated Use google::cloud::Options and IamEndpointOption instead.
179 */
180 std::string const& iam_endpoint() const {
181 return opts_.get<IamEndpointOption>();
182 }
183
184 /**
185 * @deprecated Use google::cloud::Options and IamEndpointOption instead.
186 */
187 ClientOptions& set_iam_endpoint(std::string endpoint) {
188 opts_.set<IamEndpointOption>(std::move(endpoint));
189 return *this;
190 }
191
192 /**
193 * @deprecated This was intended for development and not a public API.
194 */
195 std::string const& version() const {
196 return opts_.get<internal::TargetApiVersionOption>();
197 }
198
199 /**
200 * @deprecated This was intended for development and not a public API.
201 */
202 ClientOptions& set_version(std::string version) {
203 opts_.set<internal::TargetApiVersionOption>(std::move(version));
204 return *this;
205 }
206
207 /**
208 * @deprecated Use google::cloud::Options and
209 * google::cloud::TracingComponentsOption instead.
210 */
211 bool enable_http_tracing() const;
212
213 /**
214 * @deprecated Use google::cloud::Options and
215 * google::cloud::TracingComponentsOption instead.
216 */
218
219 /**
220 * @deprecated Use google::cloud::Options and
221 * google::cloud::TracingComponentsOption instead.
222 */
223 bool enable_raw_client_tracing() const;
224
225 /**
226 * @deprecated Use google::cloud::Options and
227 * google::cloud::TracingComponentsOption instead.
228 */
230
231 /**
232 * @deprecated Use google::cloud::Options and ProjectIdOption instead.
233 */
234 std::string const& project_id() const { return opts_.get<ProjectIdOption>(); }
235
236 /**
237 * @deprecated Use google::cloud::Options and ProjectIdOption instead.
238 */
239 ClientOptions& set_project_id(std::string v) {
240 opts_.set<ProjectIdOption>(std::move(v));
241 return *this;
242 }
243
244 /**
245 * @deprecated Use google::cloud::Options and ConnectionPoolSizeOption
246 * instead.
247 */
248 std::size_t connection_pool_size() const {
250 }
251
252 /**
253 * @deprecated Use google::cloud::Options and ConnectionPoolSizeOption
254 * instead.
255 */
256 ClientOptions& set_connection_pool_size(std::size_t size) {
258 return *this;
259 }
260
261 /**
262 * @deprecated Use google::cloud::Options and DownloadBufferSizeOption
263 * instead.
264 */
265 std::size_t download_buffer_size() const {
267 }
268
269 /**
270 * @deprecated Use google::cloud::Options and DownloadBufferSizeOption
271 * instead.
272 */
273 ClientOptions& SetDownloadBufferSize(std::size_t size);
274
275 /**
276 * @deprecated Use google::cloud::Options and UploadBufferSizeOption instead.
277 */
278 std::size_t upload_buffer_size() const {
280 }
281
282 /**
283 * @deprecated Use google::cloud::Options and UploadBufferSizeOption instead.
284 */
285 ClientOptions& SetUploadBufferSize(std::size_t size);
286
287 /**
288 * @deprecated Use google::cloud::Options and
289 * google::cloud::UserAgentProductsOption instead.
290 */
291 std::string const& user_agent_prefix() const { return user_agent_prefix_; }
292
293 /**
294 * @deprecated Use google::cloud::Options and
295 * google::cloud::UserAgentProductsOption instead.
296 */
297 ClientOptions& add_user_agent_prefix(std::string prefix) {
298 opts_.lookup<UserAgentProductsOption>().push_back(prefix);
299 if (!user_agent_prefix_.empty()) {
300 prefix += ' ';
301 prefix += user_agent_prefix_;
302 }
303 user_agent_prefix_ = std::move(prefix);
304 return *this;
305 }
306
307 /// @deprecated use `add_user_agent_prefix()` instead.
308 ClientOptions& add_user_agent_prefx(std::string const& v) {
310 }
311
312 /**
313 * @deprecated Use google::cloud::Options and MaximumSimpleUploadSizeOption
314 * instead.
315 */
316 std::size_t maximum_simple_upload_size() const {
318 }
319
320 /**
321 * @deprecated Use google::cloud::Options and MaximumSimpleUploadSizeOption
322 * instead.
323 */
326 return *this;
327 }
328
329 /**
330 * If true and using OpenSSL 1.0.2 the library configures the OpenSSL
331 * callbacks for locking.
332 *
333 * @deprecated Use google::cloud::options and EnableCurlSslLockingOption
334 * instead.
335 */
336 bool enable_ssl_locking_callbacks() const {
338 }
339
340 /**
341 * If true and using OpenSSL 1.0.2 the library configures the OpenSSL
342 * callbacks for locking.
343 *
344 * @deprecated Use google::cloud::options and EnableCurlSslLockingOption
345 * instead.
346 */
349 return *this;
350 }
351
352 /**
353 * @deprecated Use google::cloud::Options and EnableCurlSigpipeOption
354 * instead.
355 */
356 bool enable_sigpipe_handler() const {
358 }
359
360 /**
361 * @deprecated Use google::cloud::Options and EnableCurlSigpipeOption
362 * instead.
363 */
366 return *this;
367 }
368
369 /**
370 * @deprecated Use google::cloud::Options and MaximumCurlSocketRecvSizeOption
371 * instead.
372 */
373 std::size_t maximum_socket_recv_size() const {
375 }
376
377 /**
378 * @deprecated Use google::cloud::Options and MaximumCurlSocketRecvSizeOption
379 * instead.
380 */
383 return *this;
384 }
385
386 /**
387 * @deprecated Use google::cloud::Options and MaximumCurlSocketSendSizeOption
388 * instead.
389 */
390 std::size_t maximum_socket_send_size() const {
392 }
393
394 /**
395 * @deprecated Use google::cloud::Options and MaximumCurlSocketSendSizeOption
396 * instead.
397 */
400 return *this;
401 }
402
403 /// @deprecated Use google::cloud::Options and CAPathOption instead.
404 ChannelOptions& channel_options() { return channel_options_; }
405
406 /// @deprecated Use google::cloud::Options and CAPathOption instead.
407 ChannelOptions const& channel_options() const { return channel_options_; }
408
409 ///@{
410 /**
411 * Control the maximum amount of time allowed for "stalls" during a download.
412 *
413 * A download that receives no data is considered "stalled". If the download
414 * remains stalled for more than the time set in this option then the download
415 * is aborted.
416 *
417 * The default value is 2 minutes. Can be disabled by setting the value to 0.
418 *
419 * @deprecated Use google::cloud::Options and DownloadStallTimeoutOption
420 * instead.
421 */
422 std::chrono::seconds download_stall_timeout() const {
424 }
425
426 /**
427 * @deprecated Use google::cloud::Options and DownloadStallTimeoutOption
428 * instead.
429 */
430 ClientOptions& set_download_stall_timeout(std::chrono::seconds v) {
431 opts_.set<TransferStallTimeoutOption>(std::move(v));
432 return *this;
433 }
434 ///@}
435
436 private:
437 friend Options internal::MakeOptions(ClientOptions);
438 friend ClientOptions internal::MakeBackwardsCompatibleClientOptions(Options);
439
440 explicit ClientOptions(Options o);
441
442 Options opts_;
443
444 // Used for backwards compatibility. The value here is merged with the values
445 // in `opts_` by internal::MakeOptions(ClientOptions const&);
446 ChannelOptions channel_options_;
447
448 // Only used for backwards compatibility, the value in `opts_.
449 std::string user_agent_prefix_;
450};
451
452GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
453} // namespace storage
454} // namespace cloud
455} // namespace google
456
457#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_CLIENT_OPTIONS_H
ValueTypeT< T > const & get() const
ValueTypeT< T > & lookup(ValueTypeT< T > value={})
Options & set(ValueTypeT< T > v)
Describes the configuration for low-level connection features.
Definition: client_options.h:74
ChannelOptions & set_ssl_root_path(std::string ssl_root_path)
Definition: client_options.h:80
std::string ssl_root_path() const
Definition: client_options.h:77
Describes the configuration for a storage::Client object.
Definition: client_options.h:107
ClientOptions & set_iam_endpoint(std::string endpoint)
Definition: client_options.h:187
std::size_t maximum_socket_send_size() const
Definition: client_options.h:390
ClientOptions & set_enable_raw_client_tracing(bool enable)
ClientOptions(std::shared_ptr< oauth2::Credentials > credentials, ChannelOptions channel_options)
Constructor with channel options.
std::size_t download_buffer_size() const
Definition: client_options.h:265
ClientOptions & add_user_agent_prefix(std::string prefix)
Definition: client_options.h:297
ClientOptions & set_maximum_simple_upload_size(std::size_t v)
Definition: client_options.h:324
static StatusOr< ClientOptions > CreateDefaultClientOptions(ChannelOptions const &channel_options)
std::string const & user_agent_prefix() const
Definition: client_options.h:291
std::size_t maximum_simple_upload_size() const
Definition: client_options.h:316
std::string const & iam_endpoint() const
Definition: client_options.h:180
ClientOptions & set_enable_http_tracing(bool enable)
ClientOptions & set_maximum_socket_send_size(std::size_t v)
Definition: client_options.h:398
ClientOptions & set_enable_sigpipe_handler(bool v)
Definition: client_options.h:364
std::size_t upload_buffer_size() const
Definition: client_options.h:278
std::string const & version() const
Definition: client_options.h:195
std::shared_ptr< oauth2::Credentials > credentials() const
Definition: client_options.h:150
std::chrono::seconds download_stall_timeout() const
Control the maximum amount of time allowed for "stalls" during a download.
Definition: client_options.h:422
ClientOptions & add_user_agent_prefx(std::string const &v)
Definition: client_options.h:308
ChannelOptions & channel_options()
Definition: client_options.h:404
std::size_t maximum_socket_recv_size() const
Definition: client_options.h:373
ClientOptions & set_download_stall_timeout(std::chrono::seconds v)
Definition: client_options.h:430
ClientOptions(std::shared_ptr< oauth2::Credentials > credentials)
Constructor with channel options.
Definition: client_options.h:117
ChannelOptions const & channel_options() const
Definition: client_options.h:407
static StatusOr< ClientOptions > CreateDefaultClientOptions()
Creates a ClientOptions with Google Application Default Credentials.
ClientOptions & set_connection_pool_size(std::size_t size)
Definition: client_options.h:256
std::size_t connection_pool_size() const
Definition: client_options.h:248
ClientOptions & set_endpoint(std::string endpoint)
Definition: client_options.h:172
std::string const & project_id() const
Definition: client_options.h:234
ClientOptions & set_credentials(std::shared_ptr< oauth2::Credentials > c)
Definition: client_options.h:157
ClientOptions & set_maximum_socket_recv_size(std::size_t v)
Definition: client_options.h:381
std::string const & endpoint() const
Definition: client_options.h:165
ClientOptions & SetDownloadBufferSize(std::size_t size)
ClientOptions & set_project_id(std::string v)
Definition: client_options.h:239
bool enable_ssl_locking_callbacks() const
If true and using OpenSSL 1.0.2 the library configures the OpenSSL callbacks for locking.
Definition: client_options.h:336
ClientOptions & set_enable_ssl_locking_callbacks(bool v)
If true and using OpenSSL 1.0.2 the library configures the OpenSSL callbacks for locking.
Definition: client_options.h:347
bool enable_sigpipe_handler() const
Definition: client_options.h:356
ClientOptions & SetUploadBufferSize(std::size_t size)
ClientOptions & set_version(std::string version)
Definition: client_options.h:202
Define the interface for the idempotency policy.
Definition: idempotency_policy.h:58
Interface for OAuth 2.0 credentials used to access Google Cloud services.
Definition: credentials.h:47
Authentication components for Google Cloud Storage.
Definition: anonymous_credentials.h:26
Contains all the Google Cloud Storage C++ client APIs.
Definition: auto_finalize.h:24
Set the maximum connection pool size.
Definition: options.h:144
Control the formatted I/O download buffer.
Definition: options.h:161
Disables automatic OpenSSL sigpipe handler.
Definition: options.h:221
Disables automatic OpenSSL locking.
Definition: options.h:210
Configure the IAM endpoint for the GCS client library.
Definition: options.h:93
Control the maximum socket receive buffer.
Definition: options.h:232
Control the maximum socket send buffer.
Definition: options.h:242
Defines the threshold to switch from simple to resumable uploads for files.
Definition: options.h:194
Configure oauth2::Credentials for the GCS client library.
Definition: options.h:105
Set the Google Cloud Platform project id.
Definition: options.h:114
Configure the REST endpoint for the GCS client library.
Definition: options.h:84
Sets the transfer stall timeout.
Definition: options.h:263
Control the formatted I/O upload buffer.
Definition: options.h:179