Google Cloud Storage C++ Client  1.42.0
A C++ Client Library for Google Cloud Storage
client_options.h
Go to the documentation of this file.
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 
27 namespace google {
28 namespace cloud {
29 namespace storage {
31 class ClientOptions;
32 namespace internal {
33 std::string RestEndpoint(Options const&);
34 std::string IamRestEndpoint(Options const&);
35 std::string IamRestPath();
36 std::string JsonEndpoint(Options const&);
37 std::string JsonUploadEndpoint(Options const&);
38 std::string XmlEndpoint(Options const&);
39 std::string IamEndpoint(Options const&);
40 
41 Options MakeOptions(ClientOptions);
42 
43 ClientOptions MakeBackwardsCompatibleClientOptions(Options);
44 
45 Options ApplyPolicy(Options opts, RetryPolicy const& p);
46 Options ApplyPolicy(Options opts, BackoffPolicy const& p);
47 Options ApplyPolicy(Options opts, IdempotencyPolicy const& p);
48 
49 inline Options ApplyPolicies(Options opts) { return opts; }
50 
51 template <typename P, typename... Policies>
52 Options 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 
57 Options DefaultOptions(std::shared_ptr<oauth2::Credentials> credentials,
58  Options opts);
59 Options 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  */
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  */
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  */
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  */
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  */
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  */
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  */
274 
275  /**
276  * @deprecated Use google::cloud::Options and UploadBufferSizeOption instead.
277  */
278  std::size_t upload_buffer_size() const {
279  return opts_.get<UploadBufferSizeOption>();
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) {
309  return add_user_agent_prefix(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  */
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 
453 } // namespace storage
454 } // namespace cloud
455 } // namespace google
456 
457 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_CLIENT_OPTIONS_H