google-cloud-storage 1.36.2 → 1.41.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,9 +38,12 @@ module Google
38
38
 
39
39
  ##
40
40
  # Creates a new Service instance.
41
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
41
42
  def initialize project, credentials, retries: nil,
42
43
  timeout: nil, open_timeout: nil, read_timeout: nil,
43
- send_timeout: nil, host: nil, quota_project: nil
44
+ send_timeout: nil, host: nil, quota_project: nil,
45
+ max_elapsed_time: nil, base_interval: nil, max_interval: nil,
46
+ multiplier: nil
44
47
  @project = project
45
48
  @credentials = credentials
46
49
  @service = API::StorageService.new
@@ -57,9 +60,14 @@ module Google
57
60
  "gl-ruby/#{RUBY_VERSION} gccl/#{Google::Cloud::Storage::VERSION}"
58
61
  @service.request_options.header["Accept-Encoding"] = "gzip"
59
62
  @service.request_options.quota_project = quota_project if quota_project
63
+ @service.request_options.max_elapsed_time = max_elapsed_time if max_elapsed_time
64
+ @service.request_options.base_interval = base_interval if base_interval
65
+ @service.request_options.max_interval = max_interval if max_interval
66
+ @service.request_options.multiplier = multiplier if multiplier
60
67
  @service.authorization = @credentials.client if @credentials
61
68
  @service.root_url = host if host
62
69
  end
70
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
63
71
 
64
72
  def service
65
73
  return mocked_service if mocked_service
@@ -73,11 +81,11 @@ module Google
73
81
 
74
82
  ##
75
83
  # Retrieves a list of buckets for the given project.
76
- 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: {}
77
85
  execute do
78
86
  service.list_buckets \
79
87
  @project, prefix: prefix, page_token: token, max_results: max,
80
- user_project: user_project(user_project)
88
+ user_project: user_project(user_project), options: options
81
89
  end
82
90
  end
83
91
 
@@ -87,12 +95,14 @@ module Google
87
95
  def get_bucket bucket_name,
88
96
  if_metageneration_match: nil,
89
97
  if_metageneration_not_match: nil,
90
- user_project: nil
98
+ user_project: nil,
99
+ options: {}
91
100
  execute do
92
101
  service.get_bucket bucket_name,
93
102
  if_metageneration_match: if_metageneration_match,
94
103
  if_metageneration_not_match: if_metageneration_not_match,
95
- user_project: user_project(user_project)
104
+ user_project: user_project(user_project),
105
+ options: options
96
106
  end
97
107
  end
98
108
 
@@ -100,13 +110,14 @@ module Google
100
110
  # Creates a new bucket.
101
111
  # Returns Google::Apis::StorageV1::Bucket.
102
112
  def insert_bucket bucket_gapi, acl: nil, default_acl: nil,
103
- user_project: nil
113
+ user_project: nil, options: {}
104
114
  execute do
105
115
  service.insert_bucket \
106
116
  @project, bucket_gapi,
107
117
  predefined_acl: acl,
108
118
  predefined_default_object_acl: default_acl,
109
- user_project: user_project(user_project)
119
+ user_project: user_project(user_project),
120
+ options: options
110
121
  end
111
122
  end
112
123
 
@@ -118,11 +129,17 @@ module Google
118
129
  predefined_default_acl: nil,
119
130
  if_metageneration_match: nil,
120
131
  if_metageneration_not_match: nil,
121
- user_project: nil
132
+ user_project: nil,
133
+ options: {}
122
134
  bucket_gapi ||= Google::Apis::StorageV1::Bucket.new
123
135
  bucket_gapi.acl = [] if predefined_acl
124
136
  bucket_gapi.default_object_acl = [] if predefined_default_acl
125
137
 
138
+ if options[:retries].nil?
139
+ is_idempotent = retry? if_metageneration_match: if_metageneration_match
140
+ options = is_idempotent ? {} : { retries: 0 }
141
+ end
142
+
126
143
  execute do
127
144
  service.patch_bucket bucket_name,
128
145
  bucket_gapi,
@@ -130,7 +147,8 @@ module Google
130
147
  predefined_default_object_acl: predefined_default_acl,
131
148
  if_metageneration_match: if_metageneration_match,
132
149
  if_metageneration_not_match: if_metageneration_not_match,
133
- user_project: user_project(user_project)
150
+ user_project: user_project(user_project),
151
+ options: options
134
152
  end
135
153
  end
136
154
 
@@ -139,119 +157,144 @@ module Google
139
157
  def delete_bucket bucket_name,
140
158
  if_metageneration_match: nil,
141
159
  if_metageneration_not_match: nil,
142
- user_project: nil
160
+ user_project: nil,
161
+ options: {}
143
162
  execute do
144
163
  service.delete_bucket bucket_name,
145
164
  if_metageneration_match: if_metageneration_match,
146
165
  if_metageneration_not_match: if_metageneration_not_match,
147
- user_project: user_project(user_project)
166
+ user_project: user_project(user_project),
167
+ options: options
148
168
  end
149
169
  end
150
170
 
151
171
  ##
152
172
  # Locks retention policy on a bucket.
153
173
  def lock_bucket_retention_policy bucket_name, metageneration,
154
- user_project: nil
174
+ user_project: nil,
175
+ options: {}
155
176
  execute do
156
177
  service.lock_bucket_retention_policy \
157
178
  bucket_name, metageneration,
158
- user_project: user_project(user_project)
179
+ user_project: user_project(user_project),
180
+ options: options
159
181
  end
160
182
  end
161
183
 
162
184
  ##
163
185
  # Retrieves a list of ACLs for the given bucket.
164
- def list_bucket_acls bucket_name, user_project: nil
186
+ def list_bucket_acls bucket_name, user_project: nil, options: {}
165
187
  execute do
166
188
  service.list_bucket_access_controls \
167
- bucket_name, user_project: user_project(user_project)
189
+ bucket_name, user_project: user_project(user_project),
190
+ options: options
168
191
  end
169
192
  end
170
193
 
171
194
  ##
172
195
  # Creates a new bucket ACL.
173
- def insert_bucket_acl bucket_name, entity, role, user_project: nil
196
+ def insert_bucket_acl bucket_name, entity, role, user_project: nil, options: {}
174
197
  params = { entity: entity, role: role }.delete_if { |_k, v| v.nil? }
175
198
  new_acl = Google::Apis::StorageV1::BucketAccessControl.new(**params)
199
+ if options[:retries].nil?
200
+ options = options.merge({ retries: 0 })
201
+ end
176
202
  execute do
177
203
  service.insert_bucket_access_control \
178
- bucket_name, new_acl, user_project: user_project(user_project)
204
+ bucket_name, new_acl, user_project: user_project(user_project),
205
+ options: options
179
206
  end
180
207
  end
181
208
 
182
209
  ##
183
210
  # Permanently deletes a bucket ACL.
184
- def delete_bucket_acl bucket_name, entity, user_project: nil
211
+ def delete_bucket_acl bucket_name, entity, user_project: nil, options: {}
212
+ if options[:retries].nil?
213
+ options = options.merge({ retries: 0 })
214
+ end
185
215
  execute do
186
216
  service.delete_bucket_access_control \
187
- bucket_name, entity, user_project: user_project(user_project)
217
+ bucket_name, entity, user_project: user_project(user_project),
218
+ options: options
188
219
  end
189
220
  end
190
221
 
191
222
  ##
192
223
  # Retrieves a list of default ACLs for the given bucket.
193
- def list_default_acls bucket_name, user_project: nil
224
+ def list_default_acls bucket_name, user_project: nil, options: {}
194
225
  execute do
195
226
  service.list_default_object_access_controls \
196
- bucket_name, user_project: user_project(user_project)
227
+ bucket_name, user_project: user_project(user_project),
228
+ options: options
197
229
  end
198
230
  end
199
231
 
200
232
  ##
201
233
  # Creates a new default ACL.
202
- def insert_default_acl bucket_name, entity, role, user_project: nil
234
+ def insert_default_acl bucket_name, entity, role, user_project: nil, options: {}
235
+ if options[:retries].nil?
236
+ options = options.merge({ retries: 0 })
237
+ end
203
238
  param = { entity: entity, role: role }.delete_if { |_k, v| v.nil? }
204
239
  new_acl = Google::Apis::StorageV1::ObjectAccessControl.new(**param)
205
240
  execute do
206
241
  service.insert_default_object_access_control \
207
- bucket_name, new_acl, user_project: user_project(user_project)
242
+ bucket_name, new_acl, user_project: user_project(user_project),
243
+ options: options
208
244
  end
209
245
  end
210
246
 
211
247
  ##
212
248
  # Permanently deletes a default ACL.
213
- def delete_default_acl bucket_name, entity, user_project: nil
249
+ def delete_default_acl bucket_name, entity, user_project: nil, options: {}
250
+ if options[:retries].nil?
251
+ options = options.merge({ retries: 0 })
252
+ end
214
253
  execute do
215
254
  service.delete_default_object_access_control \
216
- bucket_name, entity, user_project: user_project(user_project)
255
+ bucket_name, entity, user_project: user_project(user_project),
256
+ options: options
217
257
  end
218
258
  end
219
259
 
220
260
  ##
221
261
  # Returns Google::Apis::StorageV1::Policy
222
- def get_bucket_policy bucket_name, requested_policy_version: nil, user_project: nil
262
+ def get_bucket_policy bucket_name, requested_policy_version: nil, user_project: nil,
263
+ options: {}
223
264
  # get_bucket_iam_policy(bucket, fields: nil, quota_user: nil,
224
265
  # user_ip: nil, options: nil)
225
266
  execute do
226
267
  service.get_bucket_iam_policy bucket_name, options_requested_policy_version: requested_policy_version,
227
- user_project: user_project(user_project)
268
+ user_project: user_project(user_project), options: options
228
269
  end
229
270
  end
230
271
 
231
272
  ##
232
273
  # Returns Google::Apis::StorageV1::Policy
233
- def set_bucket_policy bucket_name, new_policy, user_project: nil
274
+ def set_bucket_policy bucket_name, new_policy, user_project: nil, options: {}
234
275
  execute do
235
276
  service.set_bucket_iam_policy \
236
- bucket_name, new_policy, user_project: user_project(user_project)
277
+ bucket_name, new_policy, user_project: user_project(user_project), options: options
237
278
  end
238
279
  end
239
280
 
240
281
  ##
241
282
  # Returns Google::Apis::StorageV1::TestIamPermissionsResponse
242
- def test_bucket_permissions bucket_name, permissions, user_project: nil
283
+ def test_bucket_permissions bucket_name, permissions, user_project: nil, options: {}
243
284
  execute do
244
285
  service.test_bucket_iam_permissions \
245
- bucket_name, permissions, user_project: user_project(user_project)
286
+ bucket_name, permissions, user_project: user_project(user_project),
287
+ options: options
246
288
  end
247
289
  end
248
290
 
249
291
  ##
250
292
  # Retrieves a list of Pub/Sub notification subscriptions for a bucket.
251
- def list_notifications bucket_name, user_project: nil
293
+ def list_notifications bucket_name, user_project: nil, options: {}
252
294
  execute do
253
295
  service.list_notifications bucket_name,
254
- user_project: user_project(user_project)
296
+ user_project: user_project(user_project),
297
+ options: options
255
298
  end
256
299
  end
257
300
 
@@ -259,7 +302,7 @@ module Google
259
302
  # Creates a new Pub/Sub notification subscription for a bucket.
260
303
  def insert_notification bucket_name, topic_name, custom_attrs: nil,
261
304
  event_types: nil, prefix: nil, payload: nil,
262
- user_project: nil
305
+ user_project: nil, options: {}
263
306
  params =
264
307
  { custom_attributes: custom_attrs,
265
308
  event_types: event_types(event_types),
@@ -268,41 +311,50 @@ module Google
268
311
  topic: topic_path(topic_name) }.delete_if { |_k, v| v.nil? }
269
312
  new_notification = Google::Apis::StorageV1::Notification.new(**params)
270
313
 
314
+ if options[:retries].nil?
315
+ options = options.merge({ retries: 0 })
316
+ end
317
+
271
318
  execute do
272
319
  service.insert_notification \
273
320
  bucket_name, new_notification,
274
- user_project: user_project(user_project)
321
+ user_project: user_project(user_project),
322
+ options: options
275
323
  end
276
324
  end
277
325
 
278
326
  ##
279
327
  # Retrieves a Pub/Sub notification subscription for a bucket.
280
- def get_notification bucket_name, notification_id, user_project: nil
328
+ def get_notification bucket_name, notification_id, user_project: nil, options: {}
281
329
  execute do
282
330
  service.get_notification bucket_name, notification_id,
283
- user_project: user_project(user_project)
331
+ user_project: user_project(user_project),
332
+ options: options
284
333
  end
285
334
  end
286
335
 
287
336
  ##
288
337
  # Deletes a new Pub/Sub notification subscription for a bucket.
289
- def delete_notification bucket_name, notification_id, user_project: nil
338
+ def delete_notification bucket_name, notification_id, user_project: nil, options: {}
290
339
  execute do
291
340
  service.delete_notification bucket_name, notification_id,
292
- user_project: user_project(user_project)
341
+ user_project: user_project(user_project),
342
+ options: options
293
343
  end
294
344
  end
295
345
 
296
346
  ##
297
347
  # Retrieves a list of files matching the criteria.
298
348
  def list_files bucket_name, delimiter: nil, max: nil, token: nil,
299
- prefix: nil, versions: nil, user_project: nil
349
+ prefix: nil, versions: nil, user_project: nil,
350
+ options: {}
300
351
  execute do
301
352
  service.list_objects \
302
353
  bucket_name, delimiter: delimiter, max_results: max,
303
354
  page_token: token, prefix: prefix,
304
355
  versions: versions,
305
- user_project: user_project(user_project)
356
+ user_project: user_project(user_project),
357
+ options: options
306
358
  end
307
359
  end
308
360
 
@@ -330,7 +382,8 @@ module Google
330
382
  if_generation_not_match: nil,
331
383
  if_metageneration_match: nil,
332
384
  if_metageneration_not_match: nil,
333
- user_project: nil
385
+ user_project: nil,
386
+ options: {}
334
387
  params = {
335
388
  cache_control: cache_control,
336
389
  content_type: content_type,
@@ -348,6 +401,13 @@ module Google
348
401
  file_obj = Google::Apis::StorageV1::Object.new(**params)
349
402
  content_type ||= mime_type_for(path || Pathname(source).to_path)
350
403
 
404
+ if options[:retries].nil?
405
+ is_idempotent = retry? if_generation_match: if_generation_match
406
+ options = is_idempotent ? key_options(key) : key_options(key).merge(retries: 0)
407
+ else
408
+ options = key_options(key).merge options
409
+ end
410
+
351
411
  execute do
352
412
  service.insert_object bucket_name,
353
413
  file_obj,
@@ -362,7 +422,7 @@ module Google
362
422
  if_metageneration_not_match: if_metageneration_not_match,
363
423
  kms_key_name: kms_key,
364
424
  user_project: user_project(user_project),
365
- options: key_options(key)
425
+ options: options
366
426
  end
367
427
  end
368
428
 
@@ -376,7 +436,8 @@ module Google
376
436
  if_metageneration_match: nil,
377
437
  if_metageneration_not_match: nil,
378
438
  key: nil,
379
- user_project: nil
439
+ user_project: nil,
440
+ options: {}
380
441
  execute do
381
442
  service.get_object \
382
443
  bucket_name, file_path,
@@ -386,7 +447,7 @@ module Google
386
447
  if_metageneration_match: if_metageneration_match,
387
448
  if_metageneration_not_match: if_metageneration_not_match,
388
449
  user_project: user_project(user_project),
389
- options: key_options(key)
450
+ options: key_options(key).merge(options)
390
451
  end
391
452
  end
392
453
 
@@ -411,8 +472,17 @@ module Google
411
472
  if_source_metageneration_match: nil,
412
473
  if_source_metageneration_not_match: nil,
413
474
  token: nil,
414
- user_project: nil
475
+ user_project: nil,
476
+ options: {}
415
477
  key_options = rewrite_key_options source_key, destination_key
478
+
479
+ if options[:retries].nil?
480
+ is_idempotent = retry? if_generation_match: if_generation_match
481
+ options = is_idempotent ? key_options : key_options.merge(retries: 0)
482
+ else
483
+ options = key_options.merge options
484
+ end
485
+
416
486
  execute do
417
487
  service.rewrite_object source_bucket_name,
418
488
  source_file_path,
@@ -432,7 +502,7 @@ module Google
432
502
  if_source_metageneration_not_match: if_source_metageneration_not_match,
433
503
  rewrite_token: token,
434
504
  user_project: user_project(user_project),
435
- options: key_options
505
+ options: options
436
506
  end
437
507
  end
438
508
 
@@ -447,12 +517,20 @@ module Google
447
517
  if_source_generation_match: nil,
448
518
  if_generation_match: nil,
449
519
  if_metageneration_match: nil,
450
- user_project: nil
520
+ user_project: nil,
521
+ options: {}
451
522
 
452
523
  source_objects = compose_file_source_objects source_files, if_source_generation_match
453
524
  compose_req = Google::Apis::StorageV1::ComposeRequest.new source_objects: source_objects,
454
525
  destination: destination_gapi
455
526
 
527
+ if options[:retries].nil?
528
+ is_idempotent = retry? if_generation_match: if_generation_match
529
+ options = is_idempotent ? key_options(key) : key_options(key).merge(retries: 0)
530
+ else
531
+ options = key_options.merge options
532
+ end
533
+
456
534
  execute do
457
535
  service.compose_object bucket_name,
458
536
  destination_path,
@@ -461,7 +539,7 @@ module Google
461
539
  if_generation_match: if_generation_match,
462
540
  if_metageneration_match: if_metageneration_match,
463
541
  user_project: user_project(user_project),
464
- options: key_options(key)
542
+ options: options
465
543
  end
466
544
  end
467
545
 
@@ -475,12 +553,12 @@ module Google
475
553
  # Apis::StorageV1::StorageService and Apis::Core::DownloadCommand at
476
554
  # the end of this file.
477
555
  def download_file bucket_name, file_path, target_path, generation: nil,
478
- key: nil, range: nil, user_project: nil
479
- options = key_options key
556
+ key: nil, range: nil, user_project: nil, options: {}
557
+ options = key_options(key).merge(options)
480
558
  options = range_header options, range
481
559
 
482
560
  execute do
483
- service.get_object_with_response \
561
+ service.get_object \
484
562
  bucket_name, file_path,
485
563
  download_dest: target_path, generation: generation,
486
564
  user_project: user_project(user_project),
@@ -499,8 +577,15 @@ module Google
499
577
  if_metageneration_match: nil,
500
578
  if_metageneration_not_match: nil,
501
579
  predefined_acl: nil,
502
- user_project: nil
580
+ user_project: nil,
581
+ options: {}
503
582
  file_gapi ||= Google::Apis::StorageV1::Object.new
583
+
584
+ if options[:retries].nil?
585
+ is_idempotent = retry? if_metageneration_match: if_metageneration_match
586
+ options = is_idempotent ? {} : { retries: 0 }
587
+ end
588
+
504
589
  execute do
505
590
  service.patch_object bucket_name,
506
591
  file_path,
@@ -511,7 +596,8 @@ module Google
511
596
  if_metageneration_match: if_metageneration_match,
512
597
  if_metageneration_not_match: if_metageneration_not_match,
513
598
  predefined_acl: predefined_acl,
514
- user_project: user_project(user_project)
599
+ user_project: user_project(user_project),
600
+ options: options
515
601
  end
516
602
  end
517
603
 
@@ -524,7 +610,14 @@ module Google
524
610
  if_generation_not_match: nil,
525
611
  if_metageneration_match: nil,
526
612
  if_metageneration_not_match: nil,
527
- user_project: nil
613
+ user_project: nil,
614
+ options: {}
615
+
616
+ if options[:retries].nil?
617
+ is_idempotent = retry? generation: generation, if_generation_match: if_generation_match
618
+ options = is_idempotent ? {} : { retries: 0 }
619
+ end
620
+
528
621
  execute do
529
622
  service.delete_object bucket_name, file_path,
530
623
  generation: generation,
@@ -532,40 +625,51 @@ module Google
532
625
  if_generation_not_match: if_generation_not_match,
533
626
  if_metageneration_match: if_metageneration_match,
534
627
  if_metageneration_not_match: if_metageneration_not_match,
535
- user_project: user_project(user_project)
628
+ user_project: user_project(user_project),
629
+ options: options
536
630
  end
537
631
  end
538
632
 
539
633
  ##
540
634
  # Retrieves a list of ACLs for the given file.
541
- def list_file_acls bucket_name, file_name, user_project: nil
635
+ def list_file_acls bucket_name, file_name, user_project: nil, options: {}
542
636
  execute do
543
637
  service.list_object_access_controls \
544
- bucket_name, file_name, user_project: user_project(user_project)
638
+ bucket_name, file_name, user_project: user_project(user_project),
639
+ options: options
545
640
  end
546
641
  end
547
642
 
548
643
  ##
549
644
  # Creates a new file ACL.
550
645
  def insert_file_acl bucket_name, file_name, entity, role,
551
- generation: nil, user_project: nil
646
+ generation: nil, user_project: nil,
647
+ options: {}
648
+ if options[:retries].nil?
649
+ options = options.merge({ retries: 0 })
650
+ end
552
651
  params = { entity: entity, role: role }.delete_if { |_k, v| v.nil? }
553
652
  new_acl = Google::Apis::StorageV1::ObjectAccessControl.new(**params)
554
653
  execute do
555
654
  service.insert_object_access_control \
556
655
  bucket_name, file_name, new_acl,
557
- generation: generation, user_project: user_project(user_project)
656
+ generation: generation, user_project: user_project(user_project),
657
+ options: options
558
658
  end
559
659
  end
560
660
 
561
661
  ##
562
662
  # Permanently deletes a file ACL.
563
663
  def delete_file_acl bucket_name, file_name, entity, generation: nil,
564
- user_project: nil
664
+ user_project: nil, options: {}
665
+ if options[:retries].nil?
666
+ options = options.merge({ retries: 0 })
667
+ end
565
668
  execute do
566
669
  service.delete_object_access_control \
567
670
  bucket_name, file_name, entity,
568
- generation: generation, user_project: user_project(user_project)
671
+ generation: generation, user_project: user_project(user_project),
672
+ options: options
569
673
  end
570
674
  end
571
675
 
@@ -573,32 +677,42 @@ module Google
573
677
  # Creates a new HMAC key for the specified service account.
574
678
  # Returns Google::Apis::StorageV1::HmacKey.
575
679
  def create_hmac_key service_account_email, project_id: nil,
576
- user_project: nil
680
+ user_project: nil, options: {}
681
+
682
+ if options[:retries].nil?
683
+ options = options.merge({ retries: 0 })
684
+ end
685
+
577
686
  execute do
578
687
  service.create_project_hmac_key \
579
688
  (project_id || @project), service_account_email,
580
- user_project: user_project(user_project)
689
+ user_project: user_project(user_project),
690
+ options: options
581
691
  end
582
692
  end
583
693
 
584
694
  ##
585
695
  # Deletes an HMAC key. Key must be in the INACTIVE state.
586
- def delete_hmac_key access_id, project_id: nil, user_project: nil
696
+ def delete_hmac_key access_id, project_id: nil, user_project: nil,
697
+ options: {}
587
698
  execute do
588
699
  service.delete_project_hmac_key \
589
700
  (project_id || @project), access_id,
590
- user_project: user_project(user_project)
701
+ user_project: user_project(user_project),
702
+ options: options
591
703
  end
592
704
  end
593
705
 
594
706
  ##
595
707
  # Retrieves an HMAC key's metadata.
596
708
  # Returns Google::Apis::StorageV1::HmacKeyMetadata.
597
- def get_hmac_key access_id, project_id: nil, user_project: nil
709
+ def get_hmac_key access_id, project_id: nil, user_project: nil,
710
+ options: {}
598
711
  execute do
599
712
  service.get_project_hmac_key \
600
713
  (project_id || @project), access_id,
601
- user_project: user_project(user_project)
714
+ user_project: user_project(user_project),
715
+ options: options
602
716
  end
603
717
  end
604
718
 
@@ -607,14 +721,15 @@ module Google
607
721
  # Returns Google::Apis::StorageV1::HmacKeysMetadata.
608
722
  def list_hmac_keys max: nil, token: nil, service_account_email: nil,
609
723
  project_id: nil, show_deleted_keys: nil,
610
- user_project: nil
724
+ user_project: nil, options: {}
611
725
  execute do
612
726
  service.list_project_hmac_keys \
613
727
  (project_id || @project),
614
728
  max_results: max, page_token: token,
615
729
  service_account_email: service_account_email,
616
730
  show_deleted_keys: show_deleted_keys,
617
- user_project: user_project(user_project)
731
+ user_project: user_project(user_project),
732
+ options: options
618
733
  end
619
734
  end
620
735
 
@@ -623,11 +738,44 @@ module Google
623
738
  # for valid states.
624
739
  # Returns Google::Apis::StorageV1::HmacKeyMetadata.
625
740
  def update_hmac_key access_id, hmac_key_metadata_object,
626
- project_id: nil, user_project: nil
741
+ project_id: nil, user_project: nil,
742
+ options: {}
627
743
  execute do
628
744
  service.update_project_hmac_key \
629
745
  (project_id || @project), access_id, hmac_key_metadata_object,
630
- user_project: user_project(user_project)
746
+ user_project: user_project(user_project),
747
+ options: options
748
+ end
749
+ end
750
+
751
+ ##
752
+ # Updates a bucket, including its ACL metadata.
753
+ def update_bucket bucket_name,
754
+ bucket_gapi = nil,
755
+ predefined_acl: nil,
756
+ predefined_default_acl: nil,
757
+ if_metageneration_match: nil,
758
+ if_metageneration_not_match: nil,
759
+ user_project: nil,
760
+ options: {}
761
+ bucket_gapi ||= Google::Apis::StorageV1::Bucket.new
762
+ bucket_gapi.acl = [] if predefined_acl
763
+ bucket_gapi.default_object_acl = [] if predefined_default_acl
764
+
765
+ if options[:retries].nil?
766
+ is_idempotent = retry? if_metageneration_match: if_metageneration_match
767
+ options = is_idempotent ? {} : { retries: 0 }
768
+ end
769
+
770
+ execute do
771
+ service.update_bucket bucket_name,
772
+ bucket_gapi,
773
+ predefined_acl: predefined_acl,
774
+ predefined_default_object_acl: predefined_default_acl,
775
+ if_metageneration_match: if_metageneration_match,
776
+ if_metageneration_not_match: if_metageneration_not_match,
777
+ user_project: user_project(user_project),
778
+ options: options
631
779
  end
632
780
  end
633
781
 
@@ -763,163 +911,11 @@ module Google
763
911
  rescue Google::Apis::Error => e
764
912
  raise Google::Cloud::Error.from_error(e)
765
913
  end
766
- end
767
- end
768
- end
769
-
770
- # rubocop:disable all
771
-
772
- # @private
773
- #
774
- # IMPORTANT: These monkey-patches of Apis::StorageV1::StorageService and
775
- # Apis::Core::DownloadCommand must be verified and updated (if needed) for
776
- # every upgrade of google-api-client.
777
- #
778
- # The purpose of these modifications is to provide access to response headers
779
- # (in particular, the Content-Encoding header) for the #download_file method,
780
- # above. If google-api-client is modified to expose response headers to its
781
- # clients, this code should be removed, and #download_file updated to use that
782
- # solution instead.
783
- #
784
- module Apis
785
- # @private
786
- module StorageV1
787
- # @private
788
- class StorageService
789
- # Returns a two-element array containing:
790
- # * The `result` that is the usual return type of #get_object.
791
- # * The `http_resp` from DownloadCommand#execute_once.
792
- def get_object_with_response(bucket, object, generation: nil, if_generation_match: nil, if_generation_not_match: nil, if_metageneration_match: nil, if_metageneration_not_match: nil, projection: nil, user_project: nil, fields: nil, quota_user: nil, user_ip: nil, download_dest: nil, options: nil, &block)
793
- if download_dest.nil?
794
- command = make_simple_command(:get, 'b/{bucket}/o/{object}', options)
795
- else
796
- command = make_download_command(:get, 'b/{bucket}/o/{object}', options)
797
- command.download_dest = download_dest
798
- end
799
- command.response_representation = Google::Apis::StorageV1::Object::Representation
800
- command.response_class = Google::Apis::StorageV1::Object
801
- command.params['bucket'] = bucket unless bucket.nil?
802
- command.params['object'] = object unless object.nil?
803
- command.query['generation'] = generation unless generation.nil?
804
- command.query['ifGenerationMatch'] = if_generation_match unless if_generation_match.nil?
805
- command.query['ifGenerationNotMatch'] = if_generation_not_match unless if_generation_not_match.nil?
806
- command.query['ifMetagenerationMatch'] = if_metageneration_match unless if_metageneration_match.nil?
807
- command.query['ifMetagenerationNotMatch'] = if_metageneration_not_match unless if_metageneration_not_match.nil?
808
- command.query['projection'] = projection unless projection.nil?
809
- command.query['userProject'] = user_project unless user_project.nil?
810
- command.query['fields'] = fields unless fields.nil?
811
- command.query['quotaUser'] = quota_user unless quota_user.nil?
812
- command.query['userIp'] = user_ip unless user_ip.nil?
813
- execute_or_queue_command_with_response(command, &block)
814
- end
815
-
816
- # Returns a two-element array containing:
817
- # * The `result` that is the usual return type of #execute_or_queue_command.
818
- # * The `http_resp` from DownloadCommand#execute_once.
819
- def execute_or_queue_command_with_response(command, &callback)
820
- batch_command = current_batch
821
- if batch_command
822
- raise "Can not combine services in a batch" if Thread.current[:google_api_batch_service] != self
823
- batch_command.add(command, &callback)
824
- nil
825
- else
826
- command.execute_with_response(client, &callback)
827
- end
828
- end
829
- end
830
- end
831
- # @private
832
- module Core
833
- # @private
834
- # Streaming/resumable media download support
835
- class DownloadCommand < ApiCommand
836
- # Returns a two-element array containing:
837
- # * The `result` that is the usual return type of #execute.
838
- # * The `http_resp` from #execute_once.
839
- def execute_with_response(client)
840
- prepare!
841
- begin
842
- Retriable.retriable tries: options.retries + 1,
843
- base_interval: 1,
844
- multiplier: 2,
845
- on: RETRIABLE_ERRORS do |try|
846
- # This 2nd level retriable only catches auth errors, and supports 1 retry, which allows
847
- # auth to be re-attempted without having to retry all sorts of other failures like
848
- # NotFound, etc
849
- auth_tries = (try == 1 && authorization_refreshable? ? 2 : 1)
850
- Retriable.retriable tries: auth_tries,
851
- on: [Google::Apis::AuthorizationError, Signet::AuthorizationError],
852
- on_retry: proc { |*| refresh_authorization } do
853
- execute_once_with_response(client).tap do |result|
854
- if block_given?
855
- yield result, nil
856
- end
857
- end
858
- end
859
- end
860
- rescue => e
861
- if block_given?
862
- yield nil, e
863
- else
864
- raise e
865
- end
866
- end
867
- ensure
868
- release!
869
- end
870
914
 
871
- # Returns a two-element array containing:
872
- # * The `result` that is the usual return type of #execute_once.
873
- # * The `http_resp`.
874
- def execute_once_with_response(client, &block)
875
- request_header = header.dup
876
- apply_request_options(request_header)
877
- download_offset = nil
878
-
879
- if @offset > 0
880
- logger.debug { sprintf('Resuming download from offset %d', @offset) }
881
- request_header[RANGE_HEADER] = sprintf('bytes=%d-', @offset)
882
- end
883
-
884
- http_res = client.get(url.to_s,
885
- query: query,
886
- header: request_header,
887
- follow_redirect: true) do |res, chunk|
888
- status = res.http_header.status_code.to_i
889
- next unless OK_STATUS.include?(status)
890
-
891
- download_offset ||= (status == 206 ? @offset : 0)
892
- download_offset += chunk.bytesize
893
-
894
- if download_offset - chunk.bytesize == @offset
895
- next_chunk = chunk
896
- else
897
- # Oh no! Requested a chunk, but received the entire content
898
- chunk_index = @offset - (download_offset - chunk.bytesize)
899
- next_chunk = chunk.byteslice(chunk_index..-1)
900
- next if next_chunk.nil?
901
- end
902
- # logger.debug { sprintf('Writing chunk (%d bytes, %d total)', chunk.length, bytes_read) }
903
- @download_io.write(next_chunk)
904
-
905
- @offset += next_chunk.bytesize
906
- end
907
-
908
- @download_io.flush
909
-
910
- if @close_io_on_finish
911
- result = nil
912
- else
913
- result = @download_io
914
- end
915
- check_status(http_res.status.to_i, http_res.header, http_res.body)
916
- success([result, http_res], &block)
917
- rescue => e
918
- @download_io.flush
919
- error(e, rethrow: true, &block)
915
+ def retry? query_params
916
+ query_params.any? { |_key, val| !val.nil? }
920
917
  end
921
918
  end
922
919
  end
923
920
  end
924
- # rubocop:enable all
925
921
  end