Google Cloud Storage C++ Client  1.33.0
A C++ Client Library for Google Cloud Storage
idempotency_policy.cc
Go to the documentation of this file.
1 // Copyright 2018 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "google/cloud/storage/idempotency_policy.h"
16 #include "absl/memory/memory.h"
17 
18 namespace google {
19 namespace cloud {
20 namespace storage {
23  return absl::make_unique<AlwaysRetryIdempotencyPolicy>(*this);
24 }
25 
27  internal::ListBucketsRequest const&) const {
28  return true;
29 }
31  internal::CreateBucketRequest const&) const {
32  return true;
33 }
35  internal::GetBucketMetadataRequest const&) const {
36  return true;
37 }
39  internal::DeleteBucketRequest const&) const {
40  return true;
41 }
43  internal::UpdateBucketRequest const&) const {
44  return true;
45 }
47  internal::PatchBucketRequest const&) const {
48  return true;
49 }
51  internal::GetBucketIamPolicyRequest const&) const {
52  return true;
53 }
55  internal::SetBucketIamPolicyRequest const&) const {
56  return true;
57 }
59  internal::SetNativeBucketIamPolicyRequest const&) const {
60  return true;
61 }
63  internal::TestBucketIamPermissionsRequest const&) const {
64  return true;
65 }
67  internal::LockBucketRetentionPolicyRequest const&) const {
68  return true;
69 }
70 
72  internal::InsertObjectMediaRequest const&) const {
73  return true;
74 }
76  internal::CopyObjectRequest const&) const {
77  return true;
78 }
80  internal::GetObjectMetadataRequest const&) const {
81  return true;
82 }
84  internal::ReadObjectRangeRequest const&) const {
85  return true;
86 }
88  internal::ListObjectsRequest const&) const {
89  return true;
90 }
92  internal::DeleteObjectRequest const&) const {
93  return true;
94 }
96  internal::UpdateObjectRequest const&) const {
97  return true;
98 }
100  internal::PatchObjectRequest const&) const {
101  return true;
102 }
104  internal::ComposeObjectRequest const&) const {
105  return true;
106 }
108  internal::RewriteObjectRequest const&) const {
109  return true;
110 }
112  internal::ResumableUploadRequest const&) const {
113  return true;
114 }
116  internal::UploadChunkRequest const&) const {
117  return true;
118 }
119 
121  internal::ListBucketAclRequest const&) const {
122  return true;
123 }
125  internal::CreateBucketAclRequest const&) const {
126  return true;
127 }
129  internal::DeleteBucketAclRequest const&) const {
130  return true;
131 }
133  internal::GetBucketAclRequest const&) const {
134  return true;
135 }
137  internal::UpdateBucketAclRequest const&) const {
138  return true;
139 }
141  internal::PatchBucketAclRequest const&) const {
142  return true;
143 }
144 
146  internal::ListObjectAclRequest const&) const {
147  return true;
148 }
150  internal::CreateObjectAclRequest const&) const {
151  return true;
152 }
154  internal::DeleteObjectAclRequest const&) const {
155  return true;
156 }
158  internal::GetObjectAclRequest const&) const {
159  return true;
160 }
162  internal::UpdateObjectAclRequest const&) const {
163  return true;
164 }
166  internal::PatchObjectAclRequest const&) const {
167  return true;
168 }
169 
171  internal::ListDefaultObjectAclRequest const&) const {
172  return true;
173 }
175  internal::CreateDefaultObjectAclRequest const&) const {
176  return true;
177 }
179  internal::DeleteDefaultObjectAclRequest const&) const {
180  return true;
181 }
183  internal::GetDefaultObjectAclRequest const&) const {
184  return true;
185 }
187  internal::UpdateDefaultObjectAclRequest const&) const {
188  return true;
189 }
191  internal::PatchDefaultObjectAclRequest const&) const {
192  return true;
193 }
194 
196  internal::GetProjectServiceAccountRequest const&) const {
197  return true;
198 }
200  internal::ListHmacKeysRequest const&) const {
201  return true;
202 }
204  internal::CreateHmacKeyRequest const&) const {
205  return true;
206 }
208  internal::DeleteHmacKeyRequest const&) const {
209  return true;
210 }
212  internal::GetHmacKeyRequest const&) const {
213  return true;
214 }
216  internal::UpdateHmacKeyRequest const&) const {
217  return true;
218 }
220  internal::SignBlobRequest const&) const {
221  return true;
222 }
223 
225  internal::ListNotificationsRequest const&) const {
226  return true;
227 }
229  internal::CreateNotificationRequest const&) const {
230  return true;
231 }
233  internal::GetNotificationRequest const&) const {
234  return true;
235 }
237  internal::DeleteNotificationRequest const&) const {
238  return true;
239 }
240 
242  return absl::make_unique<StrictIdempotencyPolicy>(*this);
243 }
244 
246  internal::ListBucketsRequest const&) const {
247  // Read operations are always idempotent.
248  return true;
249 }
250 
252  internal::CreateBucketRequest const&) const {
253  // Creating a bucket is idempotent because you cannot create a new version
254  // of a bucket, it succeeds only once.
255  return true;
256 }
257 
259  internal::GetBucketMetadataRequest const&) const {
260  // Read operations are always idempotent.
261  return true;
262 }
263 
265  internal::DeleteBucketRequest const& request) const {
266  return (request.HasOption<IfMatchEtag>() ||
267  request.HasOption<IfMetagenerationMatch>());
268 }
269 
271  internal::UpdateBucketRequest const& request) const {
272  return (request.HasOption<IfMatchEtag>() ||
273  request.HasOption<IfMetagenerationMatch>());
274 }
275 
277  internal::PatchBucketRequest const& request) const {
278  return (request.HasOption<IfMatchEtag>() ||
279  request.HasOption<IfMetagenerationMatch>());
280 }
281 
283  internal::GetBucketIamPolicyRequest const&) const {
284  return true;
285 }
286 
288  internal::SetBucketIamPolicyRequest const& request) const {
289  return request.HasOption<IfMatchEtag>();
290 }
291 
293  internal::SetNativeBucketIamPolicyRequest const& request) const {
294  return request.HasOption<IfMatchEtag>();
295 }
296 
298  internal::TestBucketIamPermissionsRequest const&) const {
299  return true;
300 }
301 
303  internal::LockBucketRetentionPolicyRequest const&) const {
304  // This request type always requires a metageneration pre-condition.
305  return true;
306 }
307 
309  internal::InsertObjectMediaRequest const& request) const {
310  return request.HasOption<IfGenerationMatch>();
311 }
312 
314  internal::CopyObjectRequest const& request) const {
315  // Only the pre-conditions on the destination matter. If they are not set, it
316  // is possible for the request to succeed more than once, even if the source
317  // pre-conditions are set. If they are set, the operation can only succeed
318  // once, but the results may be different.
319  return request.HasOption<IfGenerationMatch>();
320 }
321 
323  internal::GetObjectMetadataRequest const&) const {
324  return true;
325 }
326 
328  internal::ReadObjectRangeRequest const&) const {
329  return true;
330 }
331 
333  internal::ListObjectsRequest const&) const {
334  return true;
335 }
336 
338  internal::DeleteObjectRequest const& request) const {
339  return request.HasOption<Generation>() ||
340  request.HasOption<IfGenerationMatch>();
341 }
342 
344  internal::UpdateObjectRequest const& request) const {
345  return request.HasOption<IfMatchEtag>() ||
346  request.HasOption<IfMetagenerationMatch>();
347 }
348 
350  internal::PatchObjectRequest const& request) const {
351  return request.HasOption<IfMatchEtag>() ||
352  request.HasOption<IfMetagenerationMatch>();
353 }
354 
356  internal::ComposeObjectRequest const& request) const {
357  // Only the pre-conditions on the destination matter. If they are not set, it
358  // is possible for the request to succeed more than once, even if the source
359  // pre-conditions are set. If they are set, the operation can only succeed
360  // once, but the results may be different.
361  return request.HasOption<IfGenerationMatch>();
362 }
363 
365  internal::RewriteObjectRequest const& request) const {
366  // Only the pre-conditions on the destination matter. If they are not set, it
367  // is possible for the request to succeed more than once, even if the source
368  // pre-conditions are set. If they are set, the operation can only succeed
369  // once, but the results may be different.
370  return request.HasOption<IfGenerationMatch>();
371 }
372 
374  internal::ResumableUploadRequest const& request) const {
375  // Only the pre-conditions on the destination matter. If they are not set, it
376  // is possible for the request to succeed more than once, even if the source
377  // pre-conditions are set. If they are set, the operation can only succeed
378  // once, but the results may be different.
379  return request.HasOption<IfGenerationMatch>();
380 }
381 
383  internal::UploadChunkRequest const&) const {
384  return true;
385 }
386 
388  internal::ListBucketAclRequest const&) const {
389  return true;
390 }
391 
393  internal::CreateBucketAclRequest const& request) const {
394  return request.HasOption<IfMatchEtag>();
395 }
396 
398  internal::DeleteBucketAclRequest const& request) const {
399  return request.HasOption<IfMatchEtag>();
400 }
401 
403  internal::GetBucketAclRequest const&) const {
404  return true;
405 }
406 
408  internal::UpdateBucketAclRequest const& request) const {
409  return request.HasOption<IfMatchEtag>();
410 }
411 
413  internal::PatchBucketAclRequest const& request) const {
414  return request.HasOption<IfMatchEtag>();
415 }
416 
418  internal::ListObjectAclRequest const&) const {
419  return true;
420 }
421 
423  internal::CreateObjectAclRequest const& request) const {
424  return request.HasOption<IfMatchEtag>();
425 }
426 
428  internal::DeleteObjectAclRequest const& request) const {
429  return request.HasOption<IfMatchEtag>();
430 }
431 
433  internal::GetObjectAclRequest const&) const {
434  return true;
435 }
436 
438  internal::UpdateObjectAclRequest const& request) const {
439  return request.HasOption<IfMatchEtag>();
440 }
441 
443  internal::PatchObjectAclRequest const& request) const {
444  return request.HasOption<IfMatchEtag>();
445 }
446 
448  internal::ListDefaultObjectAclRequest const&) const {
449  return true;
450 }
451 
453  internal::CreateDefaultObjectAclRequest const& request) const {
454  return request.HasOption<IfMatchEtag>();
455 }
456 
458  internal::DeleteDefaultObjectAclRequest const& request) const {
459  return request.HasOption<IfMatchEtag>();
460 }
461 
463  internal::GetDefaultObjectAclRequest const&) const {
464  return true;
465 }
466 
468  internal::UpdateDefaultObjectAclRequest const& request) const {
469  return request.HasOption<IfMatchEtag>();
470 }
471 
473  internal::PatchDefaultObjectAclRequest const& request) const {
474  return request.HasOption<IfMatchEtag>();
475 }
476 
478  internal::GetProjectServiceAccountRequest const&) const {
479  return true;
480 }
481 
483  internal::ListHmacKeysRequest const&) const {
484  return true;
485 }
486 
488  internal::CreateHmacKeyRequest const&) const {
489  return false;
490 }
491 
493  internal::DeleteHmacKeyRequest const&) const {
494  return true;
495 }
496 
498  internal::GetHmacKeyRequest const&) const {
499  return true;
500 }
501 
503  internal::UpdateHmacKeyRequest const& request) const {
504  // The plan of record is to support `If-Match-Etag` headers *and* the `etag`
505  // attribute on the payload as preconditions for `HmacKeys: update`.
506  return !request.resource().etag().empty() || request.HasOption<IfMatchEtag>();
507 }
508 
510  internal::SignBlobRequest const&) const {
511  return true;
512 }
513 
515  internal::ListNotificationsRequest const&) const {
516  return true;
517 }
518 
520  internal::CreateNotificationRequest const&) const {
521  return true;
522 }
523 
525  internal::GetNotificationRequest const&) const {
526  return true;
527 }
528 
530  internal::DeleteNotificationRequest const&) const {
531  return true;
532 }
533 
535 } // namespace storage
536 } // namespace cloud
537 } // namespace google