|
21 | 21 | #include "google/cloud/storage/internal/signed_url_requests.h" |
22 | 22 | #include "google/cloud/storage/internal/storage_connection.h" |
23 | 23 | #include "google/cloud/storage/internal/tuple_filter.h" |
| 24 | +#include "google/cloud/storage/list_buckets_partial_reader.h" |
24 | 25 | #include "google/cloud/storage/list_buckets_reader.h" |
25 | 26 | #include "google/cloud/storage/list_hmac_keys_reader.h" |
26 | 27 | #include "google/cloud/storage/list_objects_and_prefixes_reader.h" |
@@ -366,6 +367,56 @@ class Client { |
366 | 367 | std::forward<Options>(options)...); |
367 | 368 | } |
368 | 369 |
|
| 370 | + /** |
| 371 | + * Fetches the list of buckets and unreachable resources for the default |
| 372 | + * project. |
| 373 | + * |
| 374 | + * This function will return an error if it cannot determine the "default" |
| 375 | + * project. The default project is found by looking, in order, for: |
| 376 | + * - Any parameters of type `OverrideDefaultProject`, with a value. |
| 377 | + * - Any `google::cloud::storage::ProjectIdOption` value in any parameters of |
| 378 | + * type `google::cloud::Options{}`. |
| 379 | + * - Any `google::cloud::storage::ProjectIdOption` value provided in the |
| 380 | + * `google::cloud::Options{}` passed to the constructor. |
| 381 | + * - The value from the `GOOGLE_CLOUD_PROJECT` environment variable. |
| 382 | + * |
| 383 | + * @param options a list of optional query parameters and/or request headers. |
| 384 | + * Valid types for this operation include `MaxResults`, `Prefix`, |
| 385 | + * `Projection`, `UserProject`, `OverrideDefaultProject`, and |
| 386 | + * `ReturnPartialSuccess`. |
| 387 | + * |
| 388 | + * @par Idempotency |
| 389 | + * This is a read-only operation and is always idempotent. |
| 390 | + * |
| 391 | + * @par Example |
| 392 | + * @snippet storage_bucket_samples.cc list buckets partial result |
| 393 | + */ |
| 394 | + template <typename... Options> |
| 395 | + ListBucketsPartialReader ListBucketsPartial(Options&&... options) { |
| 396 | + auto opts = SpanOptions(std::forward<Options>(options)...); |
| 397 | + auto project_id = storage_internal::RequestProjectId( |
| 398 | + GCP_ERROR_INFO(), opts, std::forward<Options>(options)...); |
| 399 | + if (!project_id) { |
| 400 | + return google::cloud::internal::MakeErrorPaginationRange< |
| 401 | + ListBucketsPartialReader>(std::move(project_id).status()); |
| 402 | + } |
| 403 | + google::cloud::internal::OptionsSpan const span(std::move(opts)); |
| 404 | + |
| 405 | + internal::ListBucketsRequest request(*std::move(project_id)); |
| 406 | + request.set_multiple_options(std::forward<Options>(options)...); |
| 407 | + auto& client = connection_; |
| 408 | + return google::cloud::internal::MakePaginationRange< |
| 409 | + ListBucketsPartialReader>( |
| 410 | + request, |
| 411 | + [client](internal::ListBucketsRequest const& r) { |
| 412 | + return client->ListBuckets(r); |
| 413 | + }, |
| 414 | + [](internal::ListBucketsResponse r) { |
| 415 | + return std::vector<BucketsPartial>{ |
| 416 | + BucketsPartial{std::move(r.items), std::move(r.unreachable)}}; |
| 417 | + }); |
| 418 | + } |
| 419 | + |
369 | 420 | /** |
370 | 421 | * Creates a new Google Cloud Storage bucket using the default project. |
371 | 422 | * |
|
0 commit comments