google-cloud-storage 1.38.0 → 1.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7377748053d6da28b196231e893002e4d80849cf558b5e983003926c19526a6c
4
- data.tar.gz: b00e59073ea7230b4b654de40e6323766d6e36a562d765ad2545c8d154b16d2d
3
+ metadata.gz: 7eae657ab195e86fc8c483f9920ffc030e19b3754d118b13d49053f7f3fdc544
4
+ data.tar.gz: 259b1d1c5138ad671e06a88cb461ed18e03bc6872dfe3d66f90bc3a01eb6907a
5
5
  SHA512:
6
- metadata.gz: 65b18a6857817dd24246d287c3e51cabfb2ec61fffda26f3fc00462fd030e60c506a893ccc86a14cfc1034d882c6d488b5220e744ee2fe3316d55271c9fdaadc
7
- data.tar.gz: fede3f8da08220a89dc1642fd1937cc75ea6b57ee9d210bd8a8dc4efcb5c11ff5dab0d2962c7c25f383cda4e9aa548fe8764c0ec06867abf46ca91d7fbbd33e3
6
+ metadata.gz: bac1d42f4566defbfb79814ec6d1d6aa440b4facf26cd860b1b956bb34d832b0109cf0ef1ffe706fba78f447be8eda3c3b29c9ad3e55b30204354538c2675b99
7
+ data.tar.gz: 8c90e04918e20961dd33f1e734c65f3d942f3600484cb9ccc697016b3843cc138cb9cd0cb8db0c760f0fcfde655759ce15dad9748115a603cde8a7201e9064c6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Release History
2
2
 
3
+ ### 1.40.0 (2022-09-13)
4
+
5
+ #### Features
6
+
7
+ * Update all patch bucket helper methods to accept preconditions ([#19117](https://github.com/googleapis/google-cloud-ruby/issues/19117))
8
+
9
+ ### 1.39.0 (2022-08-24)
10
+
11
+ #### Features
12
+
13
+ * add support for conditional idempotent operations ([#18834](https://github.com/googleapis/google-cloud-ruby/issues/18834))
14
+
3
15
  ### 1.38.0 (2022-07-31)
4
16
 
5
17
  #### Features
data/OVERVIEW.md CHANGED
@@ -563,6 +563,36 @@ require "google/cloud/storage"
563
563
  storage = Google::Cloud::Storage.new retries: 10, timeout: 120
564
564
  ```
565
565
 
566
+ The library by default retries all API requests which are always idempotent on a
567
+ "transient" error.
568
+
569
+ For API requests which are idempotent only if the some conditions are satisfied
570
+ (For ex. a file has the same "generation"), the library retries only if the
571
+ condition is specified.
572
+
573
+ Rather than using this default behaviour, you may choose to disable the retries
574
+ on your own.
575
+
576
+ You can pass `retries` as `0` to disable retries for all operations regardless
577
+ of their idempotencies.
578
+
579
+ ```ruby
580
+ require "google/cloud/storage"
581
+
582
+ storage = Google::Cloud::Storage.new retries: 0
583
+ ```
584
+
585
+ You can also disable retries for a particular operation by passing `retries` as
586
+ `0` in the `options` field.
587
+
588
+ ```ruby
589
+ require "google/cloud/storage"
590
+
591
+ storage = Google::Cloud::Storage.new
592
+ service = storage.service
593
+ service.get_bucket bucket_name, options: {retries: 0}
594
+ ```
595
+
566
596
  See the [Storage status and error
567
597
  codes](https://cloud.google.com/storage/docs/json_api/v1/status-codes)
568
598
  for a list of error conditions.
@@ -349,8 +349,8 @@ module Google
349
349
  #
350
350
  # bucket.acl.auth!
351
351
  #
352
- def auth!
353
- update_predefined_acl! "authenticatedRead"
352
+ def auth! if_metageneration_match: nil
353
+ update_predefined_acl! "authenticatedRead", if_metageneration_match: if_metageneration_match
354
354
  end
355
355
  alias authenticatedRead! auth!
356
356
  alias auth_read! auth!
@@ -370,8 +370,8 @@ module Google
370
370
  #
371
371
  # bucket.acl.private!
372
372
  #
373
- def private!
374
- update_predefined_acl! "private"
373
+ def private! if_metageneration_match: nil
374
+ update_predefined_acl! "private", if_metageneration_match: if_metageneration_match
375
375
  end
376
376
 
377
377
  ##
@@ -387,8 +387,8 @@ module Google
387
387
  #
388
388
  # bucket.acl.project_private!
389
389
  #
390
- def project_private!
391
- update_predefined_acl! "projectPrivate"
390
+ def project_private! if_metageneration_match: nil
391
+ update_predefined_acl! "projectPrivate", if_metageneration_match: if_metageneration_match
392
392
  end
393
393
  alias projectPrivate! project_private!
394
394
 
@@ -405,8 +405,8 @@ module Google
405
405
  #
406
406
  # bucket.acl.public!
407
407
  #
408
- def public!
409
- update_predefined_acl! "publicRead"
408
+ def public! if_metageneration_match: nil
409
+ update_predefined_acl! "publicRead", if_metageneration_match: if_metageneration_match
410
410
  end
411
411
  alias publicRead! public!
412
412
  alias public_read! public!
@@ -423,8 +423,8 @@ module Google
423
423
  #
424
424
  # bucket.acl.public_write!
425
425
  #
426
- def public_write!
427
- update_predefined_acl! "publicReadWrite"
426
+ def public_write! if_metageneration_match: nil
427
+ update_predefined_acl! "publicReadWrite", if_metageneration_match: if_metageneration_match
428
428
  end
429
429
  alias publicReadWrite! public_write!
430
430
 
@@ -437,9 +437,10 @@ module Google
437
437
  self
438
438
  end
439
439
 
440
- def update_predefined_acl! acl_role
440
+ def update_predefined_acl! acl_role, if_metageneration_match: nil
441
441
  @service.patch_bucket @bucket, predefined_acl: acl_role,
442
- user_project: user_project
442
+ user_project: user_project,
443
+ if_metageneration_match: if_metageneration_match
443
444
  clear!
444
445
  end
445
446
 
@@ -714,8 +715,8 @@ module Google
714
715
  #
715
716
  # bucket.default_acl.auth!
716
717
  #
717
- def auth!
718
- update_predefined_default_acl! "authenticatedRead"
718
+ def auth! if_metageneration_match: nil
719
+ update_predefined_default_acl! "authenticatedRead", if_metageneration_match: if_metageneration_match
719
720
  end
720
721
  alias authenticatedRead! auth!
721
722
  alias auth_read! auth!
@@ -735,8 +736,8 @@ module Google
735
736
  #
736
737
  # bucket.default_acl.owner_full!
737
738
  #
738
- def owner_full!
739
- update_predefined_default_acl! "bucketOwnerFullControl"
739
+ def owner_full! if_metageneration_match: nil
740
+ update_predefined_default_acl! "bucketOwnerFullControl", if_metageneration_match: if_metageneration_match
740
741
  end
741
742
  alias bucketOwnerFullControl! owner_full!
742
743
 
@@ -753,8 +754,8 @@ module Google
753
754
  #
754
755
  # bucket.default_acl.owner_read!
755
756
  #
756
- def owner_read!
757
- update_predefined_default_acl! "bucketOwnerRead"
757
+ def owner_read! if_metageneration_match: nil
758
+ update_predefined_default_acl! "bucketOwnerRead", if_metageneration_match: if_metageneration_match
758
759
  end
759
760
  alias bucketOwnerRead! owner_read!
760
761
 
@@ -771,8 +772,8 @@ module Google
771
772
  #
772
773
  # bucket.default_acl.private!
773
774
  #
774
- def private!
775
- update_predefined_default_acl! "private"
775
+ def private! if_metageneration_match: nil
776
+ update_predefined_default_acl! "private", if_metageneration_match: if_metageneration_match
776
777
  end
777
778
 
778
779
  ##
@@ -788,8 +789,8 @@ module Google
788
789
  #
789
790
  # bucket.default_acl.project_private!
790
791
  #
791
- def project_private!
792
- update_predefined_default_acl! "projectPrivate"
792
+ def project_private! if_metageneration_match: nil
793
+ update_predefined_default_acl! "projectPrivate", if_metageneration_match: if_metageneration_match
793
794
  end
794
795
  alias projectPrivate! project_private!
795
796
 
@@ -806,8 +807,8 @@ module Google
806
807
  #
807
808
  # bucket.default_acl.public!
808
809
  #
809
- def public!
810
- update_predefined_default_acl! "publicRead"
810
+ def public! if_metageneration_match: nil
811
+ update_predefined_default_acl! "publicRead", if_metageneration_match: if_metageneration_match
811
812
  end
812
813
  alias publicRead! public!
813
814
  alias public_read! public!
@@ -820,9 +821,10 @@ module Google
820
821
  self
821
822
  end
822
823
 
823
- def update_predefined_default_acl! acl_role
824
+ def update_predefined_default_acl! acl_role, if_metageneration_match: nil
824
825
  @service.patch_bucket @bucket, predefined_default_acl: acl_role,
825
- user_project: user_project
826
+ user_project: user_project,
827
+ if_metageneration_match: if_metageneration_match
826
828
  clear!
827
829
  end
828
830
 
@@ -81,11 +81,11 @@ module Google
81
81
 
82
82
  ##
83
83
  # Retrieves a list of buckets for the given project.
84
- def list_buckets prefix: nil, token: nil, max: nil, user_project: nil
84
+ def list_buckets prefix: nil, token: nil, max: nil, user_project: nil, options: {}
85
85
  execute do
86
86
  service.list_buckets \
87
87
  @project, prefix: prefix, page_token: token, max_results: max,
88
- user_project: user_project(user_project)
88
+ user_project: user_project(user_project), options: options
89
89
  end
90
90
  end
91
91
 
@@ -95,12 +95,14 @@ module Google
95
95
  def get_bucket bucket_name,
96
96
  if_metageneration_match: nil,
97
97
  if_metageneration_not_match: nil,
98
- user_project: nil
98
+ user_project: nil,
99
+ options: {}
99
100
  execute do
100
101
  service.get_bucket bucket_name,
101
102
  if_metageneration_match: if_metageneration_match,
102
103
  if_metageneration_not_match: if_metageneration_not_match,
103
- user_project: user_project(user_project)
104
+ user_project: user_project(user_project),
105
+ options: options
104
106
  end
105
107
  end
106
108
 
@@ -108,13 +110,14 @@ module Google
108
110
  # Creates a new bucket.
109
111
  # Returns Google::Apis::StorageV1::Bucket.
110
112
  def insert_bucket bucket_gapi, acl: nil, default_acl: nil,
111
- user_project: nil
113
+ user_project: nil, options: {}
112
114
  execute do
113
115
  service.insert_bucket \
114
116
  @project, bucket_gapi,
115
117
  predefined_acl: acl,
116
118
  predefined_default_object_acl: default_acl,
117
- user_project: user_project(user_project)
119
+ user_project: user_project(user_project),
120
+ options: options
118
121
  end
119
122
  end
120
123
 
@@ -126,11 +129,17 @@ module Google
126
129
  predefined_default_acl: nil,
127
130
  if_metageneration_match: nil,
128
131
  if_metageneration_not_match: nil,
129
- user_project: nil
132
+ user_project: nil,
133
+ options: {}
130
134
  bucket_gapi ||= Google::Apis::StorageV1::Bucket.new
131
135
  bucket_gapi.acl = [] if predefined_acl
132
136
  bucket_gapi.default_object_acl = [] if predefined_default_acl
133
137
 
138
+ if options[:retry].nil?
139
+ is_idempotent = retry? if_metageneration_match: if_metageneration_match
140
+ options = is_idempotent ? {} : { retries: 0 }
141
+ end
142
+
134
143
  execute do
135
144
  service.patch_bucket bucket_name,
136
145
  bucket_gapi,
@@ -138,7 +147,8 @@ module Google
138
147
  predefined_default_object_acl: predefined_default_acl,
139
148
  if_metageneration_match: if_metageneration_match,
140
149
  if_metageneration_not_match: if_metageneration_not_match,
141
- user_project: user_project(user_project)
150
+ user_project: user_project(user_project),
151
+ options: options
142
152
  end
143
153
  end
144
154
 
@@ -147,119 +157,132 @@ module Google
147
157
  def delete_bucket bucket_name,
148
158
  if_metageneration_match: nil,
149
159
  if_metageneration_not_match: nil,
150
- user_project: nil
160
+ user_project: nil,
161
+ options: {}
151
162
  execute do
152
163
  service.delete_bucket bucket_name,
153
164
  if_metageneration_match: if_metageneration_match,
154
165
  if_metageneration_not_match: if_metageneration_not_match,
155
- user_project: user_project(user_project)
166
+ user_project: user_project(user_project),
167
+ options: options
156
168
  end
157
169
  end
158
170
 
159
171
  ##
160
172
  # Locks retention policy on a bucket.
161
173
  def lock_bucket_retention_policy bucket_name, metageneration,
162
- user_project: nil
174
+ user_project: nil,
175
+ options: {}
163
176
  execute do
164
177
  service.lock_bucket_retention_policy \
165
178
  bucket_name, metageneration,
166
- user_project: user_project(user_project)
179
+ user_project: user_project(user_project),
180
+ options: options
167
181
  end
168
182
  end
169
183
 
170
184
  ##
171
185
  # Retrieves a list of ACLs for the given bucket.
172
- def list_bucket_acls bucket_name, user_project: nil
186
+ def list_bucket_acls bucket_name, user_project: nil, options: {}
173
187
  execute do
174
188
  service.list_bucket_access_controls \
175
- bucket_name, user_project: user_project(user_project)
189
+ bucket_name, user_project: user_project(user_project),
190
+ options: options
176
191
  end
177
192
  end
178
193
 
179
194
  ##
180
195
  # Creates a new bucket ACL.
181
- def insert_bucket_acl bucket_name, entity, role, user_project: nil
196
+ def insert_bucket_acl bucket_name, entity, role, user_project: nil, options: {}
182
197
  params = { entity: entity, role: role }.delete_if { |_k, v| v.nil? }
183
198
  new_acl = Google::Apis::StorageV1::BucketAccessControl.new(**params)
184
199
  execute do
185
200
  service.insert_bucket_access_control \
186
- bucket_name, new_acl, user_project: user_project(user_project)
201
+ bucket_name, new_acl, user_project: user_project(user_project),
202
+ options: options
187
203
  end
188
204
  end
189
205
 
190
206
  ##
191
207
  # Permanently deletes a bucket ACL.
192
- def delete_bucket_acl bucket_name, entity, user_project: nil
208
+ def delete_bucket_acl bucket_name, entity, user_project: nil, options: {}
193
209
  execute do
194
210
  service.delete_bucket_access_control \
195
- bucket_name, entity, user_project: user_project(user_project)
211
+ bucket_name, entity, user_project: user_project(user_project),
212
+ options: options
196
213
  end
197
214
  end
198
215
 
199
216
  ##
200
217
  # Retrieves a list of default ACLs for the given bucket.
201
- def list_default_acls bucket_name, user_project: nil
218
+ def list_default_acls bucket_name, user_project: nil, options: {}
202
219
  execute do
203
220
  service.list_default_object_access_controls \
204
- bucket_name, user_project: user_project(user_project)
221
+ bucket_name, user_project: user_project(user_project),
222
+ options: options
205
223
  end
206
224
  end
207
225
 
208
226
  ##
209
227
  # Creates a new default ACL.
210
- def insert_default_acl bucket_name, entity, role, user_project: nil
228
+ def insert_default_acl bucket_name, entity, role, user_project: nil, options: {}
211
229
  param = { entity: entity, role: role }.delete_if { |_k, v| v.nil? }
212
230
  new_acl = Google::Apis::StorageV1::ObjectAccessControl.new(**param)
213
231
  execute do
214
232
  service.insert_default_object_access_control \
215
- bucket_name, new_acl, user_project: user_project(user_project)
233
+ bucket_name, new_acl, user_project: user_project(user_project),
234
+ options: options
216
235
  end
217
236
  end
218
237
 
219
238
  ##
220
239
  # Permanently deletes a default ACL.
221
- def delete_default_acl bucket_name, entity, user_project: nil
240
+ def delete_default_acl bucket_name, entity, user_project: nil, options: {}
222
241
  execute do
223
242
  service.delete_default_object_access_control \
224
- bucket_name, entity, user_project: user_project(user_project)
243
+ bucket_name, entity, user_project: user_project(user_project),
244
+ options: options
225
245
  end
226
246
  end
227
247
 
228
248
  ##
229
249
  # Returns Google::Apis::StorageV1::Policy
230
- def get_bucket_policy bucket_name, requested_policy_version: nil, user_project: nil
250
+ def get_bucket_policy bucket_name, requested_policy_version: nil, user_project: nil,
251
+ options: {}
231
252
  # get_bucket_iam_policy(bucket, fields: nil, quota_user: nil,
232
253
  # user_ip: nil, options: nil)
233
254
  execute do
234
255
  service.get_bucket_iam_policy bucket_name, options_requested_policy_version: requested_policy_version,
235
- user_project: user_project(user_project)
256
+ user_project: user_project(user_project), options: options
236
257
  end
237
258
  end
238
259
 
239
260
  ##
240
261
  # Returns Google::Apis::StorageV1::Policy
241
- def set_bucket_policy bucket_name, new_policy, user_project: nil
262
+ def set_bucket_policy bucket_name, new_policy, user_project: nil, options: {}
242
263
  execute do
243
264
  service.set_bucket_iam_policy \
244
- bucket_name, new_policy, user_project: user_project(user_project)
265
+ bucket_name, new_policy, user_project: user_project(user_project), options: options
245
266
  end
246
267
  end
247
268
 
248
269
  ##
249
270
  # Returns Google::Apis::StorageV1::TestIamPermissionsResponse
250
- def test_bucket_permissions bucket_name, permissions, user_project: nil
271
+ def test_bucket_permissions bucket_name, permissions, user_project: nil, options: {}
251
272
  execute do
252
273
  service.test_bucket_iam_permissions \
253
- bucket_name, permissions, user_project: user_project(user_project)
274
+ bucket_name, permissions, user_project: user_project(user_project),
275
+ options: options
254
276
  end
255
277
  end
256
278
 
257
279
  ##
258
280
  # Retrieves a list of Pub/Sub notification subscriptions for a bucket.
259
- def list_notifications bucket_name, user_project: nil
281
+ def list_notifications bucket_name, user_project: nil, options: {}
260
282
  execute do
261
283
  service.list_notifications bucket_name,
262
- user_project: user_project(user_project)
284
+ user_project: user_project(user_project),
285
+ options: options
263
286
  end
264
287
  end
265
288
 
@@ -267,7 +290,7 @@ module Google
267
290
  # Creates a new Pub/Sub notification subscription for a bucket.
268
291
  def insert_notification bucket_name, topic_name, custom_attrs: nil,
269
292
  event_types: nil, prefix: nil, payload: nil,
270
- user_project: nil
293
+ user_project: nil, options: {}
271
294
  params =
272
295
  { custom_attributes: custom_attrs,
273
296
  event_types: event_types(event_types),
@@ -279,38 +302,43 @@ module Google
279
302
  execute do
280
303
  service.insert_notification \
281
304
  bucket_name, new_notification,
282
- user_project: user_project(user_project)
305
+ user_project: user_project(user_project),
306
+ options: options
283
307
  end
284
308
  end
285
309
 
286
310
  ##
287
311
  # Retrieves a Pub/Sub notification subscription for a bucket.
288
- def get_notification bucket_name, notification_id, user_project: nil
312
+ def get_notification bucket_name, notification_id, user_project: nil, options: {}
289
313
  execute do
290
314
  service.get_notification bucket_name, notification_id,
291
- user_project: user_project(user_project)
315
+ user_project: user_project(user_project),
316
+ options: options
292
317
  end
293
318
  end
294
319
 
295
320
  ##
296
321
  # Deletes a new Pub/Sub notification subscription for a bucket.
297
- def delete_notification bucket_name, notification_id, user_project: nil
322
+ def delete_notification bucket_name, notification_id, user_project: nil, options: {}
298
323
  execute do
299
324
  service.delete_notification bucket_name, notification_id,
300
- user_project: user_project(user_project)
325
+ user_project: user_project(user_project),
326
+ options: options
301
327
  end
302
328
  end
303
329
 
304
330
  ##
305
331
  # Retrieves a list of files matching the criteria.
306
332
  def list_files bucket_name, delimiter: nil, max: nil, token: nil,
307
- prefix: nil, versions: nil, user_project: nil
333
+ prefix: nil, versions: nil, user_project: nil,
334
+ options: {}
308
335
  execute do
309
336
  service.list_objects \
310
337
  bucket_name, delimiter: delimiter, max_results: max,
311
338
  page_token: token, prefix: prefix,
312
339
  versions: versions,
313
- user_project: user_project(user_project)
340
+ user_project: user_project(user_project),
341
+ options: options
314
342
  end
315
343
  end
316
344
 
@@ -338,7 +366,8 @@ module Google
338
366
  if_generation_not_match: nil,
339
367
  if_metageneration_match: nil,
340
368
  if_metageneration_not_match: nil,
341
- user_project: nil
369
+ user_project: nil,
370
+ options: {}
342
371
  params = {
343
372
  cache_control: cache_control,
344
373
  content_type: content_type,
@@ -356,6 +385,13 @@ module Google
356
385
  file_obj = Google::Apis::StorageV1::Object.new(**params)
357
386
  content_type ||= mime_type_for(path || Pathname(source).to_path)
358
387
 
388
+ if options[:retry].nil?
389
+ is_idempotent = retry? if_generation_match: if_generation_match
390
+ options = is_idempotent ? key_options(key) : key_options(key).merge(retries: 0)
391
+ else
392
+ options = key_options(key).merge options
393
+ end
394
+
359
395
  execute do
360
396
  service.insert_object bucket_name,
361
397
  file_obj,
@@ -370,7 +406,7 @@ module Google
370
406
  if_metageneration_not_match: if_metageneration_not_match,
371
407
  kms_key_name: kms_key,
372
408
  user_project: user_project(user_project),
373
- options: key_options(key)
409
+ options: options
374
410
  end
375
411
  end
376
412
 
@@ -384,7 +420,8 @@ module Google
384
420
  if_metageneration_match: nil,
385
421
  if_metageneration_not_match: nil,
386
422
  key: nil,
387
- user_project: nil
423
+ user_project: nil,
424
+ options: {}
388
425
  execute do
389
426
  service.get_object \
390
427
  bucket_name, file_path,
@@ -394,7 +431,7 @@ module Google
394
431
  if_metageneration_match: if_metageneration_match,
395
432
  if_metageneration_not_match: if_metageneration_not_match,
396
433
  user_project: user_project(user_project),
397
- options: key_options(key)
434
+ options: key_options(key).merge(options)
398
435
  end
399
436
  end
400
437
 
@@ -419,8 +456,17 @@ module Google
419
456
  if_source_metageneration_match: nil,
420
457
  if_source_metageneration_not_match: nil,
421
458
  token: nil,
422
- user_project: nil
459
+ user_project: nil,
460
+ options: {}
423
461
  key_options = rewrite_key_options source_key, destination_key
462
+
463
+ if options[:retry].nil?
464
+ is_idempotent = retry? if_generation_match: if_generation_match
465
+ options = is_idempotent ? key_options : key_options.merge(retries: 0)
466
+ else
467
+ options = key_options.merge options
468
+ end
469
+
424
470
  execute do
425
471
  service.rewrite_object source_bucket_name,
426
472
  source_file_path,
@@ -440,7 +486,7 @@ module Google
440
486
  if_source_metageneration_not_match: if_source_metageneration_not_match,
441
487
  rewrite_token: token,
442
488
  user_project: user_project(user_project),
443
- options: key_options
489
+ options: options
444
490
  end
445
491
  end
446
492
 
@@ -455,12 +501,20 @@ module Google
455
501
  if_source_generation_match: nil,
456
502
  if_generation_match: nil,
457
503
  if_metageneration_match: nil,
458
- user_project: nil
504
+ user_project: nil,
505
+ options: {}
459
506
 
460
507
  source_objects = compose_file_source_objects source_files, if_source_generation_match
461
508
  compose_req = Google::Apis::StorageV1::ComposeRequest.new source_objects: source_objects,
462
509
  destination: destination_gapi
463
510
 
511
+ if options[:retry].nil?
512
+ is_idempotent = retry? if_generation_match: if_generation_match
513
+ options = is_idempotent ? key_options(key) : key_options(key).merge(retries: 0)
514
+ else
515
+ options = key_options.merge options
516
+ end
517
+
464
518
  execute do
465
519
  service.compose_object bucket_name,
466
520
  destination_path,
@@ -469,7 +523,7 @@ module Google
469
523
  if_generation_match: if_generation_match,
470
524
  if_metageneration_match: if_metageneration_match,
471
525
  user_project: user_project(user_project),
472
- options: key_options(key)
526
+ options: options
473
527
  end
474
528
  end
475
529
 
@@ -483,8 +537,8 @@ module Google
483
537
  # Apis::StorageV1::StorageService and Apis::Core::DownloadCommand at
484
538
  # the end of this file.
485
539
  def download_file bucket_name, file_path, target_path, generation: nil,
486
- key: nil, range: nil, user_project: nil
487
- options = key_options key
540
+ key: nil, range: nil, user_project: nil, options: {}
541
+ options = key_options(key).merge(options)
488
542
  options = range_header options, range
489
543
 
490
544
  execute do
@@ -507,8 +561,15 @@ module Google
507
561
  if_metageneration_match: nil,
508
562
  if_metageneration_not_match: nil,
509
563
  predefined_acl: nil,
510
- user_project: nil
564
+ user_project: nil,
565
+ options: {}
511
566
  file_gapi ||= Google::Apis::StorageV1::Object.new
567
+
568
+ if options[:retry].nil?
569
+ is_idempotent = retry? if_metageneration_match: if_metageneration_match
570
+ options = is_idempotent ? {} : { retries: 0 }
571
+ end
572
+
512
573
  execute do
513
574
  service.patch_object bucket_name,
514
575
  file_path,
@@ -519,7 +580,8 @@ module Google
519
580
  if_metageneration_match: if_metageneration_match,
520
581
  if_metageneration_not_match: if_metageneration_not_match,
521
582
  predefined_acl: predefined_acl,
522
- user_project: user_project(user_project)
583
+ user_project: user_project(user_project),
584
+ options: options
523
585
  end
524
586
  end
525
587
 
@@ -532,7 +594,14 @@ module Google
532
594
  if_generation_not_match: nil,
533
595
  if_metageneration_match: nil,
534
596
  if_metageneration_not_match: nil,
535
- user_project: nil
597
+ user_project: nil,
598
+ options: {}
599
+
600
+ if options[:retry].nil?
601
+ is_idempotent = retry? generation: generation, if_generation_match: if_generation_match
602
+ options = is_idempotent ? {} : { retries: 0 }
603
+ end
604
+
536
605
  execute do
537
606
  service.delete_object bucket_name, file_path,
538
607
  generation: generation,
@@ -540,40 +609,45 @@ module Google
540
609
  if_generation_not_match: if_generation_not_match,
541
610
  if_metageneration_match: if_metageneration_match,
542
611
  if_metageneration_not_match: if_metageneration_not_match,
543
- user_project: user_project(user_project)
612
+ user_project: user_project(user_project),
613
+ options: options
544
614
  end
545
615
  end
546
616
 
547
617
  ##
548
618
  # Retrieves a list of ACLs for the given file.
549
- def list_file_acls bucket_name, file_name, user_project: nil
619
+ def list_file_acls bucket_name, file_name, user_project: nil, options: {}
550
620
  execute do
551
621
  service.list_object_access_controls \
552
- bucket_name, file_name, user_project: user_project(user_project)
622
+ bucket_name, file_name, user_project: user_project(user_project),
623
+ options: options
553
624
  end
554
625
  end
555
626
 
556
627
  ##
557
628
  # Creates a new file ACL.
558
629
  def insert_file_acl bucket_name, file_name, entity, role,
559
- generation: nil, user_project: nil
630
+ generation: nil, user_project: nil,
631
+ options: {}
560
632
  params = { entity: entity, role: role }.delete_if { |_k, v| v.nil? }
561
633
  new_acl = Google::Apis::StorageV1::ObjectAccessControl.new(**params)
562
634
  execute do
563
635
  service.insert_object_access_control \
564
636
  bucket_name, file_name, new_acl,
565
- generation: generation, user_project: user_project(user_project)
637
+ generation: generation, user_project: user_project(user_project),
638
+ options: options
566
639
  end
567
640
  end
568
641
 
569
642
  ##
570
643
  # Permanently deletes a file ACL.
571
644
  def delete_file_acl bucket_name, file_name, entity, generation: nil,
572
- user_project: nil
645
+ user_project: nil, options: {}
573
646
  execute do
574
647
  service.delete_object_access_control \
575
648
  bucket_name, file_name, entity,
576
- generation: generation, user_project: user_project(user_project)
649
+ generation: generation, user_project: user_project(user_project),
650
+ options: options
577
651
  end
578
652
  end
579
653
 
@@ -581,32 +655,37 @@ module Google
581
655
  # Creates a new HMAC key for the specified service account.
582
656
  # Returns Google::Apis::StorageV1::HmacKey.
583
657
  def create_hmac_key service_account_email, project_id: nil,
584
- user_project: nil
658
+ user_project: nil, options: {}
585
659
  execute do
586
660
  service.create_project_hmac_key \
587
661
  (project_id || @project), service_account_email,
588
- user_project: user_project(user_project)
662
+ user_project: user_project(user_project),
663
+ options: options
589
664
  end
590
665
  end
591
666
 
592
667
  ##
593
668
  # Deletes an HMAC key. Key must be in the INACTIVE state.
594
- def delete_hmac_key access_id, project_id: nil, user_project: nil
669
+ def delete_hmac_key access_id, project_id: nil, user_project: nil,
670
+ options: {}
595
671
  execute do
596
672
  service.delete_project_hmac_key \
597
673
  (project_id || @project), access_id,
598
- user_project: user_project(user_project)
674
+ user_project: user_project(user_project),
675
+ options: options
599
676
  end
600
677
  end
601
678
 
602
679
  ##
603
680
  # Retrieves an HMAC key's metadata.
604
681
  # Returns Google::Apis::StorageV1::HmacKeyMetadata.
605
- def get_hmac_key access_id, project_id: nil, user_project: nil
682
+ def get_hmac_key access_id, project_id: nil, user_project: nil,
683
+ options: {}
606
684
  execute do
607
685
  service.get_project_hmac_key \
608
686
  (project_id || @project), access_id,
609
- user_project: user_project(user_project)
687
+ user_project: user_project(user_project),
688
+ options: options
610
689
  end
611
690
  end
612
691
 
@@ -615,14 +694,15 @@ module Google
615
694
  # Returns Google::Apis::StorageV1::HmacKeysMetadata.
616
695
  def list_hmac_keys max: nil, token: nil, service_account_email: nil,
617
696
  project_id: nil, show_deleted_keys: nil,
618
- user_project: nil
697
+ user_project: nil, options: {}
619
698
  execute do
620
699
  service.list_project_hmac_keys \
621
700
  (project_id || @project),
622
701
  max_results: max, page_token: token,
623
702
  service_account_email: service_account_email,
624
703
  show_deleted_keys: show_deleted_keys,
625
- user_project: user_project(user_project)
704
+ user_project: user_project(user_project),
705
+ options: options
626
706
  end
627
707
  end
628
708
 
@@ -631,11 +711,13 @@ module Google
631
711
  # for valid states.
632
712
  # Returns Google::Apis::StorageV1::HmacKeyMetadata.
633
713
  def update_hmac_key access_id, hmac_key_metadata_object,
634
- project_id: nil, user_project: nil
714
+ project_id: nil, user_project: nil,
715
+ options: {}
635
716
  execute do
636
717
  service.update_project_hmac_key \
637
718
  (project_id || @project), access_id, hmac_key_metadata_object,
638
- user_project: user_project(user_project)
719
+ user_project: user_project(user_project),
720
+ options: options
639
721
  end
640
722
  end
641
723
 
@@ -771,6 +853,10 @@ module Google
771
853
  rescue Google::Apis::Error => e
772
854
  raise Google::Cloud::Error.from_error(e)
773
855
  end
856
+
857
+ def retry? query_params
858
+ query_params.any? { |_key, val| !val.nil? }
859
+ end
774
860
  end
775
861
  end
776
862
  end
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Storage
19
- VERSION = "1.38.0".freeze
19
+ VERSION = "1.40.0".freeze
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.38.0
4
+ version: 1.40.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-08-01 00:00:00.000000000 Z
12
+ date: 2022-09-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core