diff --git a/ci/abi-dumps/google_cloud_cpp_storage.expected.abi.dump.gz b/ci/abi-dumps/google_cloud_cpp_storage.expected.abi.dump.gz index 1a49471169f2c..fb09695e3244b 100644 Binary files a/ci/abi-dumps/google_cloud_cpp_storage.expected.abi.dump.gz and b/ci/abi-dumps/google_cloud_cpp_storage.expected.abi.dump.gz differ diff --git a/doc/v3-migration-guide.md b/doc/v3-migration-guide.md index 9421abcddc5fc..cea28a283ae89 100644 --- a/doc/v3-migration-guide.md +++ b/doc/v3-migration-guide.md @@ -126,3 +126,149 @@ auto limit = google::cloud::bigtable::RowReader::NO_ROWS_LIMIT; ### Spanner ### Storage + +
+ClientOptions is removed + +The `ClientOptions` class is no longer available. You should now use +`google::cloud::Options` to configure the `Client`. + +**Before:** + +```cpp +#include "google/cloud/storage/client.h" + +void CreateClient() { + auto credentials = google::cloud::storage::oauth2::GoogleDefaultCredentials().value(); + auto options = google::cloud::storage::ClientOptions(credentials); + options.set_project_id("my-project"); + options.set_upload_buffer_size(1024 * 1024); + + google::cloud::storage::Client client(options); +} +``` + +**After:** + +```cpp +#include "google/cloud/storage/client.h" +#include "google/cloud/storage/options.h" // For option structs + +void CreateClient() { + auto credentials = google::cloud::MakeGoogleDefaultCredentials(); + auto client = google::cloud::storage::Client( + google::cloud::Options{} + .set(credentials) + .set("my-project") + .set(1024 * 1024)); +} +``` + +Use the following table to map `ClientOptions` setters to +`google::cloud::Options`: + +| `ClientOptions` Method | Replacement Option (`.set(value)`) | +| :------------------------------------ | :------------------------------------------------------ | +| `set_credentials(c)` | `google::cloud::storage::Oauth2CredentialsOption` | +| `set_project_id(p)` | `google::cloud::storage::ProjectIdOption` | +| `set_endpoint(url)` | `google::cloud::storage::RestEndpointOption` | +| `set_iam_endpoint(url)` | `google::cloud::storage::IamEndpointOption` | +| `SetDownloadBufferSize` | `google::cloud::storage::DownloadBufferSizeOption` | +| `SetUploadBufferSizee` | `google::cloud::storage::UploadBufferSizeOption` | +| `set_maximum_simple_upload_size(s)` | `google::cloud::storage::MaximumSimpleUploadSizeOption` | +| `set_enable_http_tracing(true)` | `google::cloud::LoggingComponentsOption` | +| `set_enable_raw_client_tracing(true)` | `google::cloud::LoggingComponentsOption` | + +**Example for Tracing:** + +```cpp +// Before +options.set_enable_http_tracing(true); + +// After +auto opts = Options{}.lookup().insert("raw-client"); +``` + +
+ +
+ChannelOptions is removed + +The `ChannelOptions` class is no longer available. You should now use +`google::cloud::Options` to configure the transport channel. + +**Before:** + +```cpp +#include "google/cloud/storage/grpc_plugin.h" + +void CreateClient() { + auto options = google::cloud::storage::ChannelOptions() + .set_ssl_root_path("path/to/roots.pem"); + + auto client = google::cloud::storage::MakeGrpcClient( + google::cloud::storage::ClientOptions(), options); +} +``` + +**After:** + +```cpp +#include "google/cloud/storage/grpc_plugin.h" +#include "google/cloud/grpc_options.h" +#include "google/cloud/common_options.h" + +void CreateClient() { + auto client = google::cloud::storage::MakeGrpcClient( + google::cloud::Options{}.set( + "path/to/roots.pem")); +} +``` + +
+ +
+ChannelOptions Mapping + +Use the following table to map `ChannelOptions` setters to +`google::cloud::Options`: + +| `ChannelOptions` Method | Replacement Option (`.set(value)`) | +| :---------------------- | :------------------------------------- | +| `set_ssl_root_path(p)` | `google::cloud::CARootsFilePathOption` | + +
+ +
+Client Constructor + +The constructor `Client(ClientOptions)` is removed. The default constructor +`Client()` generally uses default options and default credentials. To customize, +use `Client(Options)`. + +**Before:** + +```cpp +#include "google/cloud/storage/client.h" + +void CreateClient() { + auto credentials = google::cloud::storage::oauth2::GoogleDefaultCredentials().value(); + auto options = google::cloud::storage::ClientOptions(credentials); + auto client = google::cloud::storage::Client(options); +} +``` + +**After:** + +```cpp +#include "google/cloud/storage/client.h" +#include "google/cloud/storage/options.h" + +void CreateClient() { + auto credentials = google::cloud::MakeGoogleDefaultCredentials(); + auto client = google::cloud::storage::Client( + google::cloud::Options{}.set(credentials)); +} +``` + +
diff --git a/google/cloud/storage/client.cc b/google/cloud/storage/client.cc index 8d67b1fb0e6c0..5cb0af53a4ca4 100644 --- a/google/cloud/storage/client.cc +++ b/google/cloud/storage/client.cc @@ -60,8 +60,6 @@ Client::Client(InternalOnly, Options const& opts) : Client(InternalOnlyNoDecorations{}, storage_internal::MakeStorageConnection(opts)) {} -StatusOr Client::CreateDefaultClient() { return Client(Options{}); } - ObjectReadStream Client::ReadObjectImpl( internal::ReadObjectRangeRequest const& request) { auto source = connection_->ReadObject(request); @@ -235,12 +233,12 @@ std::string Client::SigningEmail(SigningAccount const& signing_account) const { if (signing_account.has_value()) { return signing_account.value(); } - return connection_->client_options().credentials()->AccountEmail(); + return connection_->options().get()->AccountEmail(); } StatusOr Client::SignBlobImpl( SigningAccount const& signing_account, std::string const& string_to_sign) { - auto credentials = connection_->client_options().credentials(); + auto credentials = connection_->options().get(); // First try to sign locally. auto signed_blob = credentials->SignBlob(signing_account, string_to_sign); diff --git a/google/cloud/storage/client.h b/google/cloud/storage/client.h index 1b279dfeaa7f1..6c9658c850189 100644 --- a/google/cloud/storage/client.h +++ b/google/cloud/storage/client.h @@ -15,6 +15,7 @@ #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_CLIENT_H #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_CLIENT_H +#include "google/cloud/storage/client_options.h" #include "google/cloud/storage/hmac_key_metadata.h" #include "google/cloud/storage/internal/policy_document_request.h" #include "google/cloud/storage/internal/request_project_id.h" @@ -3421,79 +3422,6 @@ class Client { } ///@} - /** - * Creates the default client type given the options. - * - * @param options the client options, these are used to control credentials, - * buffer sizes, etc. - * @param policies the client policies, these control the behavior of the - * client, for example, how to backoff when an operation needs to be - * retried, or what operations cannot be retried because they are not - * idempotent. - * - * @deprecated use the constructor from `google::cloud::Options` instead. - */ - template - explicit Client(ClientOptions options, Policies&&... policies) - : Client(InternalOnly{}, internal::ApplyPolicies( - internal::MakeOptions(std::move(options)), - std::forward(policies)...)) {} - - /** - * Creates the default client type given the credentials and policies. - * - * @param credentials a set of credentials to initialize the `ClientOptions`. - * @param policies the client policies, these control the behavior of the - * client, for example, how to backoff when an operation needs to be - * retried, or what operations cannot be retried because they are not - * idempotent. - * - * @deprecated use the constructor from `google::cloud::Options` instead. - */ - template - explicit Client(std::shared_ptr credentials, - Policies&&... policies) - : Client(InternalOnly{}, - internal::ApplyPolicies( - internal::DefaultOptions(std::move(credentials), {}), - std::forward(policies)...)) {} - - /** - * Create a Client using ClientOptions::CreateDefaultClientOptions(). - * - * @deprecated use the constructor from `google::cloud::Options` instead. - */ - static StatusOr CreateDefaultClient(); - - /// Builds a client and maybe override the retry, idempotency, and/or backoff - /// policies. - /// @deprecated This was intended only for test code, applications should not - /// use it. - template -#if !defined(_MSC_VER) || _MSC_VER >= 1920 - GOOGLE_CLOUD_CPP_DEPRECATED( - "applications should not need this." - " Please use the constructors from ClientOptions instead." - " For mocking, please use testing::ClientFromMock() instead." - " Please file a bug at https://github.com/googleapis/google-cloud-cpp" - " if you have a use-case not covered by these.") -#endif // _MSC_VER - // We cannot `std::move(connection)` because it is used twice in the delegated - // constructor parameters. And we cannot just use `StorageConnection const&` - // because we do hold on to the `std::shared_ptr<>`. - explicit Client( - std::shared_ptr const& connection, - Policies&&... policies) - : Client(InternalOnly{}, - internal::ApplyPolicies( - internal::DefaultOptions( - connection->client_options().credentials(), {}), - std::forward(policies)...), - // We cannot std::move() because it is also used in the previous - // parameter. - connection) { - } - /// Define a tag to disable automatic decorations of the StorageConnection. struct NoDecorations {}; diff --git a/google/cloud/storage/client_bucket_test.cc b/google/cloud/storage/client_bucket_test.cc index fe7962ab7d8fb..d7e426f79c6d6 100644 --- a/google/cloud/storage/client_bucket_test.cc +++ b/google/cloud/storage/client_bucket_test.cc @@ -197,7 +197,6 @@ TEST_F(BucketTest, CreateBucket) { })"""; auto expected = internal::BucketMetadataParser::FromString(text).value(); - EXPECT_CALL(*mock_, client_options()).Times(0); EXPECT_CALL(*mock_, CreateBucket) .WillOnce(Return(StatusOr(TransientError()))) .WillOnce([&expected](internal::CreateBucketRequest const& r) { diff --git a/google/cloud/storage/client_options.cc b/google/cloud/storage/client_options.cc index 686ed1a74d173..34fa437fb07cb 100644 --- a/google/cloud/storage/client_options.cc +++ b/google/cloud/storage/client_options.cc @@ -50,16 +50,6 @@ absl::optional GetEmulator() { return GetEnv("CLOUD_STORAGE_TESTBENCH_ENDPOINT"); } -StatusOr> StorageDefaultCredentials( - ChannelOptions const& channel_options) { - auto emulator = GetEmulator(); - if (emulator.has_value()) { - return StatusOr>( - oauth2::CreateAnonymousCredentials()); - } - return oauth2::GoogleDefaultCredentials(channel_options); -} - std::size_t DefaultConnectionPoolSize() { std::size_t nthreads = std::thread::hardware_concurrency(); if (nthreads == 0) { @@ -116,48 +106,12 @@ std::string RestEndpoint(Options const& options) { return GetEmulator().value_or(options.get()); } -std::string IamRestEndpoint(Options const& options) { - return GetEmulator().value_or(options.get()); -} - -std::string IamRestPath() { - auto emulator = GetEmulator(); - if (emulator) return "/iamapi"; - return {}; -} - -std::string JsonEndpoint(Options const& options) { - return GetEmulator().value_or(options.get()) + - "/storage/" + options.get(); -} - -std::string JsonUploadEndpoint(Options const& options) { - return GetEmulator().value_or(options.get()) + - "/upload/storage/" + options.get(); -} - -std::string XmlEndpoint(Options const& options) { - return GetEmulator().value_or(options.get()); -} - std::string IamEndpoint(Options const& options) { auto emulator = GetEmulator(); if (emulator) return *emulator + "/iamapi"; return options.get(); } -Options MakeOptions(ClientOptions o) { - auto opts = std::move(o.opts_); - if (!o.channel_options().ssl_root_path().empty()) { - opts.set(o.channel_options().ssl_root_path()); - } - return opts; -} - -ClientOptions MakeBackwardsCompatibleClientOptions(Options opts) { - return ClientOptions(std::move(opts)); -} - Options ApplyPolicy(Options opts, RetryPolicy const& p) { opts.set(p.clone()); return opts; @@ -311,67 +265,6 @@ Options DefaultOptionsWithCredentials(Options opts) { } // namespace internal -StatusOr ClientOptions::CreateDefaultClientOptions() { - return CreateDefaultClientOptions(ChannelOptions{}); -} - -StatusOr ClientOptions::CreateDefaultClientOptions( - ChannelOptions const& channel_options) { - auto creds = StorageDefaultCredentials(channel_options); - if (!creds) return creds.status(); - return ClientOptions(*creds, channel_options); -} - -ClientOptions::ClientOptions(std::shared_ptr credentials, - ChannelOptions channel_options) - : opts_(internal::DefaultOptions(std::move(credentials), {})), - channel_options_(std::move(channel_options)) {} - -ClientOptions::ClientOptions(Options o) - : opts_(std::move(o)), - user_agent_prefix_( - absl::StrJoin(opts_.get(), " ")) { - channel_options_.set_ssl_root_path(opts_.get()); -} - -bool ClientOptions::enable_http_tracing() const { - return opts_.get().count("http") != 0; -} - -ClientOptions& ClientOptions::set_enable_http_tracing(bool enable) { - if (enable) { - opts_.lookup().insert("http"); - } else { - opts_.lookup().erase("http"); - } - return *this; -} - -bool ClientOptions::enable_raw_client_tracing() const { - return opts_.get().count("raw-client") != 0; -} - -ClientOptions& ClientOptions::set_enable_raw_client_tracing(bool enable) { - if (enable) { - opts_.lookup().insert("raw-client"); - } else { - opts_.lookup().erase("raw-client"); - } - return *this; -} - -ClientOptions& ClientOptions::SetDownloadBufferSize(std::size_t size) { - opts_.set( - size == 0 ? GOOGLE_CLOUD_CPP_STORAGE_DEFAULT_DOWNLOAD_BUFFER_SIZE : size); - return *this; -} - -ClientOptions& ClientOptions::SetUploadBufferSize(std::size_t size) { - opts_.set( - size == 0 ? GOOGLE_CLOUD_CPP_STORAGE_DEFAULT_UPLOAD_BUFFER_SIZE : size); - return *this; -} - GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END } // namespace storage } // namespace cloud diff --git a/google/cloud/storage/client_options.h b/google/cloud/storage/client_options.h index 09f5e968aff7c..0b32932be6c0b 100644 --- a/google/cloud/storage/client_options.h +++ b/google/cloud/storage/client_options.h @@ -28,20 +28,10 @@ namespace google { namespace cloud { namespace storage { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -class ClientOptions; namespace internal { std::string RestEndpoint(Options const&); -std::string IamRestEndpoint(Options const&); -std::string IamRestPath(); -std::string JsonEndpoint(Options const&); -std::string JsonUploadEndpoint(Options const&); -std::string XmlEndpoint(Options const&); std::string IamEndpoint(Options const&); -Options MakeOptions(ClientOptions); - -ClientOptions MakeBackwardsCompatibleClientOptions(Options); - Options ApplyPolicy(Options opts, RetryPolicy const& p); Options ApplyPolicy(Options opts, BackoffPolicy const& p); Options ApplyPolicy(Options opts, IdempotencyPolicy const& p); @@ -60,399 +50,6 @@ Options DefaultOptionsWithCredentials(Options opts); } // namespace internal -/** - * Describes the configuration for low-level connection features. - * - * Some applications may want to use a different SSL root of trust for their - * connections, for example, containerized applications might store the - * certificate authority certificates in a hard-coded location. - * - * This is a separate class, as it is used to configure both the normal - * connections to GCS and the connections used to obtain OAuth2 access - * tokens. - */ -class ChannelOptions { - public: - /// @deprecated Use google::cloud::Options and - /// google::cloud::CARootsFilePathOption instead. - std::string ssl_root_path() const { return ssl_root_path_; } - - /// @deprecated Use google::cloud::Options and - /// google::cloud::CARootsFilePathOption instead. - ChannelOptions& set_ssl_root_path(std::string ssl_root_path) { - ssl_root_path_ = std::move(ssl_root_path); - return *this; - } - - private: - std::string ssl_root_path_; -}; - -/** - * Describes the configuration for a `storage::Client` object. - * - * By default, several environment variables are read to configure the client: - * - * - `CLOUD_STORAGE_EMULATOR_ENDPOINT`: if set, use this http endpoint to - * make all http requests instead of the production GCS service. Also, - * if set, the `CreateDefaultClientOptions()` function will use an - * `AnonymousCredentials` object instead of loading Application Default - * %Credentials. - * - `CLOUD_STORAGE_ENABLE_CLOG`: if set, enable std::clog as a backend for - * `google::cloud::LogSink`. - * - `CLOUD_STORAGE_ENABLE_TRACING`: if set, this is the list of components that - * will have logging enabled, the component this is: - * - `http`: trace all http request / responses. - * - * @deprecated Please use google::cloud::Options instead. - */ -class ClientOptions { - public: - /** - * Constructor with channel options. - * - * @deprecated use google::cloud::Options instead. - * - * @param credentials how to authenticate to the client. Using a `nullptr` for - * @p credentials results in undefined behavior. - */ - explicit ClientOptions(std::shared_ptr credentials) - : ClientOptions(std::move(credentials), {}) {} - - /** - * Constructor with channel options. - * - * @deprecated use google::cloud::Options instead. - * - * @param credentials how to authenticate to the client. Using a `nullptr` for - * @p credentials results in undefined behavior. - * @param channel_options the configuration for SSL certificate validation. - */ - ClientOptions(std::shared_ptr credentials, - ChannelOptions channel_options); - - /** - * Creates a `ClientOptions` with Google Application Default %Credentials. - * - * If Application Default %Credentials could not be loaded, this returns a - * `Status` with failure details. If the `CLOUD_STORAGE_EMULATOR_ENDPOINT` - * environment variable is set, this function instead uses an - * `AnonymousCredentials` to configure the client. - * - * @deprecated Please use google::cloud::Options instead. - */ - static StatusOr CreateDefaultClientOptions(); - /// @deprecated Please use google::cloud::Options instead. - static StatusOr CreateDefaultClientOptions( - ChannelOptions const& channel_options); - - /** - * @deprecated Use google::cloud::Options and Oauth2CredentialsOption instead. - */ - std::shared_ptr credentials() const { - return opts_.get(); - } - - /** - * @deprecated Use google::cloud::Options and Oauth2CredentialsOption instead. - */ - ClientOptions& set_credentials(std::shared_ptr c) { - opts_.set(std::move(c)); - return *this; - } - - /** - * @deprecated Use google::cloud::Options and RestEndpointOption instead. - */ - std::string const& endpoint() const { - return opts_.get(); - } - - /** - * @deprecated Use google::cloud::Options and RestEndpointOption instead. - */ - ClientOptions& set_endpoint(std::string endpoint) { - opts_.set(std::move(endpoint)); - return *this; - } - - /** - * @deprecated Use google::cloud::Options and IamEndpointOption instead. - */ - std::string const& iam_endpoint() const { - return opts_.get(); - } - - /** - * @deprecated Use google::cloud::Options and IamEndpointOption instead. - */ - ClientOptions& set_iam_endpoint(std::string endpoint) { - opts_.set(std::move(endpoint)); - return *this; - } - - /** - * @deprecated This was intended for development and not a public API. - */ - std::string const& version() const { - return opts_.get(); - } - - /** - * @deprecated This was intended for development and not a public API. - */ - ClientOptions& set_version(std::string version) { - opts_.set(std::move(version)); - return *this; - } - - /** - * @deprecated Use google::cloud::Options and - * google::cloud::LoggingComponentsOption instead. - */ - bool enable_http_tracing() const; - - /** - * @deprecated Use google::cloud::Options and - * google::cloud::LoggingComponentsOption instead. - */ - ClientOptions& set_enable_http_tracing(bool enable); - - /** - * @deprecated Use google::cloud::Options and - * google::cloud::LoggingComponentsOption instead. - */ - bool enable_raw_client_tracing() const; - - /** - * @deprecated Use google::cloud::Options and - * google::cloud::LoggingComponentsOption instead. - */ - ClientOptions& set_enable_raw_client_tracing(bool enable); - - /** - * @deprecated Use google::cloud::Options and ProjectIdOption instead. - */ - std::string const& project_id() const { return opts_.get(); } - - /** - * @deprecated Use google::cloud::Options and ProjectIdOption instead. - */ - ClientOptions& set_project_id(std::string v) { - opts_.set(std::move(v)); - return *this; - } - - /** - * @deprecated Use google::cloud::Options and ConnectionPoolSizeOption - * instead. - */ - std::size_t connection_pool_size() const { - return opts_.get(); - } - - /** - * @deprecated Use google::cloud::Options and ConnectionPoolSizeOption - * instead. - */ - ClientOptions& set_connection_pool_size(std::size_t size) { - opts_.set(size); - return *this; - } - - /** - * @deprecated Use google::cloud::Options and DownloadBufferSizeOption - * instead. - */ - std::size_t download_buffer_size() const { - return opts_.get(); - } - - /** - * @deprecated Use google::cloud::Options and DownloadBufferSizeOption - * instead. - */ - ClientOptions& SetDownloadBufferSize(std::size_t size); - - /** - * @deprecated Use google::cloud::Options and UploadBufferSizeOption instead. - */ - std::size_t upload_buffer_size() const { - return opts_.get(); - } - - /** - * @deprecated Use google::cloud::Options and UploadBufferSizeOption instead. - */ - ClientOptions& SetUploadBufferSize(std::size_t size); - - /** - * @deprecated Use google::cloud::Options and - * google::cloud::UserAgentProductsOption instead. - */ - std::string const& user_agent_prefix() const { return user_agent_prefix_; } - - /** - * @deprecated Use google::cloud::Options and - * google::cloud::UserAgentProductsOption instead. - */ - ClientOptions& add_user_agent_prefix(std::string prefix) { - opts_.lookup().push_back(prefix); - if (!user_agent_prefix_.empty()) { - prefix += ' '; - prefix += user_agent_prefix_; - } - user_agent_prefix_ = std::move(prefix); - return *this; - } - - /// @deprecated use `add_user_agent_prefix()` instead. - ClientOptions& add_user_agent_prefx(std::string const& v) { - return add_user_agent_prefix(v); - } - - /** - * @deprecated Use google::cloud::Options and MaximumSimpleUploadSizeOption - * instead. - */ - std::size_t maximum_simple_upload_size() const { - return opts_.get(); - } - - /** - * @deprecated Use google::cloud::Options and MaximumSimpleUploadSizeOption - * instead. - */ - ClientOptions& set_maximum_simple_upload_size(std::size_t v) { - opts_.set(v); - return *this; - } - - /** - * If true and using OpenSSL 1.0.2 the library configures the OpenSSL - * callbacks for locking. - * - * @deprecated Use google::cloud::options and EnableCurlSslLockingOption - * instead. - */ - bool enable_ssl_locking_callbacks() const { - return opts_.get(); - } - - /** - * If true and using OpenSSL 1.0.2 the library configures the OpenSSL - * callbacks for locking. - * - * @deprecated Use google::cloud::options and EnableCurlSslLockingOption - * instead. - */ - ClientOptions& set_enable_ssl_locking_callbacks(bool v) { - opts_.set(v); - return *this; - } - - /** - * @deprecated Use google::cloud::Options and EnableCurlSigpipeOption - * instead. - */ - bool enable_sigpipe_handler() const { - return opts_.get(); - } - - /** - * @deprecated Use google::cloud::Options and EnableCurlSigpipeOption - * instead. - */ - ClientOptions& set_enable_sigpipe_handler(bool v) { - opts_.set(v); - return *this; - } - - /** - * @deprecated Use google::cloud::Options and MaximumCurlSocketRecvSizeOption - * instead. - */ - std::size_t maximum_socket_recv_size() const { - return opts_.get(); - } - - /** - * @deprecated Use google::cloud::Options and MaximumCurlSocketRecvSizeOption - * instead. - */ - ClientOptions& set_maximum_socket_recv_size(std::size_t v) { - opts_.set(v); - return *this; - } - - /** - * @deprecated Use google::cloud::Options and MaximumCurlSocketSendSizeOption - * instead. - */ - std::size_t maximum_socket_send_size() const { - return opts_.get(); - } - - /** - * @deprecated Use google::cloud::Options and MaximumCurlSocketSendSizeOption - * instead. - */ - ClientOptions& set_maximum_socket_send_size(std::size_t v) { - opts_.set(v); - return *this; - } - - /// @deprecated Use google::cloud::Options and - /// google::cloud::CARootsFilePathOption instead. - ChannelOptions& channel_options() { return channel_options_; } - - /// @deprecated Use google::cloud::Options and - /// google::cloud::CARootsFilePathOption instead. - ChannelOptions const& channel_options() const { return channel_options_; } - - ///@{ - /** - * Control the maximum amount of time allowed for "stalls" during a download. - * - * A download that receives no data is considered "stalled". If the download - * remains stalled for more than the time set in this option then the download - * is aborted. - * - * The default value is 2 minutes. Can be disabled by setting the value to 0. - * - * @deprecated Use google::cloud::Options and DownloadStallTimeoutOption - * instead. - */ - std::chrono::seconds download_stall_timeout() const { - return opts_.get(); - } - - /** - * @deprecated Use google::cloud::Options and DownloadStallTimeoutOption - * instead. - */ - ClientOptions& set_download_stall_timeout(std::chrono::seconds v) { - opts_.set(std::move(v)); - return *this; - } - ///@} - - private: - friend Options internal::MakeOptions(ClientOptions); - friend ClientOptions internal::MakeBackwardsCompatibleClientOptions(Options); - - explicit ClientOptions(Options o); - - Options opts_; - - // Used for backwards compatibility. The value here is merged with the values - // in `opts_` by internal::MakeOptions(ClientOptions const&); - ChannelOptions channel_options_; - - // Only used for backwards compatibility, the value in `opts_. - std::string user_agent_prefix_; -}; - GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END } // namespace storage } // namespace cloud diff --git a/google/cloud/storage/client_options_test.cc b/google/cloud/storage/client_options_test.cc index 722e5e82c1369..dea07878b0cfb 100644 --- a/google/cloud/storage/client_options_test.cc +++ b/google/cloud/storage/client_options_test.cc @@ -14,6 +14,7 @@ #include "google/cloud/storage/client_options.h" #include "google/cloud/storage/oauth2/google_credentials.h" +#include "google/cloud/storage/options.h" #include "google/cloud/internal/curl_options.h" #include "google/cloud/internal/filesystem.h" #include "google/cloud/internal/random.h" @@ -35,10 +36,7 @@ namespace cloud { namespace storage { GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN -using ::google::cloud::testing_util::IsOk; using ::google::cloud::testing_util::ScopedEnvironment; -using ::testing::IsEmpty; -using ::testing::Not; using ::testing::UnorderedElementsAre; namespace { @@ -67,278 +65,45 @@ class ClientOptionsTest : public ::testing::Test { google::cloud::internal::DefaultPRNG generator_; }; -// This is a syntactically valid JSON key file, but the key has been invalidated -// and therefore present no security risks. -constexpr char kJsonKeyfileContents[] = R"""({ - "type": "service_account", - "project_id": "foo-project", - "private_key_id": "a1a111aa1111a11a11a11aa111a111a1a1111111", - "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCltiF2oP3KJJ+S\ntTc1McylY+TuAi3AdohX7mmqIjd8a3eBYDHs7FlnUrFC4CRijCr0rUqYfg2pmk4a\n6TaKbQRAhWDJ7XD931g7EBvCtd8+JQBNWVKnP9ByJUaO0hWVniM50KTsWtyX3up/\nfS0W2R8Cyx4yvasE8QHH8gnNGtr94iiORDC7De2BwHi/iU8FxMVJAIyDLNfyk0hN\neheYKfIDBgJV2v6VaCOGWaZyEuD0FJ6wFeLybFBwibrLIBE5Y/StCrZoVZ5LocFP\nT4o8kT7bU6yonudSCyNMedYmqHj/iF8B2UN1WrYx8zvoDqZk0nxIglmEYKn/6U7U\ngyETGcW9AgMBAAECggEAC231vmkpwA7JG9UYbviVmSW79UecsLzsOAZnbtbn1VLT\nPg7sup7tprD/LXHoyIxK7S/jqINvPU65iuUhgCg3Rhz8+UiBhd0pCH/arlIdiPuD\n2xHpX8RIxAq6pGCsoPJ0kwkHSw8UTnxPV8ZCPSRyHV71oQHQgSl/WjNhRi6PQroB\nSqc/pS1m09cTwyKQIopBBVayRzmI2BtBxyhQp9I8t5b7PYkEZDQlbdq0j5Xipoov\n9EW0+Zvkh1FGNig8IJ9Wp+SZi3rd7KLpkyKPY7BK/g0nXBkDxn019cET0SdJOHQG\nDiHiv4yTRsDCHZhtEbAMKZEpku4WxtQ+JjR31l8ueQKBgQDkO2oC8gi6vQDcx/CX\nZ23x2ZUyar6i0BQ8eJFAEN+IiUapEeCVazuxJSt4RjYfwSa/p117jdZGEWD0GxMC\n+iAXlc5LlrrWs4MWUc0AHTgXna28/vii3ltcsI0AjWMqaybhBTTNbMFa2/fV2OX2\nUimuFyBWbzVc3Zb9KAG4Y7OmJQKBgQC5324IjXPq5oH8UWZTdJPuO2cgRsvKmR/r\n9zl4loRjkS7FiOMfzAgUiXfH9XCnvwXMqJpuMw2PEUjUT+OyWjJONEK4qGFJkbN5\n3ykc7p5V7iPPc7Zxj4mFvJ1xjkcj+i5LY8Me+gL5mGIrJ2j8hbuv7f+PWIauyjnp\nNx/0GVFRuQKBgGNT4D1L7LSokPmFIpYh811wHliE0Fa3TDdNGZnSPhaD9/aYyy78\nLkxYKuT7WY7UVvLN+gdNoVV5NsLGDa4cAV+CWPfYr5PFKGXMT/Wewcy1WOmJ5des\nAgMC6zq0TdYmMBN6WpKUpEnQtbmh3eMnuvADLJWxbH3wCkg+4xDGg2bpAoGAYRNk\nMGtQQzqoYNNSkfus1xuHPMA8508Z8O9pwKU795R3zQs1NAInpjI1sOVrNPD7Ymwc\nW7mmNzZbxycCUL/yzg1VW4P1a6sBBYGbw1SMtWxun4ZbnuvMc2CTCh+43/1l+FHe\nMmt46kq/2rH2jwx5feTbOE6P6PINVNRJh/9BDWECgYEAsCWcH9D3cI/QDeLG1ao7\nrE2NcknP8N783edM07Z/zxWsIsXhBPY3gjHVz2LDl+QHgPWhGML62M0ja/6SsJW3\nYvLLIc82V7eqcVJTZtaFkuht68qu/Jn1ezbzJMJ4YXDYo1+KFi+2CAGR06QILb+I\nlUtj+/nH3HDQjM4ltYfTPUg=\n-----END PRIVATE KEY-----\n", - "client_email": "foo-email@foo-project.iam.gserviceaccount.com", - "client_id": "100000000000000000001", - "auth_uri": "https://accounts.google.com/o/oauth2/auth", - "token_uri": "https://oauth2.googleapis.com/token", - "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", - "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/foo-email%40foo-project.iam.gserviceaccount.com" -})"""; - -TEST_F(ClientOptionsTest, Default) { - // Create the options with the anonymous credentials because the default - // credentials try to load the application default credentials, and those do - // not exist in the CI environment, which results in errors or warnings. - auto creds = oauth2::CreateAnonymousCredentials(); - ClientOptions options(creds); - EXPECT_FALSE(options.enable_http_tracing()); - EXPECT_FALSE(options.enable_raw_client_tracing()); - EXPECT_TRUE(creds.get() == options.credentials().get()); - EXPECT_EQ("https://storage.googleapis.com", options.endpoint()); - EXPECT_EQ("v1", options.version()); - EXPECT_EQ("https://iamcredentials.googleapis.com/v1", options.iam_endpoint()); -} - -TEST_F(ClientOptionsTest, CreateDefaultError) { - testing_util::ScopedEnvironment creds("GOOGLE_APPLICATION_CREDENTIALS", - "not-a-file-should-fail"); - auto connection = ClientOptions::CreateDefaultClientOptions(); - EXPECT_THAT(connection, Not(IsOk())); -} - -TEST_F(ClientOptionsTest, CreateDefaultWithChannelOptionsError) { - testing_util::ScopedEnvironment creds("GOOGLE_APPLICATION_CREDENTIALS", - "not-a-file-should-fail"); - auto connection = ClientOptions::CreateDefaultClientOptions({}); - EXPECT_THAT(connection, Not(IsOk())); -} - -TEST_F(ClientOptionsTest, CreateDefault) { - auto file = CreateRandomFileName(); - std::ofstream(file) << kJsonKeyfileContents; - testing_util::ScopedEnvironment creds("GOOGLE_APPLICATION_CREDENTIALS", file); - auto connection = ClientOptions::CreateDefaultClientOptions(); - EXPECT_STATUS_OK(connection); - std::remove(file.c_str()); -} - -TEST_F(ClientOptionsTest, CreateDefaultWithChannelOptions) { - auto file = CreateRandomFileName(); - std::ofstream(file) << kJsonKeyfileContents; - testing_util::ScopedEnvironment creds("GOOGLE_APPLICATION_CREDENTIALS", file); - auto connection = ClientOptions::CreateDefaultClientOptions({}); - EXPECT_STATUS_OK(connection); -} - -TEST_F(ClientOptionsTest, EnableRpc) { - testing_util::ScopedEnvironment enable_tracing("CLOUD_STORAGE_ENABLE_TRACING", - "foo,raw-client,bar"); - ClientOptions options(oauth2::CreateAnonymousCredentials()); - EXPECT_TRUE(options.enable_raw_client_tracing()); -} - -TEST_F(ClientOptionsTest, EnableHttp) { - testing_util::ScopedEnvironment enable_tracing("CLOUD_STORAGE_ENABLE_TRACING", - "foo,http,bar"); - ClientOptions options(oauth2::CreateAnonymousCredentials()); - EXPECT_TRUE(options.enable_http_tracing()); -} - TEST_F(ClientOptionsTest, EndpointsDefault) { testing_util::ScopedEnvironment endpoint("CLOUD_STORAGE_EMULATOR_ENDPOINT", {}); - ClientOptions options(oauth2::CreateAnonymousCredentials()); - EXPECT_EQ("https://storage.googleapis.com", options.endpoint()); - auto o = internal::MakeOptions(std::move(options)); - EXPECT_EQ("https://storage.googleapis.com/storage/v1", - internal::JsonEndpoint(o)); - EXPECT_EQ("https://storage.googleapis.com/upload/storage/v1", - internal::JsonUploadEndpoint(o)); + auto options = + internal::DefaultOptions(oauth2::CreateAnonymousCredentials(), {}); + EXPECT_EQ("https://storage.googleapis.com", + options.get()); EXPECT_EQ("https://iamcredentials.googleapis.com/v1", - internal::IamEndpoint(o)); + internal::IamEndpoint(options)); } TEST_F(ClientOptionsTest, EndpointsOverride) { testing_util::ScopedEnvironment endpoint("CLOUD_STORAGE_EMULATOR_ENDPOINT", {}); - ClientOptions options(oauth2::CreateAnonymousCredentials()); - options.set_endpoint("http://127.0.0.1.nip.io:1234"); - EXPECT_EQ("http://127.0.0.1.nip.io:1234", options.endpoint()); - auto o = internal::MakeOptions(std::move(options)); - EXPECT_EQ("http://127.0.0.1.nip.io:1234/storage/v1", - internal::JsonEndpoint(o)); - EXPECT_EQ("http://127.0.0.1.nip.io:1234/upload/storage/v1", - internal::JsonUploadEndpoint(o)); - EXPECT_EQ("http://127.0.0.1.nip.io:1234", internal::XmlEndpoint(o)); + auto options = internal::DefaultOptions( + oauth2::CreateAnonymousCredentials(), + Options{}.set("http://127.0.0.1.nip.io:1234")); + EXPECT_EQ("http://127.0.0.1.nip.io:1234", options.get()); EXPECT_EQ("https://iamcredentials.googleapis.com/v1", - internal::IamEndpoint(o)); + internal::IamEndpoint(options)); } TEST_F(ClientOptionsTest, EndpointsEmulator) { testing_util::ScopedEnvironment endpoint("CLOUD_STORAGE_EMULATOR_ENDPOINT", "http://localhost:1234"); - ClientOptions options(oauth2::CreateAnonymousCredentials()); - EXPECT_EQ("http://localhost:1234", options.endpoint()); - auto o = internal::MakeOptions(std::move(options)); - EXPECT_EQ("http://localhost:1234/storage/v1", internal::JsonEndpoint(o)); - EXPECT_EQ("http://localhost:1234/upload/storage/v1", - internal::JsonUploadEndpoint(o)); - EXPECT_EQ("http://localhost:1234", internal::XmlEndpoint(o)); - EXPECT_EQ("http://localhost:1234/iamapi", internal::IamEndpoint(o)); + auto options = + internal::DefaultOptions(oauth2::CreateAnonymousCredentials(), {}); + EXPECT_EQ("http://localhost:1234", options.get()); + EXPECT_EQ("http://localhost:1234/iamapi", internal::IamEndpoint(options)); } TEST_F(ClientOptionsTest, OldEndpointsEmulator) { google::cloud::testing_util::UnsetEnv("CLOUD_STORAGE_EMULATOR_ENDPOINT"); testing_util::ScopedEnvironment endpoint("CLOUD_STORAGE_TESTBENCH_ENDPOINT", "http://localhost:1234"); - ClientOptions options(oauth2::CreateAnonymousCredentials()); - EXPECT_EQ("http://localhost:1234", options.endpoint()); - auto o = internal::MakeOptions(std::move(options)); - EXPECT_EQ("http://localhost:1234/storage/v1", internal::JsonEndpoint(o)); - EXPECT_EQ("http://localhost:1234/upload/storage/v1", - internal::JsonUploadEndpoint(o)); - EXPECT_EQ("http://localhost:1234", internal::XmlEndpoint(o)); - EXPECT_EQ("http://localhost:1234/iamapi", internal::IamEndpoint(o)); -} - -TEST_F(ClientOptionsTest, SetVersion) { - ClientOptions options(oauth2::CreateAnonymousCredentials()); - options.set_version("vTest"); - EXPECT_EQ("vTest", options.version()); - auto o = internal::MakeOptions(std::move(options)); - EXPECT_EQ("https://storage.googleapis.com/storage/vTest", - internal::JsonEndpoint(o)); - EXPECT_EQ("https://storage.googleapis.com/upload/storage/vTest", - internal::JsonUploadEndpoint(o)); -} - -TEST_F(ClientOptionsTest, SetIamEndpoint) { - ClientOptions options(oauth2::CreateAnonymousCredentials()); - options.set_iam_endpoint("http://localhost:1/v2"); - EXPECT_EQ("http://localhost:1/v2", options.iam_endpoint()); -} - -TEST_F(ClientOptionsTest, SetCredentials) { - auto creds = oauth2::CreateAnonymousCredentials(); - ClientOptions options(creds); - auto other = oauth2::CreateAnonymousCredentials(); - options.set_credentials(other); - EXPECT_TRUE(other.get() == options.credentials().get()); - EXPECT_FALSE(creds.get() == other.get()); -} - -TEST_F(ClientOptionsTest, ProjectIdFromEnvironment) { - google::cloud::testing_util::SetEnv("GOOGLE_CLOUD_PROJECT", - "test-project-id"); - ClientOptions options(oauth2::CreateAnonymousCredentials()); - EXPECT_EQ("test-project-id", options.project_id()); -} - -TEST_F(ClientOptionsTest, ProjectIdFromEnvironmentNotSet) { - google::cloud::testing_util::UnsetEnv("GOOGLE_CLOUD_PROJECT"); - ClientOptions options(oauth2::CreateAnonymousCredentials()); - EXPECT_EQ("", options.project_id()); -} - -TEST_F(ClientOptionsTest, SetProjectId) { - ClientOptions options(oauth2::CreateAnonymousCredentials()); - options.set_project_id("test-project-id"); - EXPECT_EQ("test-project-id", options.project_id()); -} - -TEST_F(ClientOptionsTest, SetDownloadBufferSize) { - ClientOptions client_options(oauth2::CreateAnonymousCredentials()); - auto default_size = client_options.download_buffer_size(); - EXPECT_NE(0U, default_size); - client_options.SetDownloadBufferSize(1024); - EXPECT_EQ(1024, client_options.download_buffer_size()); - client_options.SetDownloadBufferSize(0); - EXPECT_EQ(default_size, client_options.download_buffer_size()); -} - -TEST_F(ClientOptionsTest, SetUploadBufferSize) { - ClientOptions client_options(oauth2::CreateAnonymousCredentials()); - auto default_size = client_options.upload_buffer_size(); - EXPECT_NE(0U, default_size); - client_options.SetUploadBufferSize(1024); - EXPECT_EQ(1024, client_options.upload_buffer_size()); - client_options.SetUploadBufferSize(0); - EXPECT_EQ(default_size, client_options.upload_buffer_size()); -} - -TEST_F(ClientOptionsTest, UserAgentPrefix) { - ClientOptions options(oauth2::CreateAnonymousCredentials()); - EXPECT_EQ("", options.user_agent_prefix()); - options.add_user_agent_prefix("foo-1.0"); - EXPECT_EQ("foo-1.0", options.user_agent_prefix()); - options.add_user_agent_prefix("bar-2.2"); - EXPECT_EQ("bar-2.2 foo-1.0", options.user_agent_prefix()); -} - -TEST_F(ClientOptionsTest, SetMaximumSimpleUploadSize) { - ClientOptions client_options(oauth2::CreateAnonymousCredentials()); - auto default_size = client_options.maximum_simple_upload_size(); - EXPECT_NE(0U, default_size); - client_options.set_maximum_simple_upload_size(1024); - EXPECT_EQ(1024, client_options.maximum_simple_upload_size()); - client_options.set_maximum_simple_upload_size(0); - EXPECT_EQ(0, client_options.maximum_simple_upload_size()); -} - -TEST_F(ClientOptionsTest, SetEnableLockingCallbacks) { - ClientOptions client_options(oauth2::CreateAnonymousCredentials()); - auto default_value = client_options.enable_ssl_locking_callbacks(); - EXPECT_TRUE(default_value); - client_options.set_enable_ssl_locking_callbacks(false); - EXPECT_FALSE(client_options.enable_ssl_locking_callbacks()); - client_options.set_enable_ssl_locking_callbacks(true); - EXPECT_TRUE(client_options.enable_ssl_locking_callbacks()); -} - -TEST_F(ClientOptionsTest, SetMaximumSocketRecvSize) { - ClientOptions client_options(oauth2::CreateAnonymousCredentials()); - auto default_value = client_options.maximum_socket_recv_size(); - EXPECT_EQ(0, default_value); - client_options.set_maximum_socket_recv_size(16 * 1024); - EXPECT_EQ(16 * 1024, client_options.maximum_socket_recv_size()); -} - -TEST_F(ClientOptionsTest, SetMaximumSocketSendSize) { - ClientOptions client_options(oauth2::CreateAnonymousCredentials()); - auto default_value = client_options.maximum_socket_send_size(); - EXPECT_EQ(0, default_value); - client_options.set_maximum_socket_send_size(16 * 1024); - EXPECT_EQ(16 * 1024, client_options.maximum_socket_send_size()); -} - -TEST_F(ClientOptionsTest, SetMaximumDownloadStall) { - ClientOptions client_options(oauth2::CreateAnonymousCredentials()); - auto default_value = client_options.download_stall_timeout(); - EXPECT_NE(0, default_value.count()); - client_options.set_download_stall_timeout(std::chrono::seconds(60)); - EXPECT_EQ(60, client_options.download_stall_timeout().count()); -} - -TEST_F(ClientOptionsTest, MakeOptionsFromDefault) { - google::cloud::testing_util::SetEnv("GOOGLE_CLOUD_PROJECT", - "test-project-id"); - auto const opts = internal::MakeOptions( - ClientOptions(oauth2::CreateAnonymousCredentials())); - EXPECT_EQ("https://storage.googleapis.com", opts.get()); - EXPECT_EQ("https://iamcredentials.googleapis.com/v1", - opts.get()); - EXPECT_TRUE(opts.has()); - EXPECT_EQ("v1", opts.get()); - EXPECT_EQ("test-project-id", opts.get()); - EXPECT_LT(0, opts.get()); - EXPECT_LT(0, opts.get()); - EXPECT_LT(0, opts.get()); - EXPECT_LT(0, opts.get()); - EXPECT_LT(0, opts.get()); - EXPECT_TRUE(opts.has()); - EXPECT_TRUE(opts.has()); - EXPECT_EQ(0, opts.get()); - EXPECT_EQ(0, opts.get()); - EXPECT_LT(0, opts.get().count()); - EXPECT_LT(0, opts.get()); - EXPECT_THAT(opts.get(), IsEmpty()); + auto options = + internal::DefaultOptions(oauth2::CreateAnonymousCredentials(), {}); + EXPECT_EQ("http://localhost:1234", options.get()); + EXPECT_EQ("http://localhost:1234/iamapi", internal::IamEndpoint(options)); } TEST_F(ClientOptionsTest, DefaultOptions) { diff --git a/google/cloud/storage/client_test.cc b/google/cloud/storage/client_test.cc index 4ac15c0170eba..270a0b918d46e 100644 --- a/google/cloud/storage/client_test.cc +++ b/google/cloud/storage/client_test.cc @@ -37,8 +37,6 @@ namespace { using ::google::cloud::storage::internal::ClientImplDetails; using ::google::cloud::storage::testing::canonical_errors::TransientError; -using ::google::cloud::testing_util::IsOkAndHolds; -using ::google::cloud::testing_util::MockBackoffPolicy; using ::google::cloud::testing_util::ScopedEnvironment; using ::testing::ElementsAre; using ::testing::NotNull; @@ -238,63 +236,6 @@ TEST_F(ClientTest, OTelDisableTracing) { ElementsAre("RestStub", "LoggingStub", "StorageConnectionImpl")); } -#include "google/cloud/internal/disable_deprecation_warnings.inc" - -TEST_F(ClientTest, DeprecatedButNotDecommissioned) { - auto m1 = std::make_shared(); - - auto c1 = storage::Client(m1, Client::NoDecorations{}); - EXPECT_EQ(c1.raw_client().get(), m1.get()); - - auto m2 = std::make_shared(); - auto c2 = storage::Client(m2, LimitedErrorCountRetryPolicy(3)); - EXPECT_NE(c2.raw_client().get(), m2.get()); -} - -TEST_F(ClientTest, DeprecatedRetryPolicies) { - auto constexpr kNumRetries = 2; - auto mock_b = std::make_unique(); - EXPECT_CALL(*mock_b, clone).WillOnce([=] { - auto clone_1 = std::make_unique(); - EXPECT_CALL(*clone_1, clone).WillOnce([=] { - auto clone_2 = std::make_unique(); - EXPECT_CALL(*clone_2, OnCompletion) - .Times(kNumRetries) - .WillRepeatedly(Return(std::chrono::milliseconds(0))); - return clone_2; - }); - return clone_1; - }); - - auto mock = std::make_shared(); - EXPECT_CALL(*mock, ListBuckets) - .Times(kNumRetries + 1) - .WillRepeatedly(Return(TransientError())); - - auto client = storage::Client(mock, LimitedErrorCountRetryPolicy(kNumRetries), - std::move(*mock_b)); - (void)client.ListBuckets(OverrideDefaultProject("fake-project")); -} - -TEST_F(ClientTest, DeprecatedClientFromMock) { - auto mock = std::make_shared(); - auto client = testing::ClientFromMock(mock); - - internal::ListObjectsResponse response; - response.items.push_back( - ObjectMetadata{}.set_bucket("bucket").set_name("object/1")); - response.items.push_back( - ObjectMetadata{}.set_bucket("bucket").set_name("object/2")); - EXPECT_CALL(*mock, ListObjects) - .WillOnce(Return(TransientError())) - .WillOnce(Return(response)); - - auto stream = client.ListObjects("bucket", Prefix("object/")); - std::vector> objects{stream.begin(), stream.end()}; - EXPECT_THAT(objects, ElementsAre(IsOkAndHolds(response.items[0]), - IsOkAndHolds(response.items[1]))); -} - } // namespace GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END } // namespace storage diff --git a/google/cloud/storage/internal/async/rewriter_connection_impl.h b/google/cloud/storage/internal/async/rewriter_connection_impl.h index 32e44ef9ca7c0..39ccce887737d 100644 --- a/google/cloud/storage/internal/async/rewriter_connection_impl.h +++ b/google/cloud/storage/internal/async/rewriter_connection_impl.h @@ -17,9 +17,9 @@ #include "google/cloud/storage/async/rewriter_connection.h" #include "google/cloud/storage/internal/storage_stub.h" +#include "google/cloud/storage/options.h" #include "google/cloud/completion_queue.h" #include "google/cloud/future.h" -#include "google/cloud/options.h" #include "google/cloud/status_or.h" #include "google/cloud/version.h" #include "google/storage/v2/storage.pb.h" diff --git a/google/cloud/storage/internal/connection_impl.cc b/google/cloud/storage/internal/connection_impl.cc index e86236b7942ab..6078d137b10d8 100644 --- a/google/cloud/storage/internal/connection_impl.cc +++ b/google/cloud/storage/internal/connection_impl.cc @@ -154,12 +154,7 @@ std::shared_ptr StorageConnectionImpl::Create( StorageConnectionImpl::StorageConnectionImpl( std::unique_ptr stub, Options options) : stub_(std::move(stub)), - options_(MergeOptions(std::move(options), stub_->options())), - client_options_(MakeBackwardsCompatibleClientOptions(options_)) {} - -ClientOptions const& StorageConnectionImpl::client_options() const { - return client_options_; -} + options_(MergeOptions(std::move(options), stub_->options())) {} Options StorageConnectionImpl::options() const { return options_; } diff --git a/google/cloud/storage/internal/connection_impl.h b/google/cloud/storage/internal/connection_impl.h index 43bc8795f479d..b487aa6fd6efa 100644 --- a/google/cloud/storage/internal/connection_impl.h +++ b/google/cloud/storage/internal/connection_impl.h @@ -44,7 +44,6 @@ class StorageConnectionImpl ~StorageConnectionImpl() override = default; - ClientOptions const& client_options() const override; Options options() const override; StatusOr ListBuckets( @@ -188,7 +187,6 @@ class StorageConnectionImpl std::unique_ptr stub_; Options options_; - ClientOptions client_options_; // For backwards compatibility google::cloud::internal::InvocationIdGenerator invocation_id_generator_; }; diff --git a/google/cloud/storage/internal/generic_stub.h b/google/cloud/storage/internal/generic_stub.h index ddf35b377488a..1e03abe2f5a4c 100644 --- a/google/cloud/storage/internal/generic_stub.h +++ b/google/cloud/storage/internal/generic_stub.h @@ -16,7 +16,6 @@ #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_GENERIC_STUB_H #include "google/cloud/storage/bucket_metadata.h" -#include "google/cloud/storage/client_options.h" #include "google/cloud/storage/internal/bucket_acl_requests.h" #include "google/cloud/storage/internal/bucket_requests.h" #include "google/cloud/storage/internal/default_object_acl_requests.h" diff --git a/google/cloud/storage/internal/grpc/stub.h b/google/cloud/storage/internal/grpc/stub.h index 9e6024bdb781e..71b216b7be62a 100644 --- a/google/cloud/storage/internal/grpc/stub.h +++ b/google/cloud/storage/internal/grpc/stub.h @@ -15,6 +15,7 @@ #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_GRPC_STUB_H #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_GRPC_STUB_H +#include "google/cloud/storage/client_options.h" #include "google/cloud/storage/internal/generic_stub.h" #include "google/cloud/storage/version.h" #include "google/cloud/background_threads.h" diff --git a/google/cloud/storage/internal/rest/stub.cc b/google/cloud/storage/internal/rest/stub.cc index 32c0e93542be9..6c5235773058b 100644 --- a/google/cloud/storage/internal/rest/stub.cc +++ b/google/cloud/storage/internal/rest/stub.cc @@ -13,6 +13,7 @@ // limitations under the License. #include "google/cloud/storage/internal/rest/stub.h" +#include "google/cloud/storage/client_options.h" #include "google/cloud/storage/internal/bucket_access_control_parser.h" #include "google/cloud/storage/internal/bucket_metadata_parser.h" #include "google/cloud/storage/internal/bucket_requests.h" @@ -31,6 +32,7 @@ #include "google/cloud/internal/curl_wrappers.h" #include "google/cloud/internal/getenv.h" #include "google/cloud/internal/make_status.h" +#include "google/cloud/internal/rest_options.h" #include "google/cloud/internal/url_encode.h" #include "absl/strings/match.h" #include "absl/strings/strip.h" diff --git a/google/cloud/storage/internal/rest/stub.h b/google/cloud/storage/internal/rest/stub.h index d6a04a96c2a20..e0d100bc486cb 100644 --- a/google/cloud/storage/internal/rest/stub.h +++ b/google/cloud/storage/internal/rest/stub.h @@ -17,6 +17,7 @@ #include "google/cloud/storage/internal/generic_stub.h" #include "google/cloud/storage/internal/rest/request_builder.h" +#include "google/cloud/storage/options.h" #include "google/cloud/storage/version.h" #include "google/cloud/internal/random.h" #include "google/cloud/internal/rest_client.h" diff --git a/google/cloud/storage/internal/storage_connection.h b/google/cloud/storage/internal/storage_connection.h index 0cc24e6876125..28cfe3af468cb 100644 --- a/google/cloud/storage/internal/storage_connection.h +++ b/google/cloud/storage/internal/storage_connection.h @@ -16,7 +16,6 @@ #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_STORAGE_CONNECTION_H #include "google/cloud/storage/bucket_metadata.h" -#include "google/cloud/storage/client_options.h" #include "google/cloud/storage/internal/bucket_acl_requests.h" #include "google/cloud/storage/internal/bucket_requests.h" #include "google/cloud/storage/internal/default_object_acl_requests.h" @@ -57,8 +56,6 @@ class StorageConnection { public: virtual ~StorageConnection() = default; - virtual ClientOptions const& client_options() const = 0; - virtual google::cloud::Options options() const { return {}; } ///@{ diff --git a/google/cloud/storage/internal/storage_connection_test.cc b/google/cloud/storage/internal/storage_connection_test.cc index 09c0e539bd234..54b23c3172d50 100644 --- a/google/cloud/storage/internal/storage_connection_test.cc +++ b/google/cloud/storage/internal/storage_connection_test.cc @@ -33,7 +33,6 @@ class TestStorageConnection : public StorageConnection { public: ~TestStorageConnection() override = default; // LCOV_EXCL_START - MOCK_METHOD(ClientOptions const&, client_options, (), (const, override)); MOCK_METHOD(StatusOr, ListBuckets, (ListBucketsRequest const&), (override)); MOCK_METHOD(StatusOr, CreateBucket, diff --git a/google/cloud/storage/internal/tracing_connection.cc b/google/cloud/storage/internal/tracing_connection.cc index 2f8711dc99831..6d7e20a2d349b 100644 --- a/google/cloud/storage/internal/tracing_connection.cc +++ b/google/cloud/storage/internal/tracing_connection.cc @@ -29,9 +29,6 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN TracingConnection::TracingConnection(std::shared_ptr impl) : impl_(std::move(impl)) {} -storage::ClientOptions const& TracingConnection::client_options() const { - return impl_->client_options(); -} Options TracingConnection::options() const { return impl_->options(); } StatusOr TracingConnection::ListBuckets( diff --git a/google/cloud/storage/internal/tracing_connection.h b/google/cloud/storage/internal/tracing_connection.h index 66ece3f37f4c7..45df6239f956d 100644 --- a/google/cloud/storage/internal/tracing_connection.h +++ b/google/cloud/storage/internal/tracing_connection.h @@ -32,7 +32,6 @@ class TracingConnection : public storage::internal::StorageConnection { explicit TracingConnection(std::shared_ptr impl); ~TracingConnection() override = default; - storage::ClientOptions const& client_options() const override; Options options() const override; StatusOr ListBuckets( diff --git a/google/cloud/storage/oauth2/authorized_user_credentials.cc b/google/cloud/storage/oauth2/authorized_user_credentials.cc index d17956c5c7d49..2aa7c4ba50bd7 100644 --- a/google/cloud/storage/oauth2/authorized_user_credentials.cc +++ b/google/cloud/storage/oauth2/authorized_user_credentials.cc @@ -69,22 +69,20 @@ ParseAuthorizedUserRefreshResponse( AuthorizedUserCredentials:: AuthorizedUserCredentials(AuthorizedUserCredentialsInfo const& info, - ChannelOptions const& channel_options) + Options options) : AuthorizedUserCredentials( google::cloud::oauth2_internal::AuthorizedUserCredentialsInfo{ info.client_id, info.client_secret, info.refresh_token, info.token_uri, info.universe_domain}, - channel_options) {} + std::move(options)) {} AuthorizedUserCredentials:: AuthorizedUserCredentials( google::cloud::oauth2_internal::AuthorizedUserCredentialsInfo info, - ChannelOptions const& channel_options) + Options options) : AuthorizedUserCredentials( - std::move(info), - Options{}.set(channel_options.ssl_root_path()), - [](Options const& o) { + std::move(info), std::move(options), [](Options const& o) { return rest_internal::MakeDefaultRestClient(std::string{}, o); }) {} diff --git a/google/cloud/storage/oauth2/authorized_user_credentials.h b/google/cloud/storage/oauth2/authorized_user_credentials.h index ca9a04fb57001..8393e73a5d4ce 100644 --- a/google/cloud/storage/oauth2/authorized_user_credentials.h +++ b/google/cloud/storage/oauth2/authorized_user_credentials.h @@ -15,7 +15,6 @@ #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OAUTH2_AUTHORIZED_USER_CREDENTIALS_H #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OAUTH2_AUTHORIZED_USER_CREDENTIALS_H -#include "google/cloud/storage/client_options.h" #include "google/cloud/storage/internal/curl/request_builder.h" #include "google/cloud/storage/internal/http_response.h" #include "google/cloud/storage/oauth2/credential_constants.h" @@ -26,6 +25,7 @@ #include "google/cloud/internal/oauth2_authorized_user_credentials.h" #include "google/cloud/internal/oauth2_cached_credentials.h" #include "google/cloud/internal/oauth2_credential_constants.h" +#include "google/cloud/options.h" #include "google/cloud/status.h" #include #include @@ -121,13 +121,12 @@ class GOOGLE_CLOUD_CPP_DEPRECATED( AuthorizedUserCredentials : public Credentials { public: - explicit AuthorizedUserCredentials( - AuthorizedUserCredentialsInfo const& info, - ChannelOptions const& channel_options = {}); + explicit AuthorizedUserCredentials(AuthorizedUserCredentialsInfo const& info, + Options options = {}); explicit AuthorizedUserCredentials( google::cloud::oauth2_internal::AuthorizedUserCredentialsInfo info, - ChannelOptions const& channel_options = {}); + Options options = {}); StatusOr AuthorizationHeader() override { return oauth2_internal::AuthenticationHeaderJoined(*impl_); @@ -155,11 +154,8 @@ class GOOGLE_CLOUD_CPP_DEPRECATED( : public Credentials { public: explicit AuthorizedUserCredentials(AuthorizedUserCredentialsInfo info, - ChannelOptions const& channel_options = {}) - : info_(std::move(info)), - options_(Options{}.set( - channel_options.ssl_root_path())), - clock_() {} + Options options = {}) + : info_(std::move(info)), options_(std::move(options)), clock_() {} StatusOr AuthorizationHeader() override { std::unique_lock lock(mu_); diff --git a/google/cloud/storage/oauth2/authorized_user_credentials_test.cc b/google/cloud/storage/oauth2/authorized_user_credentials_test.cc index 141872cd2e76c..785f6e9ee7b92 100644 --- a/google/cloud/storage/oauth2/authorized_user_credentials_test.cc +++ b/google/cloud/storage/oauth2/authorized_user_credentials_test.cc @@ -15,6 +15,7 @@ #include "google/cloud/storage/oauth2/authorized_user_credentials.h" #include "google/cloud/storage/oauth2/credential_constants.h" #include "google/cloud/storage/testing/mock_http_request.h" +#include "google/cloud/common_options.h" #include "google/cloud/testing_util/mock_fake_clock.h" #include "google/cloud/testing_util/mock_http_payload.h" #include "google/cloud/testing_util/mock_rest_client.h" @@ -272,7 +273,7 @@ TEST_F(AuthorizedUserCredentialsTest, UsesCARootsInfo) { auto info = ParseAuthorizedUserCredentials(config, "test"); ASSERT_STATUS_OK(info); AuthorizedUserCredentials credentials( - *info, ChannelOptions().set_ssl_root_path(cainfo)); + *info, Options{}.set(cainfo)); EXPECT_EQ("Authorization: Mock-Type fake-token", credentials.AuthorizationHeader().value()); } diff --git a/google/cloud/storage/oauth2/google_credentials.cc b/google/cloud/storage/oauth2/google_credentials.cc index 31f384f7543e2..357db5c71ac41 100644 --- a/google/cloud/storage/oauth2/google_credentials.cc +++ b/google/cloud/storage/oauth2/google_credentials.cc @@ -51,7 +51,7 @@ StatusOr> LoadCredsFromPath( std::string const& path, bool non_service_account_ok, absl::optional> service_account_scopes, absl::optional service_account_subject, - ChannelOptions const& options) { + Options const& options) { std::ifstream ifs(path); if (!ifs.is_open()) { // We use kUnknown here because we don't know if the file does not exist, or @@ -119,7 +119,7 @@ StatusOr> MaybeLoadCredsFromAdcPaths( bool non_service_account_ok, absl::optional> service_account_scopes, absl::optional service_account_subject, - ChannelOptions const& options = {}) { + Options const& options = {}) { // 1) Check if the GOOGLE_APPLICATION_CREDENTIALS environment variable is set. auto path = GoogleAdcFilePathFromEnvVarOrEmpty(); if (path.empty()) { @@ -146,7 +146,7 @@ StatusOr> MaybeLoadCredsFromAdcPaths( } StatusOr> GoogleDefaultCredentials( - ChannelOptions const& options) { + Options const& options) { // 1 and 2) Check if the GOOGLE_APPLICATION_CREDENTIALS environment variable // is set or if the gcloud ADC file exists. auto creds = MaybeLoadCredsFromAdcPaths(true, {}, {}, options); @@ -181,7 +181,7 @@ CreateAuthorizedUserCredentialsFromJsonFilePath(std::string const& path) { StatusOr> CreateAuthorizedUserCredentialsFromJsonContents(std::string const& contents, - ChannelOptions const& options) { + Options const& options) { auto info = ParseAuthorizedUserCredentials(contents, "memory"); if (!info) { return StatusOr>(info.status()); @@ -216,7 +216,7 @@ CreateServiceAccountCredentialsFromJsonFilePath(std::string const& path) { StatusOr> CreateServiceAccountCredentialsFromJsonFilePath( std::string const& path, absl::optional> scopes, - absl::optional subject, ChannelOptions const& options) { + absl::optional subject, Options const& options) { std::ifstream is(path); std::string contents(std::istreambuf_iterator{is}, {}); auto info = ParseServiceAccountCredentials(contents, path); @@ -234,7 +234,7 @@ CreateServiceAccountCredentialsFromJsonFilePath( StatusOr> CreateServiceAccountCredentialsFromP12FilePath( std::string const& path, absl::optional> scopes, - absl::optional subject, ChannelOptions const& options) { + absl::optional subject, Options const& options) { auto info = ParseServiceAccountP12File(path); if (!info) { return StatusOr>(info.status()); @@ -253,14 +253,14 @@ CreateServiceAccountCredentialsFromP12FilePath(std::string const& path) { } StatusOr> -CreateServiceAccountCredentialsFromDefaultPaths(ChannelOptions const& options) { +CreateServiceAccountCredentialsFromDefaultPaths(Options const& options) { return CreateServiceAccountCredentialsFromDefaultPaths({}, {}, options); } StatusOr> CreateServiceAccountCredentialsFromDefaultPaths( absl::optional> scopes, - absl::optional subject, ChannelOptions const& options) { + absl::optional subject, Options const& options) { auto creds = MaybeLoadCredsFromAdcPaths(false, std::move(scopes), std::move(subject), options); if (!creds) { @@ -280,7 +280,7 @@ CreateServiceAccountCredentialsFromDefaultPaths( StatusOr> CreateServiceAccountCredentialsFromJsonContents(std::string const& contents, - ChannelOptions const& options) { + Options const& options) { return CreateServiceAccountCredentialsFromJsonContents(contents, {}, {}, options); } @@ -288,7 +288,7 @@ CreateServiceAccountCredentialsFromJsonContents(std::string const& contents, StatusOr> CreateServiceAccountCredentialsFromJsonContents( std::string const& contents, absl::optional> scopes, - absl::optional subject, ChannelOptions const& options) { + absl::optional subject, Options const& options) { auto info = ParseServiceAccountCredentials(contents, "memory"); if (!info) { return StatusOr>(info.status()); diff --git a/google/cloud/storage/oauth2/google_credentials.h b/google/cloud/storage/oauth2/google_credentials.h index 6c31d7c1de493..dd891ac1acad6 100644 --- a/google/cloud/storage/oauth2/google_credentials.h +++ b/google/cloud/storage/oauth2/google_credentials.h @@ -15,10 +15,10 @@ #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OAUTH2_GOOGLE_CREDENTIALS_H #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OAUTH2_GOOGLE_CREDENTIALS_H -#include "google/cloud/storage/client_options.h" #include "google/cloud/storage/oauth2/credentials.h" #include "google/cloud/storage/version.h" #include "google/cloud/optional.h" +#include "google/cloud/options.h" #include "absl/types/optional.h" #include #include @@ -48,7 +48,7 @@ GOOGLE_CLOUD_CPP_DEPRECATED( "This function will be removed in v4.0.0 and later. Prefer using the " "unified credentials documented in @ref guac.") StatusOr> GoogleDefaultCredentials( - ChannelOptions const& options = {}); + Options const& options = {}); ///@{ /** @@ -93,8 +93,8 @@ GOOGLE_CLOUD_CPP_DEPRECATED( "This function will be removed in v4.0.0 and later. Prefer using the " "unified credentials documented in @ref guac.") StatusOr> -CreateAuthorizedUserCredentialsFromJsonContents( - std::string const& contents, ChannelOptions const& options = {}); +CreateAuthorizedUserCredentialsFromJsonContents(std::string const& contents, + Options const& options = {}); ///@{ /** @@ -197,7 +197,7 @@ GOOGLE_CLOUD_CPP_DEPRECATED( StatusOr> CreateServiceAccountCredentialsFromJsonFilePath( std::string const& path, absl::optional> scopes, - absl::optional subject, ChannelOptions const& options = {}); + absl::optional subject, Options const& options = {}); /** * Creates a ServiceAccountCredentials from a P12 file at the specified path. @@ -241,7 +241,7 @@ GOOGLE_CLOUD_CPP_DEPRECATED( StatusOr> CreateServiceAccountCredentialsFromP12FilePath( std::string const& path, absl::optional> scopes, - absl::optional subject, ChannelOptions const& options = {}); + absl::optional subject, Options const& options = {}); ///@} /** @@ -265,8 +265,7 @@ GOOGLE_CLOUD_CPP_DEPRECATED( "This function will be removed in v4.0.0 and later. Prefer using the " "unified credentials documented in @ref guac.") StatusOr> -CreateServiceAccountCredentialsFromDefaultPaths( - ChannelOptions const& options = {}); +CreateServiceAccountCredentialsFromDefaultPaths(Options const& options = {}); /** * Produces a ServiceAccountCredentials type by trying to load the standard @@ -300,7 +299,7 @@ GOOGLE_CLOUD_CPP_DEPRECATED( StatusOr> CreateServiceAccountCredentialsFromDefaultPaths( absl::optional> scopes, - absl::optional subject, ChannelOptions const& options = {}); + absl::optional subject, Options const& options = {}); /** * Creates a ServiceAccountCredentials from a JSON string. @@ -315,8 +314,8 @@ GOOGLE_CLOUD_CPP_DEPRECATED( "This function will be removed in v4.0.0 and later. Prefer using the " "unified credentials documented in @ref guac.") StatusOr> -CreateServiceAccountCredentialsFromJsonContents( - std::string const& contents, ChannelOptions const& options = {}); +CreateServiceAccountCredentialsFromJsonContents(std::string const& contents, + Options const& options = {}); /** * Creates a ServiceAccountCredentials from a JSON string. @@ -346,7 +345,7 @@ GOOGLE_CLOUD_CPP_DEPRECATED( StatusOr> CreateServiceAccountCredentialsFromJsonContents( std::string const& contents, absl::optional> scopes, - absl::optional subject, ChannelOptions const& options = {}); + absl::optional subject, Options const& options = {}); /** * Creates a ComputeEngineCredentials for the VM's default service account. diff --git a/google/cloud/storage/oauth2/service_account_credentials.cc b/google/cloud/storage/oauth2/service_account_credentials.cc index 248152e8b64ad..963a6ca62ab01 100644 --- a/google/cloud/storage/oauth2/service_account_credentials.cc +++ b/google/cloud/storage/oauth2/service_account_credentials.cc @@ -125,12 +125,11 @@ bool ServiceAccountUseOAuth(ServiceAccountCredentialsInfo const& info) { ServiceAccountCredentials:: ServiceAccountCredentials(ServiceAccountCredentialsInfo info, - ChannelOptions const& options) + Options options) : impl_(std::make_unique( std::make_unique( internal::MapServiceAccountCredentialsInfo(std::move(info)), - Options{}.set(options.ssl_root_path()), - [](Options const& o) { + std::move(options), [](Options const& o) { return rest_internal::MakeDefaultRestClient(std::string{}, o); }))) {} diff --git a/google/cloud/storage/oauth2/service_account_credentials.h b/google/cloud/storage/oauth2/service_account_credentials.h index cdf1b56f8e5e3..9bc28128beee8 100644 --- a/google/cloud/storage/oauth2/service_account_credentials.h +++ b/google/cloud/storage/oauth2/service_account_credentials.h @@ -15,7 +15,6 @@ #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OAUTH2_SERVICE_ACCOUNT_CREDENTIALS_H #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OAUTH2_SERVICE_ACCOUNT_CREDENTIALS_H -#include "google/cloud/storage/client_options.h" #include "google/cloud/storage/internal/base64.h" #include "google/cloud/storage/internal/curl/request_builder.h" #include "google/cloud/storage/internal/http_response.h" @@ -30,6 +29,7 @@ #include "google/cloud/internal/sha256_hash.h" #include "google/cloud/internal/sign_using_sha256.h" #include "google/cloud/optional.h" +#include "google/cloud/options.h" #include "google/cloud/status_or.h" #include "absl/types/optional.h" #include @@ -246,7 +246,7 @@ class GOOGLE_CLOUD_CPP_DEPRECATED( explicit ServiceAccountCredentials(ServiceAccountCredentialsInfo info) : ServiceAccountCredentials(std::move(info), {}) {} ServiceAccountCredentials(ServiceAccountCredentialsInfo info, - ChannelOptions const& options); + Options options); StatusOr AuthorizationHeader() override { return oauth2_internal::AuthenticationHeaderJoined(*impl_); @@ -295,11 +295,8 @@ class GOOGLE_CLOUD_CPP_DEPRECATED( public: explicit ServiceAccountCredentials(ServiceAccountCredentialsInfo info) : ServiceAccountCredentials(std::move(info), {}) {} - ServiceAccountCredentials(ServiceAccountCredentialsInfo info, - ChannelOptions const& options) - : info_(std::move(info)), - options_(Options{}.set(options.ssl_root_path())), - clock_() {} + ServiceAccountCredentials(ServiceAccountCredentialsInfo info, Options options) + : info_(std::move(info)), options_(std::move(options)), clock_() {} StatusOr AuthorizationHeader() override { std::unique_lock lock(mu_); diff --git a/google/cloud/storage/oauth2/service_account_credentials_test.cc b/google/cloud/storage/oauth2/service_account_credentials_test.cc index e0dbfececf785..948095d24e30f 100644 --- a/google/cloud/storage/oauth2/service_account_credentials_test.cc +++ b/google/cloud/storage/oauth2/service_account_credentials_test.cc @@ -18,6 +18,8 @@ #include "google/cloud/storage/testing/constants.h" #include "google/cloud/storage/testing/mock_http_request.h" #include "google/cloud/storage/testing/write_base64.h" +#include "google/cloud/common_options.h" +#include "google/cloud/credentials.h" #include "google/cloud/internal/base64_transforms.h" #include "google/cloud/internal/filesystem.h" #include "google/cloud/internal/random.h" @@ -389,7 +391,7 @@ TEST_F(ServiceAccountCredentialsTest, UsesCARootsInfo) { }); ServiceAccountCredentials credentials( - *info, ChannelOptions().set_ssl_root_path(cainfo)); + *info, Options{}.set(cainfo)); // Call Refresh to obtain the access token for our authorization header. auto authorization_header = credentials.AuthorizationHeader(); ASSERT_STATUS_OK(authorization_header); diff --git a/google/cloud/storage/testing/client_unit_test.cc b/google/cloud/storage/testing/client_unit_test.cc index 66a2cb45f389a..b7c828a523d22 100644 --- a/google/cloud/storage/testing/client_unit_test.cc +++ b/google/cloud/storage/testing/client_unit_test.cc @@ -21,13 +21,9 @@ namespace storage { namespace testing { using ::testing::Return; -using ::testing::ReturnRef; ClientUnitTest::ClientUnitTest() - : mock_(std::make_shared()), - client_options_(ClientOptions(oauth2::CreateAnonymousCredentials())) { - EXPECT_CALL(*mock_, client_options()) - .WillRepeatedly(ReturnRef(client_options_)); + : mock_(std::make_shared()) { EXPECT_CALL(*mock_, options) .WillRepeatedly(Return(storage::internal::DefaultOptionsWithCredentials( Options{} diff --git a/google/cloud/storage/testing/client_unit_test.h b/google/cloud/storage/testing/client_unit_test.h index 5cb34074af098..17734caf5b2e1 100644 --- a/google/cloud/storage/testing/client_unit_test.h +++ b/google/cloud/storage/testing/client_unit_test.h @@ -34,7 +34,6 @@ class ClientUnitTest : public ::testing::Test { google::cloud::storage::Client ClientForMock(); std::shared_ptr mock_; - ClientOptions client_options_; }; } // namespace testing diff --git a/google/cloud/storage/testing/mock_client.h b/google/cloud/storage/testing/mock_client.h index 0c4161f9d3343..0f63951d28920 100644 --- a/google/cloud/storage/testing/mock_client.h +++ b/google/cloud/storage/testing/mock_client.h @@ -31,11 +31,7 @@ namespace testing { class MockClient : public google::cloud::storage::internal::StorageConnection { public: - MockClient() - : client_options_( - google::cloud::storage::oauth2::CreateAnonymousCredentials()) { - EXPECT_CALL(*this, client_options()) - .WillRepeatedly(::testing::ReturnRef(client_options_)); + MockClient() { EXPECT_CALL(*this, options) .WillRepeatedly( ::testing::Return(storage::internal::DefaultOptionsWithCredentials( @@ -43,7 +39,6 @@ class MockClient : public google::cloud::storage::internal::StorageConnection { MakeInsecureCredentials())))); } - MOCK_METHOD(ClientOptions const&, client_options, (), (const, override)); MOCK_METHOD(Options, options, (), (const, override)); MOCK_METHOD(StatusOr, ListBuckets, (internal::ListBucketsRequest const&), (override)); @@ -187,9 +182,6 @@ class MockClient : public google::cloud::storage::internal::StorageConnection { MOCK_METHOD(std::vector, InspectStackStructure, (), (const, override)); - - private: - ClientOptions client_options_; }; class MockObjectReadSource : public internal::ObjectReadSource { diff --git a/google/cloud/storage/tests/create_client_integration_test.cc b/google/cloud/storage/tests/create_client_integration_test.cc index 1af30e631c788..fafdeedebd5fb 100644 --- a/google/cloud/storage/tests/create_client_integration_test.cc +++ b/google/cloud/storage/tests/create_client_integration_test.cc @@ -66,10 +66,9 @@ class CreateClientIntegrationTest #include "google/cloud/internal/disable_deprecation_warnings.inc" TEST_F(CreateClientIntegrationTest, DefaultWorks) { - auto client = Client::CreateDefaultClient(); - ASSERT_THAT(client, IsOk()); + auto client = Client(Options{}); ASSERT_NO_FATAL_FAILURE( - UseClient(*client, bucket_name(), MakeRandomObjectName(), LoremIpsum())); + UseClient(client, bucket_name(), MakeRandomObjectName(), LoremIpsum())); } TEST_F(CreateClientIntegrationTest, SettingPolicies) { @@ -79,24 +78,20 @@ TEST_F(CreateClientIntegrationTest, SettingPolicies) { ASSERT_THAT(c, IsOk()); credentials = *std::move(c); } - auto client = - Client(ClientOptions(std::move(credentials)), - LimitedErrorCountRetryPolicy(/*maximum_failures=*/5), - ExponentialBackoffPolicy(/*initial_delay=*/std::chrono::seconds(1), - /*maximum_delay=*/std::chrono::minutes(5), - /*scaling=*/1.5)); + auto client = Client( + Options{} + .set( + LimitedErrorCountRetryPolicy(/*maximum_failures=*/5).clone()) + .set( + ExponentialBackoffPolicy( + /*initial_delay=*/std::chrono::seconds(1), + /*maximum_delay=*/std::chrono::minutes(5), + /*scaling=*/1.5) + .clone())); ASSERT_NO_FATAL_FAILURE( UseClient(client, bucket_name(), MakeRandomObjectName(), LoremIpsum())); } -/// @test Verify the backwards compatibility `v1` namespace still exists. -TEST_F(CreateClientIntegrationTest, BackwardsCompatibility) { - auto client = ::google::cloud::storage::v1::Client::CreateDefaultClient(); - ASSERT_THAT(client, IsOk()); - ASSERT_NO_FATAL_FAILURE( - UseClient(*client, bucket_name(), MakeRandomObjectName(), LoremIpsum())); -} - } // namespace GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END } // namespace storage diff --git a/google/cloud/storage/tests/object_media_integration_test.cc b/google/cloud/storage/tests/object_media_integration_test.cc index 604bffe1364d6..5250461ee1d24 100644 --- a/google/cloud/storage/tests/object_media_integration_test.cc +++ b/google/cloud/storage/tests/object_media_integration_test.cc @@ -515,9 +515,6 @@ TEST_F(ObjectMediaIntegrationTest, ConnectionFailureUploadFile) { TEST_F(ObjectMediaIntegrationTest, StreamingReadTimeout) { // The emulator does not support this type of fault injection for gRPC. if (!UsingEmulator() || UsingGrpc()) GTEST_SKIP(); - auto options = ClientOptions::CreateDefaultClientOptions(); - ASSERT_STATUS_OK(options); - auto client = MakeIntegrationTestClient( Options{} .set(std::chrono::seconds(3))