15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_CLIENT_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_CLIENT_H
18 #include "google/cloud/storage/hmac_key_metadata.h"
19 #include "google/cloud/storage/internal/group_options.h"
20 #include "google/cloud/storage/internal/logging_client.h"
21 #include "google/cloud/storage/internal/parameter_pack_validation.h"
22 #include "google/cloud/storage/internal/policy_document_request.h"
23 #include "google/cloud/storage/internal/retry_client.h"
24 #include "google/cloud/storage/internal/signed_url_requests.h"
25 #include "google/cloud/storage/internal/tuple_filter.h"
26 #include "google/cloud/storage/list_buckets_reader.h"
27 #include "google/cloud/storage/list_hmac_keys_reader.h"
28 #include "google/cloud/storage/list_objects_and_prefixes_reader.h"
29 #include "google/cloud/storage/list_objects_reader.h"
30 #include "google/cloud/storage/notification_event_type.h"
31 #include "google/cloud/storage/notification_payload_format.h"
32 #include "google/cloud/storage/oauth2/google_credentials.h"
33 #include "google/cloud/storage/object_rewriter.h"
34 #include "google/cloud/storage/object_stream.h"
35 #include "google/cloud/storage/retry_policy.h"
36 #include "google/cloud/storage/upload_options.h"
37 #include "google/cloud/storage/version.h"
38 #include "google/cloud/internal/throw_delegate.h"
39 #include "google/cloud/options.h"
40 #include "google/cloud/status.h"
41 #include "google/cloud/status_or.h"
42 #include "absl/meta/type_traits.h"
44 #include <type_traits>
52 class NonResumableParallelUploadState;
53 class ResumableParallelUploadState;
54 struct ClientImplDetails;
284 return a.raw_client_ == b.raw_client_;
315 template <
typename... Options>
317 Options&&... options) {
319 SpanOptions(std::forward<Options>(options)...));
320 internal::ListBucketsRequest request(project_id);
321 request.set_multiple_options(std::forward<Options>(options)...);
322 auto& client = raw_client_;
323 return google::
cloud::internal::MakePaginationRange<ListBucketsReader>(
325 [client](internal::ListBucketsRequest
const& r) {
326 return client->ListBuckets(r);
328 [](internal::ListBucketsResponse r) {
return std::move(r.items); });
351 template <
typename... Options>
354 SpanOptions(std::forward<Options>(options)...));
355 auto const& project_id = raw_client_->client_options()
.project_id();
356 return ListBucketsForProject(project_id, std::forward<Options>(options)...);
386 template <
typename... Options>
389 Options&&... options) {
390 auto const& project_id = raw_client_->client_options()
.project_id();
391 return CreateBucketForProject(std::move(bucket_name), project_id,
393 std::forward<Options>(options)...);
422 template <
typename... Options>
424 std::string project_id,
426 Options&&... options) {
428 SpanOptions(std::forward<Options>(options)...));
430 internal::CreateBucketRequest request(std::move(project_id),
431 std::move(metadata));
432 request.set_multiple_options(std::forward<Options>(options)...);
433 return raw_client_->CreateBucket(request);
450 template <
typename... Options>
452 Options&&... options) {
454 SpanOptions(std::forward<Options>(options)...));
455 internal::GetBucketMetadataRequest request(bucket_name);
456 request.set_multiple_options(std::forward<Options>(options)...);
457 return raw_client_->GetBucketMetadata(request);
475 template <
typename... Options>
478 SpanOptions(std::forward<Options>(options)...));
479 internal::DeleteBucketRequest request(bucket_name);
480 request.set_multiple_options(std::forward<Options>(options)...);
481 return raw_client_->DeleteBucket(request)
.status();
517 template <
typename... Options>
520 Options&&... options) {
522 SpanOptions(std::forward<Options>(options)...));
524 internal::UpdateBucketRequest request(std::move(metadata));
525 request.set_multiple_options(std::forward<Options>(options)...);
526 return raw_client_->UpdateBucket(request);
567 template <
typename... Options>
571 Options&&... options) {
573 SpanOptions(std::forward<Options>(options)...));
574 internal::PatchBucketRequest request(std::move(bucket_name), original,
576 request.set_multiple_options(std::forward<Options>(options)...);
577 return raw_client_->PatchBucket(request);
613 template <
typename... Options>
616 Options&&... options) {
618 SpanOptions(std::forward<Options>(options)...));
619 internal::PatchBucketRequest request(std::move(bucket_name), builder);
620 request.set_multiple_options(std::forward<Options>(options)...);
621 return raw_client_->PatchBucket(request);
657 template <
typename... Options>
659 std::string
const& bucket_name, Options&&... options) {
661 SpanOptions(std::forward<Options>(options)...));
662 internal::GetBucketIamPolicyRequest request(bucket_name);
663 request.set_multiple_options(std::forward<Options>(options)...);
664 return raw_client_->GetNativeBucketIamPolicy(request);
713 template <
typename... Options>
716 Options&&... options) {
718 SpanOptions(std::forward<Options>(options)...));
719 internal::SetNativeBucketIamPolicyRequest request(bucket_name, iam_policy);
720 request.set_multiple_options(std::forward<Options>(options)...);
721 return raw_client_->SetNativeBucketIamPolicy(request);
751 template <
typename... Options>
753 std::string bucket_name, std::vector<std::string> permissions,
754 Options&&... options) {
756 SpanOptions(std::forward<Options>(options)...));
757 internal::TestBucketIamPermissionsRequest request(std::move(bucket_name),
758 std::move(permissions));
759 request.set_multiple_options(std::forward<Options>(options)...);
760 auto result = raw_client_->TestBucketIamPermissions(request);
764 return std::move(result
.value().permissions);
813 template <
typename... Options>
815 std::string
const& bucket_name, std::uint64_t metageneration,
816 Options&&... options) {
818 SpanOptions(std::forward<Options>(options)...));
819 internal::LockBucketRetentionPolicyRequest request(bucket_name,
821 request.set_multiple_options(std::forward<Options>(options)...);
822 return raw_client_->LockBucketRetentionPolicy(request);
863 template <
typename... Options>
865 std::string
const& object_name,
866 std::string contents,
867 Options&&... options) {
869 SpanOptions(std::forward<Options>(options)...));
870 internal::InsertObjectMediaRequest request(bucket_name, object_name,
871 std::move(contents));
872 request.set_multiple_options(std::forward<Options>(options)...);
873 return raw_client_->InsertObjectMedia(request);
916 template <
typename... Options>
918 std::string source_object_name,
919 std::string destination_bucket_name,
920 std::string destination_object_name,
921 Options&&... options) {
923 SpanOptions(std::forward<Options>(options)...));
924 internal::CopyObjectRequest request(
925 std::move(source_bucket_name), std::move(source_object_name),
926 std::move(destination_bucket_name), std::move(destination_object_name));
927 request.set_multiple_options(std::forward<Options>(options)...);
928 return raw_client_->CopyObject(request);
947 template <
typename... Options>
949 std::string
const& object_name,
950 Options&&... options) {
952 SpanOptions(std::forward<Options>(options)...));
953 internal::GetObjectMetadataRequest request(bucket_name, object_name);
954 request.set_multiple_options(std::forward<Options>(options)...);
955 return raw_client_->GetObjectMetadata(request);
973 template <
typename... Options>
975 Options&&... options) {
977 SpanOptions(std::forward<Options>(options)...));
978 internal::ListObjectsRequest request(bucket_name);
979 request.set_multiple_options(std::forward<Options>(options)...);
980 auto& client = raw_client_;
981 return google::
cloud::internal::MakePaginationRange<ListObjectsReader>(
983 [client](internal::ListObjectsRequest
const& r) {
984 return client->ListObjects(r);
986 [](internal::ListObjectsResponse r) {
return std::move(r.items); });
1005 template <
typename... Options>
1007 std::string
const& bucket_name, Options&&... options) {
1009 SpanOptions(std::forward<Options>(options)...));
1010 internal::ListObjectsRequest request(bucket_name);
1011 request.set_multiple_options(std::forward<Options>(options)...);
1012 auto& client = raw_client_;
1013 return google::
cloud::internal::MakePaginationRange<
1014 ListObjectsAndPrefixesReader>(
1016 [client](internal::ListObjectsRequest
const& r) {
1017 return client->ListObjects(r);
1019 [](internal::ListObjectsResponse r) {
1020 std::vector<ObjectOrPrefix> result;
1021 for (
auto& item : r.items) {
1022 result.emplace_back(std::move(item));
1024 for (
auto& prefix : r.prefixes) {
1025 result.emplace_back(std::move(prefix));
1027 internal::SortObjectsAndPrefixes(result);
1067 template <
typename... Options>
1069 std::string
const& object_name,
1070 Options&&... options) {
1072 :
public absl::disjunction<std::is_same<
ReadRange, Options>...> {};
1073 struct HasReadFromOffset
1074 :
public absl::disjunction<std::is_same<
ReadFromOffset, Options>...> {};
1076 :
public absl::disjunction<std::is_same<
ReadLast, Options>...> {};
1078 struct HasIncompatibleRangeOptions
1079 :
public std::integral_constant<
bool, HasReadLast::value &&
1080 (HasReadFromOffset::value ||
1081 HasReadRange::value)> {};
1083 static_assert(!HasIncompatibleRangeOptions::value,
1084 "Cannot set ReadLast option with either ReadFromOffset or "
1088 SpanOptions(std::forward<Options>(options)...));
1089 internal::ReadObjectRangeRequest request(bucket_name, object_name);
1090 request.set_multiple_options(std::forward<Options>(options)...);
1091 return ReadObjectImpl(request);
1155 template <
typename... Options>
1157 std::string
const& object_name,
1158 Options&&... options) {
1160 SpanOptions(std::forward<Options>(options)...));
1161 internal::ResumableUploadRequest request(bucket_name, object_name);
1162 request.set_multiple_options(std::forward<Options>(options)...);
1163 return WriteObjectImpl(request);
1196 template <
typename... Options>
1198 std::string
const& bucket_name,
1199 std::string
const& object_name,
1200 Options&&... options) {
1205 using HasUseResumableUpload =
1207 return UploadFileImpl(file_name, bucket_name, object_name,
1208 HasUseResumableUpload{},
1209 std::forward<Options>(options)...);
1224 template <
typename... Options>
1226 Options&&... options) {
1228 SpanOptions(std::forward<Options>(options)...));
1229 internal::DeleteResumableUploadRequest request(upload_session_url);
1230 request.set_multiple_options(std::forward<Options>(options)...);
1231 return raw_client_->DeleteResumableUpload(request)
.status();
1253 template <
typename... Options>
1255 std::string
const& object_name,
1256 std::string
const& file_name, Options&&... options) {
1258 SpanOptions(std::forward<Options>(options)...));
1259 internal::ReadObjectRangeRequest request(bucket_name, object_name);
1260 request.set_multiple_options(std::forward<Options>(options)...);
1261 return DownloadFileImpl(request, file_name);
1282 template <
typename... Options>
1284 std::string
const& object_name, Options&&... options) {
1286 SpanOptions(std::forward<Options>(options)...));
1287 internal::DeleteObjectRequest request(bucket_name, object_name);
1288 request.set_multiple_options(std::forward<Options>(options)...);
1289 return raw_client_->DeleteObject(request)
.status();
1314 template <
typename... Options>
1316 std::string object_name,
1318 Options&&... options) {
1320 SpanOptions(std::forward<Options>(options)...));
1321 internal::UpdateObjectRequest request(
1322 std::move(bucket_name), std::move(object_name), std::move(metadata));
1323 request.set_multiple_options(std::forward<Options>(options)...);
1324 return raw_client_->UpdateObject(request);
1353 template <
typename... Options>
1355 std::string object_name,
1358 Options&&... options) {
1360 SpanOptions(std::forward<Options>(options)...));
1361 internal::PatchObjectRequest request(
1362 std::move(bucket_name), std::move(object_name), original, updated);
1363 request.set_multiple_options(std::forward<Options>(options)...);
1364 return raw_client_->PatchObject(request);
1391 template <
typename... Options>
1393 std::string bucket_name, std::string object_name,
1396 SpanOptions(std::forward<Options>(options)...));
1397 internal::PatchObjectRequest request(std::move(bucket_name),
1398 std::move(object_name), builder);
1399 request.set_multiple_options(std::forward<Options>(options)...);
1400 return raw_client_->PatchObject(request);
1426 template <
typename... Options>
1429 std::string destination_object_name, Options&&... options) {
1431 SpanOptions(std::forward<Options>(options)...));
1432 internal::ComposeObjectRequest request(std::move(bucket_name),
1433 std::move(source_objects),
1434 std::move(destination_object_name));
1435 request.set_multiple_options(std::forward<Options>(options)...);
1436 return raw_client_->ComposeObject(request);
1477 template <
typename... Options>
1479 std::string source_object_name,
1480 std::string destination_bucket_name,
1481 std::string destination_object_name,
1482 Options&&... options) {
1483 return ResumeRewriteObject(
1484 std::move(source_bucket_name), std::move(source_object_name),
1485 std::move(destination_bucket_name), std::move(destination_object_name),
1486 std::string{}, std::forward<Options>(options)...);
1529 template <
typename... Options>
1531 std::string source_object_name,
1532 std::string destination_bucket_name,
1533 std::string destination_object_name,
1534 std::string rewrite_token,
1535 Options&&... options) {
1537 SpanOptions(std::forward<Options>(options)...));
1538 internal::RewriteObjectRequest request(
1539 std::move(source_bucket_name), std::move(source_object_name),
1540 std::move(destination_bucket_name), std::move(destination_object_name),
1541 std::move(rewrite_token));
1542 request.set_multiple_options(std::forward<Options>(options)...);
1589 template <
typename... Options>
1591 std::string source_bucket_name, std::string source_object_name,
1592 std::string destination_bucket_name, std::string destination_object_name,
1593 Options&&... options) {
1594 return ResumeRewriteObject(std::move(source_bucket_name),
1595 std::move(source_object_name),
1596 std::move(destination_bucket_name),
1597 std::move(destination_object_name),
1598 std::string{}, std::forward<Options>(options)...)
1647 template <
typename... Options>
1649 std::string
const& bucket_name, Options&&... options) {
1651 SpanOptions(std::forward<Options>(options)...));
1652 internal::ListBucketAclRequest request(bucket_name);
1653 request.set_multiple_options(std::forward<Options>(options)...);
1654 auto items = raw_client_->ListBucketAcl(request);
1658 return std::move(items
.value().items);
1682 template <
typename... Options>
1684 std::string
const& entity,
1685 std::string
const& role,
1686 Options&&... options) {
1688 SpanOptions(std::forward<Options>(options)...));
1689 internal::CreateBucketAclRequest request(bucket_name, entity, role);
1690 request.set_multiple_options(std::forward<Options>(options)...);
1691 return raw_client_->CreateBucketAcl(request);
1712 template <
typename... Options>
1714 std::string
const& entity, Options&&... options) {
1716 SpanOptions(std::forward<Options>(options)...));
1717 internal::DeleteBucketAclRequest request(bucket_name, entity);
1718 request.set_multiple_options(std::forward<Options>(options)...);
1719 return raw_client_->DeleteBucketAcl(request)
.status();
1739 template <
typename... Options>
1741 std::string
const& entity,
1742 Options&&... options) {
1744 SpanOptions(std::forward<Options>(options)...));
1745 internal::GetBucketAclRequest request(bucket_name, entity);
1746 request.set_multiple_options(std::forward<Options>(options)...);
1747 return raw_client_->GetBucketAcl(request);
1780 template <
typename... Options>
1783 Options&&... options) {
1785 SpanOptions(std::forward<Options>(options)...));
1786 internal::UpdateBucketAclRequest request(bucket_name, acl.entity(),
1788 request.set_multiple_options(std::forward<Options>(options)...);
1789 return raw_client_->UpdateBucketAcl(request);
1827 template <
typename... Options>
1829 std::string
const& bucket_name, std::string
const& entity,
1833 SpanOptions(std::forward<Options>(options)...));
1834 internal::PatchBucketAclRequest request(bucket_name, entity, original_acl,
1836 request.set_multiple_options(std::forward<Options>(options)...);
1837 return raw_client_->PatchBucketAcl(request);
1873 template <
typename... Options>
1875 std::string
const& bucket_name, std::string
const& entity,
1878 SpanOptions(std::forward<Options>(options)...));
1879 internal::PatchBucketAclRequest request(bucket_name, entity, builder);
1880 request.set_multiple_options(std::forward<Options>(options)...);
1881 return raw_client_->PatchBucketAcl(request);
1923 template <
typename... Options>
1925 std::string
const& bucket_name, std::string
const& object_name,
1926 Options&&... options) {
1928 SpanOptions(std::forward<Options>(options)...));
1929 internal::ListObjectAclRequest request(bucket_name, object_name);
1930 request.set_multiple_options(std::forward<Options>(options)...);
1931 auto result = raw_client_->ListObjectAcl(request);
1935 return std::move(result
.value().items);
1960 template <
typename... Options>
1962 std::string
const& object_name,
1963 std::string
const& entity,
1964 std::string
const& role,
1965 Options&&... options) {
1967 SpanOptions(std::forward<Options>(options)...));
1968 internal::CreateObjectAclRequest request(bucket_name, object_name, entity,
1970 request.set_multiple_options(std::forward<Options>(options)...);
1971 return raw_client_->CreateObjectAcl(request);
1994 template <
typename... Options>
1996 std::string
const& object_name,
1997 std::string
const& entity, Options&&... options) {
1999 SpanOptions(std::forward<Options>(options)...));
2000 internal::DeleteObjectAclRequest request(bucket_name, object_name, entity);
2001 request.set_multiple_options(std::forward<Options>(options)...);
2002 return raw_client_->DeleteObjectAcl(request)
.status();
2023 template <
typename... Options>
2025 std::string
const& object_name,
2026 std::string
const& entity,
2027 Options&&... options) {
2029 SpanOptions(std::forward<Options>(options)...));
2030 internal::GetObjectAclRequest request(bucket_name, object_name, entity);
2031 request.set_multiple_options(std::forward<Options>(options)...);
2032 return raw_client_->GetObjectAcl(request);
2064 template <
typename... Options>
2066 std::string
const& object_name,
2068 Options&&... options) {
2070 SpanOptions(std::forward<Options>(options)...));
2071 internal::UpdateObjectAclRequest request(bucket_name, object_name,
2072 acl.entity(), acl.role());
2073 request.set_multiple_options(std::forward<Options>(options)...);
2074 return raw_client_->UpdateObjectAcl(request);
2113 template <
typename... Options>
2115 std::string
const& bucket_name, std::string
const& object_name,
2119 SpanOptions(std::forward<Options>(options)...));
2120 internal::PatchObjectAclRequest request(bucket_name, object_name, entity,
2121 original_acl, new_acl);
2122 request.set_multiple_options(std::forward<Options>(options)...);
2123 return raw_client_->PatchObjectAcl(request);
2160 template <
typename... Options>
2162 std::string
const& bucket_name, std::string
const& object_name,
2164 Options&&... options) {
2166 SpanOptions(std::forward<Options>(options)...));
2167 internal::PatchObjectAclRequest request(bucket_name, object_name, entity,
2169 request.set_multiple_options(std::forward<Options>(options)...);
2170 return raw_client_->PatchObjectAcl(request);
2211 template <
typename... Options>
2213 std::string
const& bucket_name, Options&&... options) {
2215 SpanOptions(std::forward<Options>(options)...));
2216 internal::ListDefaultObjectAclRequest request(bucket_name);
2217 request.set_multiple_options(std::forward<Options>(options)...);
2218 auto response = raw_client_->ListDefaultObjectAcl(request);
2222 return std::move(response
.value().items);
2251 template <
typename... Options>
2253 std::string
const& bucket_name, std::string
const& entity,
2254 std::string
const& role, Options&&... options) {
2256 SpanOptions(std::forward<Options>(options)...));
2257 internal::CreateDefaultObjectAclRequest request(bucket_name, entity, role);
2258 request.set_multiple_options(std::forward<Options>(options)...);
2259 return raw_client_->CreateDefaultObjectAcl(request);
2285 template <
typename... Options>
2287 std::string
const& entity,
2288 Options&&... options) {
2290 SpanOptions(std::forward<Options>(options)...));
2291 internal::DeleteDefaultObjectAclRequest request(bucket_name, entity);
2292 request.set_multiple_options(std::forward<Options>(options)...);
2293 return raw_client_->DeleteDefaultObjectAcl(request)
.status();
2318 template <
typename... Options>
2320 std::string
const& bucket_name, std::string
const& entity,
2321 Options&&... options) {
2323 SpanOptions(std::forward<Options>(options)...));
2324 internal::GetDefaultObjectAclRequest request(bucket_name, entity);
2325 request.set_multiple_options(std::forward<Options>(options)...);
2326 return raw_client_->GetDefaultObjectAcl(request);
2362 template <
typename... Options>
2365 Options&&... options) {
2367 SpanOptions(std::forward<Options>(options)...));
2368 internal::UpdateDefaultObjectAclRequest request(bucket_name, acl.entity(),
2370 request.set_multiple_options(std::forward<Options>(options)...);
2371 return raw_client_->UpdateDefaultObjectAcl(request);
2412 template <
typename... Options>
2414 std::string
const& bucket_name, std::string
const& entity,
2418 SpanOptions(std::forward<Options>(options)...));
2419 internal::PatchDefaultObjectAclRequest request(bucket_name, entity,
2420 original_acl, new_acl);
2421 request.set_multiple_options(std::forward<Options>(options)...);
2422 return raw_client_->PatchDefaultObjectAcl(request);
2462 template <
typename... Options>
2464 std::string
const& bucket_name, std::string
const& entity,
2467 SpanOptions(std::forward<Options>(options)...));
2468 internal::PatchDefaultObjectAclRequest request(bucket_name, entity,
2470 request.set_multiple_options(std::forward<Options>(options)...);
2471 return raw_client_->PatchDefaultObjectAcl(request);
2508 template <
typename... Options>
2510 std::string
const& project_id, Options&&... options) {
2512 SpanOptions(std::forward<Options>(options)...));
2513 internal::GetProjectServiceAccountRequest request(project_id);
2514 request.set_multiple_options(std::forward<Options>(options)...);
2515 return raw_client_->GetServiceAccount(request);
2545 template <
typename... Options>
2548 SpanOptions(std::forward<Options>(options)...));
2549 auto const& project_id = raw_client_->client_options()
.project_id();
2550 return GetServiceAccountForProject(project_id,
2551 std::forward<Options>(options)...);
2583 template <
typename... Options>
2586 SpanOptions(std::forward<Options>(options)...));
2587 auto const& project_id = raw_client_->client_options()
.project_id();
2588 internal::ListHmacKeysRequest request(project_id);
2589 request.set_multiple_options(std::forward<Options>(options)...);
2590 auto& client = raw_client_;
2591 return google::
cloud::internal::MakePaginationRange<ListHmacKeysReader>(
2593 [client](internal::ListHmacKeysRequest
const& r) {
2594 return client->ListHmacKeys(r);
2596 [](internal::ListHmacKeysResponse r) {
return std::move(r.items); });
2629 template <
typename... Options>
2631 std::string service_account, Options&&... options) {
2633 SpanOptions(std::forward<Options>(options)...));
2634 auto const& project_id = raw_client_->client_options()
.project_id();
2635 internal::CreateHmacKeyRequest request(project_id,
2636 std::move(service_account));
2637 request.set_multiple_options(std::forward<Options>(options)...);
2638 auto result = raw_client_->CreateHmacKey(request);
2642 return std::make_pair(std::move(result
->metadata),
2643 std::move(result
->secret));
2671 template <
typename... Options>
2674 SpanOptions(std::forward<Options>(options)...));
2675 auto const& project_id = raw_client_->client_options()
.project_id();
2676 internal::DeleteHmacKeyRequest request(project_id, std::move(access_id));
2677 request.set_multiple_options(std::forward<Options>(options)...);
2678 return raw_client_->DeleteHmacKey(request)
.status();
2705 template <
typename... Options>
2707 Options&&... options) {
2709 SpanOptions(std::forward<Options>(options)...));
2710 auto const& project_id = raw_client_->client_options()
.project_id();
2711 internal::GetHmacKeyRequest request(project_id, std::move(access_id));
2712 request.set_multiple_options(std::forward<Options>(options)...);
2713 return raw_client_->GetHmacKey(request);
2744 template <
typename... Options>
2747 Options&&... options) {
2749 SpanOptions(std::forward<Options>(options)...));
2750 auto const& project_id = raw_client_->client_options()
.project_id();
2751 internal::UpdateHmacKeyRequest request(project_id, std::move(access_id),
2752 std::move(resource));
2753 request.set_multiple_options(std::forward<Options>(options)...);
2754 return raw_client_->UpdateHmacKey(request);
2812 template <
typename... Options>
2814 std::string bucket_name,
2815 std::string object_name,
2816 Options&&... options) {
2818 SpanOptions(std::forward<Options>(options)...));
2819 internal::V2SignUrlRequest request(std::move(verb), std::move(bucket_name),
2820 std::move(object_name));
2821 request.set_multiple_options(std::forward<Options>(options)...);
2822 return SignUrlV2(request);
2877 template <
typename... Options>
2879 std::string bucket_name,
2880 std::string object_name,
2881 Options&&... options) {
2883 SpanOptions(std::forward<Options>(options)...));
2884 internal::V4SignUrlRequest request(std::move(verb), std::move(bucket_name),
2885 std::move(object_name));
2886 request.set_multiple_options(std::forward<Options>(options)...);
2887 return SignUrlV4(std::move(request));
2923 template <
typename... Options>
2927 SpanOptions(std::forward<Options>(options)...));
2928 internal::PolicyDocumentRequest request(std::move(document));
2929 request.set_multiple_options(std::forward<Options>(options)...);
2930 return SignPolicyDocument(request);
2966 template <
typename... Options>
2970 SpanOptions(std::forward<Options>(options)...));
2971 internal::PolicyDocumentV4Request request(std::move(document));
2972 request.set_multiple_options(std::forward<Options>(options)...);
2973 return SignPolicyDocumentV4(std::move(request));
3003 template <
typename... Options>
3005 std::string
const& bucket_name, Options&&... options) {
3007 SpanOptions(std::forward<Options>(options)...));
3008 internal::ListNotificationsRequest request(bucket_name);
3009 request.set_multiple_options(std::forward<Options>(options)...);
3010 auto result = raw_client_->ListNotifications(request);
3014 return std::move(result
.value().items);
3046 template <
typename... Options>
3048 std::string
const& bucket_name, std::string
const& topic_name,
3051 SpanOptions(std::forward<Options>(options)...));
3052 return CreateNotification(bucket_name, topic_name,
3054 std::forward<Options>(options)...);
3090 template <
typename... Options>
3092 std::string
const& bucket_name, std::string
const& topic_name,
3094 Options&&... options) {
3096 SpanOptions(std::forward<Options>(options)...));
3098 internal::CreateNotificationRequest request(bucket_name, metadata);
3099 request.set_multiple_options(std::forward<Options>(options)...);
3100 return raw_client_->CreateNotification(request);
3128 template <
typename... Options>
3130 std::string
const& bucket_name, std::string
const& notification_id,
3131 Options&&... options) {
3133 SpanOptions(std::forward<Options>(options)...));
3134 internal::GetNotificationRequest request(bucket_name, notification_id);
3135 request.set_multiple_options(std::forward<Options>(options)...);
3136 return raw_client_->GetNotification(request);
3166 template <
typename... Options>
3168 std::string
const& notification_id,
3169 Options&&... options) {
3171 SpanOptions(std::forward<Options>(options)...));
3172 internal::DeleteNotificationRequest request(bucket_name, notification_id);
3173 request.set_multiple_options(std::forward<Options>(options)...);
3174 return std::move(raw_client_->DeleteNotification(request))
.status();
3190 template <
typename... Policies>
3192 :
Client(InternalOnly{}, internal::ApplyPolicies(
3193 internal::MakeOptions(std::move(options)),
3194 std::forward<Policies>(policies)...)) {}
3207 template <
typename... Policies>
3209 Policies&&... policies)
3211 internal::ApplyPolicies(
3212 internal::DefaultOptions(std::move(credentials),
{}),
3213 std::forward<Policies>(policies)...)) {}
3226 template <
typename... Policies>
3227 #if !defined(_MSC_VER) || _MSC_VER >= 1920
3228 GOOGLE_CLOUD_CPP_DEPRECATED(
3229 "applications should not need this."
3230 " Please use the constructors from ClientOptions instead."
3231 " For mocking, please use testing::ClientFromMock() instead."
3232 " Please file a bug at https://github.com/googleapis/google-cloud-cpp"
3233 " if you have a use-case not covered by these.")
3236 explicit Client(std::shared_ptr<internal::RawClient> client,
3237 Policies&&... policies)
3238 :
Client(InternalOnlyNoDecorations{},
3239 CreateDefaultInternalClient(
3240 internal::ApplyPolicies(
3241 internal::DefaultOptions(
3243 std::forward<Policies>(policies)...),
3253 GOOGLE_CLOUD_CPP_DEPRECATED(
3254 "applications should not need this."
3255 " Please file a bug at https://github.com/googleapis/google-cloud-cpp"
3258 :
Client(InternalOnlyNoDecorations{}, std::move(client)) {}
3262 GOOGLE_CLOUD_CPP_DEPRECATED(
3263 "applications should not need this."
3264 " Please file a bug at https://github.com/googleapis/google-cloud-cpp"
3271 friend class internal::NonResumableParallelUploadState;
3272 friend class internal::ResumableParallelUploadState;
3273 friend internal::ClientImplDetails;
3275 struct InternalOnly {};
3276 struct InternalOnlyNoDecorations {};
3278 Client(InternalOnly,
Options const& opts)
3279 : raw_client_(CreateDefaultInternalClient(opts)) {}
3280 Client(InternalOnlyNoDecorations, std::shared_ptr<internal::RawClient> c)
3281 : raw_client_(std::move(c)) {}
3283 static std::shared_ptr<internal::RawClient> CreateDefaultInternalClient(
3284 Options const& opts, std::shared_ptr<internal::RawClient> client);
3285 static std::shared_ptr<internal::RawClient> CreateDefaultInternalClient(
3289 internal::ReadObjectRangeRequest
const& request);
3292 internal::ResumableUploadRequest
const& request);
3294 template <
typename... RequestOptions>
3296 return internal::GroupOptions(raw_client_->options(),
3297 std::forward<RequestOptions>(o)...);
3302 template <
typename... Options>
3303 StatusOr<
ObjectMetadata> UploadFileImpl(std::string
const& file_name,
3304 std::string
const& bucket_name,
3305 std::string
const& object_name,
3307 Options&&... options) {
3309 SpanOptions(std::forward<Options>(options)...));
3310 internal::ResumableUploadRequest request(bucket_name, object_name);
3311 request.set_multiple_options(std::forward<Options>(options)...);
3312 return UploadFileResumable(file_name, std::move(request));
3318 template <
typename... Options>
3319 StatusOr<
ObjectMetadata> UploadFileImpl(std::string
const& file_name,
3320 std::string
const& bucket_name,
3321 std::string
const& object_name,
3323 Options&&... options) {
3325 SpanOptions(std::forward<Options>(options)...));
3326 std::size_t file_size = 0;
3327 if (UseSimpleUpload(file_name, file_size)) {
3328 internal::InsertObjectMediaRequest request(bucket_name, object_name,
3330 request.set_multiple_options(std::forward<Options>(options)...);
3331 return UploadFileSimple(file_name, file_size, request);
3333 internal::ResumableUploadRequest request(bucket_name, object_name);
3334 request.set_multiple_options(std::forward<Options>(options)...);
3335 return UploadFileResumable(file_name, std::move(request));
3338 bool UseSimpleUpload(std::string
const& file_name, std::size_t& size)
const;
3341 std::string
const& file_name, std::size_t file_size,
3342 internal::InsertObjectMediaRequest request);
3345 std::string
const& file_name, internal::ResumableUploadRequest request);
3348 std::istream& source,
3349 internal::ResumableUploadRequest
const& request)
const;
3351 Status DownloadFileImpl(internal::ReadObjectRangeRequest
const& request,
3352 std::string
const& file_name);
3355 std::string SigningEmail(
SigningAccount const& signing_account)
const;
3359 struct SignBlobResponseRaw {
3361 std::vector<std::uint8_t> signed_blob;
3365 StatusOr<SignBlobResponseRaw> SignBlobImpl(
3366 SigningAccount const& signing_account, std::string
const& string_to_sign);
3368 StatusOr<std::string> SignUrlV2(internal::V2SignUrlRequest
const& request);
3369 StatusOr<std::string> SignUrlV4(internal::V4SignUrlRequest request);
3372 internal::PolicyDocumentRequest
const& request);
3374 internal::PolicyDocumentV4Request request);
3376 std::shared_ptr<internal::RawClient> raw_client_;
3397 namespace internal {
3398 struct ClientImplDetails {
3399 static std::shared_ptr<RawClient> GetRawClient(
Client& c) {
3400 return c.raw_client_;
3404 Client& client, std::istream& source,
3405 internal::ResumableUploadRequest
const& request) {
3406 return client.UploadStreamResumable(source, request);
3409 template <
typename... Policies>
3410 static Client CreateClient(std::shared_ptr<internal::RawClient> c,
3413 internal::ApplyPolicies(c->options(), std::forward<Policies>(p)...);
3415 Client::CreateDefaultInternalClient(opts, std::move(c)));
3418 static Client CreateWithoutDecorations(
3419 std::shared_ptr<internal::RawClient> c) {
3420 return Client(
Client::InternalOnlyNoDecorations{}, std::move(c));
3425 struct DeleteApplyHelper {
3426 template <
typename... Options>
3427 Status operator()(Options... options)
const {
3428 return client.DeleteObject(bucket_name, object_name,
Generation(generation),
3429 std::move(options)...);
3433 std::string bucket_name;
3434 std::string object_name;
3435 std::int64_t generation;
3439 struct InsertObjectApplyHelper {
3440 template <
typename... Options>
3442 return client.InsertObject(bucket_name, object_name, std::move(contents),
3443 std::move(options)...);
3447 std::string
const& bucket_name;
3448 std::string
const& object_name;
3449 std::string contents;
3465 template <
typename... Options>
3467 std::string
const& bucket_name,
3468 std::string
const& prefix,
3469 Options&&... options) {
3471 internal::InsertObjectApplyHelper{client, bucket_name, prefix,
""},
3474 internal::StaticTupleFilter<
3477 std::forward_as_tuple(std::forward<Options>(options)...))));
3492 template <
typename... Options>
3494 std::string
const& prefix, Options&&... options) {
3495 using internal::NotAmong;
3496 using internal::StaticTupleFilter;
3498 auto all_options = std::tie(options...);
3502 decltype(StaticTupleFilter<
3504 all_options))>::value == 0,
3505 "This functions accepts only options of type QuotaUser, UserIp, "
3506 "UserProject or Versions.");
3510 std::forward<Options>(options)...)) {
3511 if (!object)
return std::move(object).status();
3513 internal::DeleteApplyHelper{client, object->bucket(), object->name(),
3514 object->generation()},
3515 StaticTupleFilter<NotAmong<
Versions>::TPred>(all_options));
3518 status = std::move(del);
3523 namespace internal {
3526 struct ComposeApplyHelper {
3527 template <
typename... Options>
3529 return client.ComposeObject(
3530 std::move(bucket_name), std::move(source_objects),
3531 std::move(destination_object_name), std::move(options)...);
3535 std::string bucket_name;
3537 std::string destination_object_name;
3541 class ScopedDeleter {
3545 explicit ScopedDeleter(std::function<
Status(std::string, std::int64_t)> df);
3546 ScopedDeleter(ScopedDeleter
const&) =
delete;
3547 ScopedDeleter& operator=(ScopedDeleter
const&) =
delete;
3554 void Add(std::string object_name, std::int64_t generation);
3559 void Enable(
bool enable) { enabled_ = enable; }
3562 bool enabled_ =
true;
3563 std::function<
Status(std::string, std::int64_t)> delete_fun_;
3564 std::vector<std::pair<std::string, std::int64_t>> object_list_;
3612 template <
typename... Options>
3614 Client& client, std::string
const& bucket_name,
3616 std::string destination_object_name,
bool ignore_cleanup_failures,
3617 Options&&... options) {
3618 using internal::Among;
3619 using internal::NotAmong;
3620 using internal::StaticTupleFilter;
3621 std::size_t
const max_num_objects = 32;
3623 if (source_objects.empty()) {
3625 "ComposeMany requires at least one source object.");
3628 auto all_options = std::make_tuple(options...);
3633 decltype(StaticTupleFilter<
3639 "This functions accepts only options of type DestinationPredefinedAcl, "
3640 "EncryptionKey, IfGenerationMatch, IfMetagenerationMatch, KmsKeyName, "
3641 "QuotaUser, UserIp, UserProject or WithObjectMetadata.");
3643 internal::ScopedDeleter deleter(
3644 [&](std::string
const& object_name, std::int64_t generation) {
3646 internal::DeleteApplyHelper{client, bucket_name, object_name,
3652 auto lock = internal::LockPrefix(client, bucket_name, prefix,
"",
3653 std::make_tuple(options...));
3656 lock.status().code(),
3657 "Failed to lock prefix for ComposeMany: " + lock.status().message());
3661 std::size_t num_tmp_objects = 0;
3662 auto tmpobject_name_gen = [&num_tmp_objects, &prefix] {
3663 return prefix +
".compose-tmp-" + std::to_string(num_tmp_objects++);
3666 auto to_source_objects = [](std::vector<
ObjectMetadata> objects) {
3668 std::transform(objects.begin(), objects.end(), sources.begin(),
3679 internal::ComposeApplyHelper{client, bucket_name,
3680 std::move(compose_range),
3681 std::move(destination_object_name)},
3685 internal::ComposeApplyHelper{client, bucket_name,
3686 std::move(compose_range),
3687 tmpobject_name_gen()},
3696 for (
auto range_begin = source_objects.begin();
3697 range_begin != source_objects.end();) {
3698 std::size_t range_size = std::min<std::size_t>(
3699 std::distance(range_begin, source_objects.end()), max_num_objects);
3700 auto range_end = std::next(range_begin, range_size);
3702 std::move(range_begin, range_end, compose_range.begin());
3704 bool const is_final_composition =
3705 source_objects.size() <= max_num_objects;
3706 auto object = composer(std::move(compose_range), is_final_composition);
3708 return std::move(object).status();
3710 objects.push_back(*std::move(object));
3711 if (!is_final_composition) {
3712 deleter.Add(objects.back());
3714 range_begin = range_end;
3721 StatusOr<std::vector<
ObjectMetadata>> objects = reduce(source_objects);
3725 if (objects
->size() == 1) {
3726 if (!ignore_cleanup_failures) {
3727 auto delete_status = deleter.ExecuteDelete();
3728 if (!delete_status
.ok()) {
3729 return delete_status;
3732 result = std::move((
*objects)[0]);
3735 source_objects = to_source_objects(
*std::move(objects));
3736 }
while (source_objects.size() > 1);