Skip to content

Commit 9d3526d

Browse files
committed
impl(storage): remove deprecated ClientOptions class
1 parent d0db317 commit 9d3526d

31 files changed

+110
-919
lines changed

google/cloud/storage/client.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ Client::Client(InternalOnly, Options const& opts)
6060
: Client(InternalOnlyNoDecorations{},
6161
storage_internal::MakeStorageConnection(opts)) {}
6262

63-
StatusOr<Client> Client::CreateDefaultClient() { return Client(Options{}); }
64-
6563
ObjectReadStream Client::ReadObjectImpl(
6664
internal::ReadObjectRangeRequest const& request) {
6765
auto source = connection_->ReadObject(request);
@@ -235,12 +233,12 @@ std::string Client::SigningEmail(SigningAccount const& signing_account) const {
235233
if (signing_account.has_value()) {
236234
return signing_account.value();
237235
}
238-
return connection_->client_options().credentials()->AccountEmail();
236+
return connection_->options().get<Oauth2CredentialsOption>()->AccountEmail();
239237
}
240238

241239
StatusOr<Client::SignBlobResponseRaw> Client::SignBlobImpl(
242240
SigningAccount const& signing_account, std::string const& string_to_sign) {
243-
auto credentials = connection_->client_options().credentials();
241+
auto credentials = connection_->options().get<Oauth2CredentialsOption>();
244242

245243
// First try to sign locally.
246244
auto signed_blob = credentials->SignBlob(signing_account, string_to_sign);

google/cloud/storage/client.h

Lines changed: 15 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_CLIENT_H
1616
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_CLIENT_H
1717

18+
#include "google/cloud/storage/client_options.h"
1819
#include "google/cloud/storage/hmac_key_metadata.h"
1920
#include "google/cloud/storage/internal/policy_document_request.h"
2021
#include "google/cloud/storage/internal/request_project_id.h"
@@ -3421,79 +3422,6 @@ class Client {
34213422
}
34223423
///@}
34233424

3424-
/**
3425-
* Creates the default client type given the options.
3426-
*
3427-
* @param options the client options, these are used to control credentials,
3428-
* buffer sizes, etc.
3429-
* @param policies the client policies, these control the behavior of the
3430-
* client, for example, how to backoff when an operation needs to be
3431-
* retried, or what operations cannot be retried because they are not
3432-
* idempotent.
3433-
*
3434-
* @deprecated use the constructor from `google::cloud::Options` instead.
3435-
*/
3436-
template <typename... Policies>
3437-
explicit Client(ClientOptions options, Policies&&... policies)
3438-
: Client(InternalOnly{}, internal::ApplyPolicies(
3439-
internal::MakeOptions(std::move(options)),
3440-
std::forward<Policies>(policies)...)) {}
3441-
3442-
/**
3443-
* Creates the default client type given the credentials and policies.
3444-
*
3445-
* @param credentials a set of credentials to initialize the `ClientOptions`.
3446-
* @param policies the client policies, these control the behavior of the
3447-
* client, for example, how to backoff when an operation needs to be
3448-
* retried, or what operations cannot be retried because they are not
3449-
* idempotent.
3450-
*
3451-
* @deprecated use the constructor from `google::cloud::Options` instead.
3452-
*/
3453-
template <typename... Policies>
3454-
explicit Client(std::shared_ptr<oauth2::Credentials> credentials,
3455-
Policies&&... policies)
3456-
: Client(InternalOnly{},
3457-
internal::ApplyPolicies(
3458-
internal::DefaultOptions(std::move(credentials), {}),
3459-
std::forward<Policies>(policies)...)) {}
3460-
3461-
/**
3462-
* Create a Client using ClientOptions::CreateDefaultClientOptions().
3463-
*
3464-
* @deprecated use the constructor from `google::cloud::Options` instead.
3465-
*/
3466-
static StatusOr<Client> CreateDefaultClient();
3467-
3468-
/// Builds a client and maybe override the retry, idempotency, and/or backoff
3469-
/// policies.
3470-
/// @deprecated This was intended only for test code, applications should not
3471-
/// use it.
3472-
template <typename... Policies>
3473-
#if !defined(_MSC_VER) || _MSC_VER >= 1920
3474-
GOOGLE_CLOUD_CPP_DEPRECATED(
3475-
"applications should not need this."
3476-
" Please use the constructors from ClientOptions instead."
3477-
" For mocking, please use testing::ClientFromMock() instead."
3478-
" Please file a bug at https://github.com/googleapis/google-cloud-cpp"
3479-
" if you have a use-case not covered by these.")
3480-
#endif // _MSC_VER
3481-
// We cannot `std::move(connection)` because it is used twice in the delegated
3482-
// constructor parameters. And we cannot just use `StorageConnection const&`
3483-
// because we do hold on to the `std::shared_ptr<>`.
3484-
explicit Client(
3485-
std::shared_ptr<internal::StorageConnection> const& connection,
3486-
Policies&&... policies)
3487-
: Client(InternalOnly{},
3488-
internal::ApplyPolicies(
3489-
internal::DefaultOptions(
3490-
connection->client_options().credentials(), {}),
3491-
std::forward<Policies>(policies)...),
3492-
// We cannot std::move() because it is also used in the previous
3493-
// parameter.
3494-
connection) {
3495-
}
3496-
34973425
/// Define a tag to disable automatic decorations of the StorageConnection.
34983426
struct NoDecorations {};
34993427

@@ -3675,8 +3603,20 @@ struct ClientImplDetails {
36753603
// NOLINTNEXTLINE(performance-unnecessary-value-param)
36763604
static Client CreateClient(std::shared_ptr<StorageConnection> c,
36773605
Policies&&... p) {
3678-
auto opts =
3679-
internal::ApplyPolicies(c->options(), std::forward<Policies>(p)...);
3606+
struct ApplyPoliciesHelper {
3607+
Options& opts;
3608+
void operator()(RetryPolicy const& p) {
3609+
opts.set<RetryPolicyOption>(p.clone());
3610+
}
3611+
void operator()(BackoffPolicy const& p) {
3612+
opts.set<BackoffPolicyOption>(p.clone());
3613+
}
3614+
void operator()(IdempotencyPolicy const& p) {
3615+
opts.set<IdempotencyPolicyOption>(p.clone());
3616+
}
3617+
};
3618+
auto opts = c->options();
3619+
(ApplyPoliciesHelper{opts}(std::forward<Policies>(p)), ...);
36803620
return CreateWithDecorations(opts, std::move(c));
36813621
}
36823622
};

google/cloud/storage/client_bucket_test.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ TEST_F(BucketTest, CreateBucket) {
197197
})""";
198198
auto expected = internal::BucketMetadataParser::FromString(text).value();
199199

200-
EXPECT_CALL(*mock_, client_options()).Times(0);
201200
EXPECT_CALL(*mock_, CreateBucket)
202201
.WillOnce(Return(StatusOr<BucketMetadata>(TransientError())))
203202
.WillOnce([&expected](internal::CreateBucketRequest const& r) {

google/cloud/storage/client_options.cc

Lines changed: 2 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ absl::optional<std::string> GetEmulator() {
5151
}
5252

5353
StatusOr<std::shared_ptr<oauth2::Credentials>> StorageDefaultCredentials(
54-
ChannelOptions const& channel_options) {
54+
Options const& options) {
5555
auto emulator = GetEmulator();
5656
if (emulator.has_value()) {
5757
return StatusOr<std::shared_ptr<oauth2::Credentials>>(
5858
oauth2::CreateAnonymousCredentials());
5959
}
60-
return oauth2::GoogleDefaultCredentials(channel_options);
60+
return oauth2::GoogleDefaultCredentials(options);
6161
}
6262

6363
std::size_t DefaultConnectionPoolSize() {
@@ -146,18 +146,6 @@ std::string IamEndpoint(Options const& options) {
146146
return options.get<IamEndpointOption>();
147147
}
148148

149-
Options MakeOptions(ClientOptions o) {
150-
auto opts = std::move(o.opts_);
151-
if (!o.channel_options().ssl_root_path().empty()) {
152-
opts.set<CARootsFilePathOption>(o.channel_options().ssl_root_path());
153-
}
154-
return opts;
155-
}
156-
157-
ClientOptions MakeBackwardsCompatibleClientOptions(Options opts) {
158-
return ClientOptions(std::move(opts));
159-
}
160-
161149
Options ApplyPolicy(Options opts, RetryPolicy const& p) {
162150
opts.set<RetryPolicyOption>(p.clone());
163151
return opts;
@@ -311,67 +299,6 @@ Options DefaultOptionsWithCredentials(Options opts) {
311299

312300
} // namespace internal
313301

314-
StatusOr<ClientOptions> ClientOptions::CreateDefaultClientOptions() {
315-
return CreateDefaultClientOptions(ChannelOptions{});
316-
}
317-
318-
StatusOr<ClientOptions> ClientOptions::CreateDefaultClientOptions(
319-
ChannelOptions const& channel_options) {
320-
auto creds = StorageDefaultCredentials(channel_options);
321-
if (!creds) return creds.status();
322-
return ClientOptions(*creds, channel_options);
323-
}
324-
325-
ClientOptions::ClientOptions(std::shared_ptr<oauth2::Credentials> credentials,
326-
ChannelOptions channel_options)
327-
: opts_(internal::DefaultOptions(std::move(credentials), {})),
328-
channel_options_(std::move(channel_options)) {}
329-
330-
ClientOptions::ClientOptions(Options o)
331-
: opts_(std::move(o)),
332-
user_agent_prefix_(
333-
absl::StrJoin(opts_.get<UserAgentProductsOption>(), " ")) {
334-
channel_options_.set_ssl_root_path(opts_.get<CARootsFilePathOption>());
335-
}
336-
337-
bool ClientOptions::enable_http_tracing() const {
338-
return opts_.get<LoggingComponentsOption>().count("http") != 0;
339-
}
340-
341-
ClientOptions& ClientOptions::set_enable_http_tracing(bool enable) {
342-
if (enable) {
343-
opts_.lookup<LoggingComponentsOption>().insert("http");
344-
} else {
345-
opts_.lookup<LoggingComponentsOption>().erase("http");
346-
}
347-
return *this;
348-
}
349-
350-
bool ClientOptions::enable_raw_client_tracing() const {
351-
return opts_.get<LoggingComponentsOption>().count("raw-client") != 0;
352-
}
353-
354-
ClientOptions& ClientOptions::set_enable_raw_client_tracing(bool enable) {
355-
if (enable) {
356-
opts_.lookup<LoggingComponentsOption>().insert("raw-client");
357-
} else {
358-
opts_.lookup<LoggingComponentsOption>().erase("raw-client");
359-
}
360-
return *this;
361-
}
362-
363-
ClientOptions& ClientOptions::SetDownloadBufferSize(std::size_t size) {
364-
opts_.set<DownloadBufferSizeOption>(
365-
size == 0 ? GOOGLE_CLOUD_CPP_STORAGE_DEFAULT_DOWNLOAD_BUFFER_SIZE : size);
366-
return *this;
367-
}
368-
369-
ClientOptions& ClientOptions::SetUploadBufferSize(std::size_t size) {
370-
opts_.set<UploadBufferSizeOption>(
371-
size == 0 ? GOOGLE_CLOUD_CPP_STORAGE_DEFAULT_UPLOAD_BUFFER_SIZE : size);
372-
return *this;
373-
}
374-
375302
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
376303
} // namespace storage
377304
} // namespace cloud

0 commit comments

Comments
 (0)