Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
146 changes: 146 additions & 0 deletions doc/v3-migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,149 @@ auto limit = google::cloud::bigtable::RowReader::NO_ROWS_LIMIT;
### Spanner

### Storage

<details>
<summary><code>ClientOptions</code> is removed</summary>

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<google::cloud::Oauth2CredentialsOption>(credentials)
.set<google::cloud::storage::ProjectIdOption>("my-project")
.set<google::cloud::storage::UploadBufferSizeOption>(1024 * 1024));
}
```

Use the following table to map `ClientOptions` setters to
`google::cloud::Options`:

| `ClientOptions` Method | Replacement Option (`.set<T>(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<LoggingComponentsOption>().insert("raw-client");
```

</details>

<details>
<summary><code>ChannelOptions</code> is removed</summary>

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<google::cloud::CARootsFilePathOption>(
"path/to/roots.pem"));
}
```

</details>

<details>
<summary>ChannelOptions Mapping</summary>

Use the following table to map `ChannelOptions` setters to
`google::cloud::Options`:

| `ChannelOptions` Method | Replacement Option (`.set<T>(value)`) |
| :---------------------- | :------------------------------------- |
| `set_ssl_root_path(p)` | `google::cloud::CARootsFilePathOption` |

</details>

<details>
<summary><code>Client</code> Constructor</summary>

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<google::cloud::storage::Oauth2CredentialsOption>(credentials));
}
```

</details>
6 changes: 2 additions & 4 deletions google/cloud/storage/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ Client::Client(InternalOnly, Options const& opts)
: Client(InternalOnlyNoDecorations{},
storage_internal::MakeStorageConnection(opts)) {}

StatusOr<Client> Client::CreateDefaultClient() { return Client(Options{}); }

ObjectReadStream Client::ReadObjectImpl(
internal::ReadObjectRangeRequest const& request) {
auto source = connection_->ReadObject(request);
Expand Down Expand Up @@ -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<Oauth2CredentialsOption>()->AccountEmail();
}

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

// First try to sign locally.
auto signed_blob = credentials->SignBlob(signing_account, string_to_sign);
Expand Down
74 changes: 1 addition & 73 deletions google/cloud/storage/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 <typename... Policies>
explicit Client(ClientOptions options, Policies&&... policies)
: Client(InternalOnly{}, internal::ApplyPolicies(
internal::MakeOptions(std::move(options)),
std::forward<Policies>(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 <typename... Policies>
explicit Client(std::shared_ptr<oauth2::Credentials> credentials,
Policies&&... policies)
: Client(InternalOnly{},
internal::ApplyPolicies(
internal::DefaultOptions(std::move(credentials), {}),
std::forward<Policies>(policies)...)) {}

/**
* Create a Client using ClientOptions::CreateDefaultClientOptions().
*
* @deprecated use the constructor from `google::cloud::Options` instead.
*/
static StatusOr<Client> 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 <typename... Policies>
#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<internal::StorageConnection> const& connection,
Policies&&... policies)
: Client(InternalOnly{},
internal::ApplyPolicies(
internal::DefaultOptions(
connection->client_options().credentials(), {}),
std::forward<Policies>(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 {};

Expand Down
1 change: 0 additions & 1 deletion google/cloud/storage/client_bucket_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<BucketMetadata>(TransientError())))
.WillOnce([&expected](internal::CreateBucketRequest const& r) {
Expand Down
Loading