google-cloud-storage 1.36.2 → 1.44.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.
@@ -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,15 @@ 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
67
+ @service.request_options.add_invocation_id_header = true
60
68
  @service.authorization = @credentials.client if @credentials
61
69
  @service.root_url = host if host
62
70
  end
71
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
63
72
 
64
73
  def service
65
74
  return mocked_service if mocked_service
@@ -73,11 +82,11 @@ module Google
73
82
 
74
83
  ##
75
84
  # Retrieves a list of buckets for the given project.
76
- def list_buckets prefix: nil, token: nil, max: nil, user_project: nil
85
+ def list_buckets prefix: nil, token: nil, max: nil, user_project: nil, options: {}
77
86
  execute do
78
87
  service.list_buckets \
79
88
  @project, prefix: prefix, page_token: token, max_results: max,
80
- user_project: user_project(user_project)
89
+ user_project: user_project(user_project), options: options
81
90
  end
82
91
  end
83
92
 
@@ -87,12 +96,14 @@ module Google
87
96
  def get_bucket bucket_name,
88
97
  if_metageneration_match: nil,
89
98
  if_metageneration_not_match: nil,
90
- user_project: nil
99
+ user_project: nil,
100
+ options: {}
91
101
  execute do
92
102
  service.get_bucket bucket_name,
93
103
  if_metageneration_match: if_metageneration_match,
94
104
  if_metageneration_not_match: if_metageneration_not_match,
95
- user_project: user_project(user_project)
105
+ user_project: user_project(user_project),
106
+ options: options
96
107
  end
97
108
  end
98
109
 
@@ -100,13 +111,14 @@ module Google
100
111
  # Creates a new bucket.
101
112
  # Returns Google::Apis::StorageV1::Bucket.
102
113
  def insert_bucket bucket_gapi, acl: nil, default_acl: nil,
103
- user_project: nil
114
+ user_project: nil, options: {}
104
115
  execute do
105
116
  service.insert_bucket \
106
117
  @project, bucket_gapi,
107
118
  predefined_acl: acl,
108
119
  predefined_default_object_acl: default_acl,
109
- user_project: user_project(user_project)
120
+ user_project: user_project(user_project),
121
+ options: options
110
122
  end
111
123
  end
112
124
 
@@ -118,11 +130,17 @@ module Google
118
130
  predefined_default_acl: nil,
119
131
  if_metageneration_match: nil,
120
132
  if_metageneration_not_match: nil,
121
- user_project: nil
133
+ user_project: nil,
134
+ options: {}
122
135
  bucket_gapi ||= Google::Apis::StorageV1::Bucket.new
123
136
  bucket_gapi.acl = [] if predefined_acl
124
137
  bucket_gapi.default_object_acl = [] if predefined_default_acl
125
138
 
139
+ if options[:retries].nil?
140
+ is_idempotent = retry? if_metageneration_match: if_metageneration_match
141
+ options = is_idempotent ? {} : { retries: 0 }
142
+ end
143
+
126
144
  execute do
127
145
  service.patch_bucket bucket_name,
128
146
  bucket_gapi,
@@ -130,7 +148,8 @@ module Google
130
148
  predefined_default_object_acl: predefined_default_acl,
131
149
  if_metageneration_match: if_metageneration_match,
132
150
  if_metageneration_not_match: if_metageneration_not_match,
133
- user_project: user_project(user_project)
151
+ user_project: user_project(user_project),
152
+ options: options
134
153
  end
135
154
  end
136
155
 
@@ -139,119 +158,144 @@ module Google
139
158
  def delete_bucket bucket_name,
140
159
  if_metageneration_match: nil,
141
160
  if_metageneration_not_match: nil,
142
- user_project: nil
161
+ user_project: nil,
162
+ options: {}
143
163
  execute do
144
164
  service.delete_bucket bucket_name,
145
165
  if_metageneration_match: if_metageneration_match,
146
166
  if_metageneration_not_match: if_metageneration_not_match,
147
- user_project: user_project(user_project)
167
+ user_project: user_project(user_project),
168
+ options: options
148
169
  end
149
170
  end
150
171
 
151
172
  ##
152
173
  # Locks retention policy on a bucket.
153
174
  def lock_bucket_retention_policy bucket_name, metageneration,
154
- user_project: nil
175
+ user_project: nil,
176
+ options: {}
155
177
  execute do
156
178
  service.lock_bucket_retention_policy \
157
179
  bucket_name, metageneration,
158
- user_project: user_project(user_project)
180
+ user_project: user_project(user_project),
181
+ options: options
159
182
  end
160
183
  end
161
184
 
162
185
  ##
163
186
  # Retrieves a list of ACLs for the given bucket.
164
- def list_bucket_acls bucket_name, user_project: nil
187
+ def list_bucket_acls bucket_name, user_project: nil, options: {}
165
188
  execute do
166
189
  service.list_bucket_access_controls \
167
- bucket_name, user_project: user_project(user_project)
190
+ bucket_name, user_project: user_project(user_project),
191
+ options: options
168
192
  end
169
193
  end
170
194
 
171
195
  ##
172
196
  # Creates a new bucket ACL.
173
- def insert_bucket_acl bucket_name, entity, role, user_project: nil
197
+ def insert_bucket_acl bucket_name, entity, role, user_project: nil, options: {}
174
198
  params = { entity: entity, role: role }.delete_if { |_k, v| v.nil? }
175
199
  new_acl = Google::Apis::StorageV1::BucketAccessControl.new(**params)
200
+ if options[:retries].nil?
201
+ options = options.merge({ retries: 0 })
202
+ end
176
203
  execute do
177
204
  service.insert_bucket_access_control \
178
- bucket_name, new_acl, user_project: user_project(user_project)
205
+ bucket_name, new_acl, user_project: user_project(user_project),
206
+ options: options
179
207
  end
180
208
  end
181
209
 
182
210
  ##
183
211
  # Permanently deletes a bucket ACL.
184
- def delete_bucket_acl bucket_name, entity, user_project: nil
212
+ def delete_bucket_acl bucket_name, entity, user_project: nil, options: {}
213
+ if options[:retries].nil?
214
+ options = options.merge({ retries: 0 })
215
+ end
185
216
  execute do
186
217
  service.delete_bucket_access_control \
187
- bucket_name, entity, user_project: user_project(user_project)
218
+ bucket_name, entity, user_project: user_project(user_project),
219
+ options: options
188
220
  end
189
221
  end
190
222
 
191
223
  ##
192
224
  # Retrieves a list of default ACLs for the given bucket.
193
- def list_default_acls bucket_name, user_project: nil
225
+ def list_default_acls bucket_name, user_project: nil, options: {}
194
226
  execute do
195
227
  service.list_default_object_access_controls \
196
- bucket_name, user_project: user_project(user_project)
228
+ bucket_name, user_project: user_project(user_project),
229
+ options: options
197
230
  end
198
231
  end
199
232
 
200
233
  ##
201
234
  # Creates a new default ACL.
202
- def insert_default_acl bucket_name, entity, role, user_project: nil
235
+ def insert_default_acl bucket_name, entity, role, user_project: nil, options: {}
236
+ if options[:retries].nil?
237
+ options = options.merge({ retries: 0 })
238
+ end
203
239
  param = { entity: entity, role: role }.delete_if { |_k, v| v.nil? }
204
240
  new_acl = Google::Apis::StorageV1::ObjectAccessControl.new(**param)
205
241
  execute do
206
242
  service.insert_default_object_access_control \
207
- bucket_name, new_acl, user_project: user_project(user_project)
243
+ bucket_name, new_acl, user_project: user_project(user_project),
244
+ options: options
208
245
  end
209
246
  end
210
247
 
211
248
  ##
212
249
  # Permanently deletes a default ACL.
213
- def delete_default_acl bucket_name, entity, user_project: nil
250
+ def delete_default_acl bucket_name, entity, user_project: nil, options: {}
251
+ if options[:retries].nil?
252
+ options = options.merge({ retries: 0 })
253
+ end
214
254
  execute do
215
255
  service.delete_default_object_access_control \
216
- bucket_name, entity, user_project: user_project(user_project)
256
+ bucket_name, entity, user_project: user_project(user_project),
257
+ options: options
217
258
  end
218
259
  end
219
260
 
220
261
  ##
221
262
  # Returns Google::Apis::StorageV1::Policy
222
- def get_bucket_policy bucket_name, requested_policy_version: nil, user_project: nil
263
+ def get_bucket_policy bucket_name, requested_policy_version: nil, user_project: nil,
264
+ options: {}
223
265
  # get_bucket_iam_policy(bucket, fields: nil, quota_user: nil,
224
266
  # user_ip: nil, options: nil)
225
267
  execute do
226
268
  service.get_bucket_iam_policy bucket_name, options_requested_policy_version: requested_policy_version,
227
- user_project: user_project(user_project)
269
+ user_project: user_project(user_project), options: options
228
270
  end
229
271
  end
230
272
 
231
273
  ##
232
274
  # Returns Google::Apis::StorageV1::Policy
233
- def set_bucket_policy bucket_name, new_policy, user_project: nil
275
+ def set_bucket_policy bucket_name, new_policy, user_project: nil, options: {}
234
276
  execute do
235
277
  service.set_bucket_iam_policy \
236
- bucket_name, new_policy, user_project: user_project(user_project)
278
+ bucket_name, new_policy, user_project: user_project(user_project), options: options
237
279
  end
238
280
  end
239
281
 
240
282
  ##
241
283
  # Returns Google::Apis::StorageV1::TestIamPermissionsResponse
242
- def test_bucket_permissions bucket_name, permissions, user_project: nil
284
+ def test_bucket_permissions bucket_name, permissions, user_project: nil, options: {}
243
285
  execute do
244
286
  service.test_bucket_iam_permissions \
245
- bucket_name, permissions, user_project: user_project(user_project)
287
+ bucket_name, permissions, user_project: user_project(user_project),
288
+ options: options
246
289
  end
247
290
  end
248
291
 
249
292
  ##
250
293
  # Retrieves a list of Pub/Sub notification subscriptions for a bucket.
251
- def list_notifications bucket_name, user_project: nil
294
+ def list_notifications bucket_name, user_project: nil, options: {}
252
295
  execute do
253
296
  service.list_notifications bucket_name,
254
- user_project: user_project(user_project)
297
+ user_project: user_project(user_project),
298
+ options: options
255
299
  end
256
300
  end
257
301
 
@@ -259,7 +303,7 @@ module Google
259
303
  # Creates a new Pub/Sub notification subscription for a bucket.
260
304
  def insert_notification bucket_name, topic_name, custom_attrs: nil,
261
305
  event_types: nil, prefix: nil, payload: nil,
262
- user_project: nil
306
+ user_project: nil, options: {}
263
307
  params =
264
308
  { custom_attributes: custom_attrs,
265
309
  event_types: event_types(event_types),
@@ -268,41 +312,50 @@ module Google
268
312
  topic: topic_path(topic_name) }.delete_if { |_k, v| v.nil? }
269
313
  new_notification = Google::Apis::StorageV1::Notification.new(**params)
270
314
 
315
+ if options[:retries].nil?
316
+ options = options.merge({ retries: 0 })
317
+ end
318
+
271
319
  execute do
272
320
  service.insert_notification \
273
321
  bucket_name, new_notification,
274
- user_project: user_project(user_project)
322
+ user_project: user_project(user_project),
323
+ options: options
275
324
  end
276
325
  end
277
326
 
278
327
  ##
279
328
  # Retrieves a Pub/Sub notification subscription for a bucket.
280
- def get_notification bucket_name, notification_id, user_project: nil
329
+ def get_notification bucket_name, notification_id, user_project: nil, options: {}
281
330
  execute do
282
331
  service.get_notification bucket_name, notification_id,
283
- user_project: user_project(user_project)
332
+ user_project: user_project(user_project),
333
+ options: options
284
334
  end
285
335
  end
286
336
 
287
337
  ##
288
338
  # Deletes a new Pub/Sub notification subscription for a bucket.
289
- def delete_notification bucket_name, notification_id, user_project: nil
339
+ def delete_notification bucket_name, notification_id, user_project: nil, options: {}
290
340
  execute do
291
341
  service.delete_notification bucket_name, notification_id,
292
- user_project: user_project(user_project)
342
+ user_project: user_project(user_project),
343
+ options: options
293
344
  end
294
345
  end
295
346
 
296
347
  ##
297
348
  # Retrieves a list of files matching the criteria.
298
349
  def list_files bucket_name, delimiter: nil, max: nil, token: nil,
299
- prefix: nil, versions: nil, user_project: nil
350
+ prefix: nil, versions: nil, user_project: nil,
351
+ options: {}
300
352
  execute do
301
353
  service.list_objects \
302
354
  bucket_name, delimiter: delimiter, max_results: max,
303
355
  page_token: token, prefix: prefix,
304
356
  versions: versions,
305
- user_project: user_project(user_project)
357
+ user_project: user_project(user_project),
358
+ options: options
306
359
  end
307
360
  end
308
361
 
@@ -330,7 +383,8 @@ module Google
330
383
  if_generation_not_match: nil,
331
384
  if_metageneration_match: nil,
332
385
  if_metageneration_not_match: nil,
333
- user_project: nil
386
+ user_project: nil,
387
+ options: {}
334
388
  params = {
335
389
  cache_control: cache_control,
336
390
  content_type: content_type,
@@ -348,6 +402,13 @@ module Google
348
402
  file_obj = Google::Apis::StorageV1::Object.new(**params)
349
403
  content_type ||= mime_type_for(path || Pathname(source).to_path)
350
404
 
405
+ if options[:retries].nil?
406
+ is_idempotent = retry? if_generation_match: if_generation_match
407
+ options = is_idempotent ? key_options(key) : key_options(key).merge(retries: 0)
408
+ else
409
+ options = key_options(key).merge options
410
+ end
411
+
351
412
  execute do
352
413
  service.insert_object bucket_name,
353
414
  file_obj,
@@ -362,7 +423,7 @@ module Google
362
423
  if_metageneration_not_match: if_metageneration_not_match,
363
424
  kms_key_name: kms_key,
364
425
  user_project: user_project(user_project),
365
- options: key_options(key)
426
+ options: options
366
427
  end
367
428
  end
368
429
 
@@ -376,7 +437,8 @@ module Google
376
437
  if_metageneration_match: nil,
377
438
  if_metageneration_not_match: nil,
378
439
  key: nil,
379
- user_project: nil
440
+ user_project: nil,
441
+ options: {}
380
442
  execute do
381
443
  service.get_object \
382
444
  bucket_name, file_path,
@@ -386,7 +448,7 @@ module Google
386
448
  if_metageneration_match: if_metageneration_match,
387
449
  if_metageneration_not_match: if_metageneration_not_match,
388
450
  user_project: user_project(user_project),
389
- options: key_options(key)
451
+ options: key_options(key).merge(options)
390
452
  end
391
453
  end
392
454
 
@@ -411,8 +473,17 @@ module Google
411
473
  if_source_metageneration_match: nil,
412
474
  if_source_metageneration_not_match: nil,
413
475
  token: nil,
414
- user_project: nil
476
+ user_project: nil,
477
+ options: {}
415
478
  key_options = rewrite_key_options source_key, destination_key
479
+
480
+ if options[:retries].nil?
481
+ is_idempotent = retry? if_generation_match: if_generation_match
482
+ options = is_idempotent ? key_options : key_options.merge(retries: 0)
483
+ else
484
+ options = key_options.merge options
485
+ end
486
+
416
487
  execute do
417
488
  service.rewrite_object source_bucket_name,
418
489
  source_file_path,
@@ -432,7 +503,7 @@ module Google
432
503
  if_source_metageneration_not_match: if_source_metageneration_not_match,
433
504
  rewrite_token: token,
434
505
  user_project: user_project(user_project),
435
- options: key_options
506
+ options: options
436
507
  end
437
508
  end
438
509
 
@@ -447,12 +518,20 @@ module Google
447
518
  if_source_generation_match: nil,
448
519
  if_generation_match: nil,
449
520
  if_metageneration_match: nil,
450
- user_project: nil
521
+ user_project: nil,
522
+ options: {}
451
523
 
452
524
  source_objects = compose_file_source_objects source_files, if_source_generation_match
453
525
  compose_req = Google::Apis::StorageV1::ComposeRequest.new source_objects: source_objects,
454
526
  destination: destination_gapi
455
527
 
528
+ if options[:retries].nil?
529
+ is_idempotent = retry? if_generation_match: if_generation_match
530
+ options = is_idempotent ? key_options(key) : key_options(key).merge(retries: 0)
531
+ else
532
+ options = key_options.merge options
533
+ end
534
+
456
535
  execute do
457
536
  service.compose_object bucket_name,
458
537
  destination_path,
@@ -461,7 +540,7 @@ module Google
461
540
  if_generation_match: if_generation_match,
462
541
  if_metageneration_match: if_metageneration_match,
463
542
  user_project: user_project(user_project),
464
- options: key_options(key)
543
+ options: options
465
544
  end
466
545
  end
467
546
 
@@ -475,12 +554,12 @@ module Google
475
554
  # Apis::StorageV1::StorageService and Apis::Core::DownloadCommand at
476
555
  # the end of this file.
477
556
  def download_file bucket_name, file_path, target_path, generation: nil,
478
- key: nil, range: nil, user_project: nil
479
- options = key_options key
557
+ key: nil, range: nil, user_project: nil, options: {}
558
+ options = key_options(key).merge(options)
480
559
  options = range_header options, range
481
560
 
482
561
  execute do
483
- service.get_object_with_response \
562
+ service.get_object \
484
563
  bucket_name, file_path,
485
564
  download_dest: target_path, generation: generation,
486
565
  user_project: user_project(user_project),
@@ -499,8 +578,15 @@ module Google
499
578
  if_metageneration_match: nil,
500
579
  if_metageneration_not_match: nil,
501
580
  predefined_acl: nil,
502
- user_project: nil
581
+ user_project: nil,
582
+ options: {}
503
583
  file_gapi ||= Google::Apis::StorageV1::Object.new
584
+
585
+ if options[:retries].nil?
586
+ is_idempotent = retry? if_metageneration_match: if_metageneration_match
587
+ options = is_idempotent ? {} : { retries: 0 }
588
+ end
589
+
504
590
  execute do
505
591
  service.patch_object bucket_name,
506
592
  file_path,
@@ -511,7 +597,8 @@ module Google
511
597
  if_metageneration_match: if_metageneration_match,
512
598
  if_metageneration_not_match: if_metageneration_not_match,
513
599
  predefined_acl: predefined_acl,
514
- user_project: user_project(user_project)
600
+ user_project: user_project(user_project),
601
+ options: options
515
602
  end
516
603
  end
517
604
 
@@ -524,7 +611,14 @@ module Google
524
611
  if_generation_not_match: nil,
525
612
  if_metageneration_match: nil,
526
613
  if_metageneration_not_match: nil,
527
- user_project: nil
614
+ user_project: nil,
615
+ options: {}
616
+
617
+ if options[:retries].nil?
618
+ is_idempotent = retry? generation: generation, if_generation_match: if_generation_match
619
+ options = is_idempotent ? {} : { retries: 0 }
620
+ end
621
+
528
622
  execute do
529
623
  service.delete_object bucket_name, file_path,
530
624
  generation: generation,
@@ -532,40 +626,51 @@ module Google
532
626
  if_generation_not_match: if_generation_not_match,
533
627
  if_metageneration_match: if_metageneration_match,
534
628
  if_metageneration_not_match: if_metageneration_not_match,
535
- user_project: user_project(user_project)
629
+ user_project: user_project(user_project),
630
+ options: options
536
631
  end
537
632
  end
538
633
 
539
634
  ##
540
635
  # Retrieves a list of ACLs for the given file.
541
- def list_file_acls bucket_name, file_name, user_project: nil
636
+ def list_file_acls bucket_name, file_name, user_project: nil, options: {}
542
637
  execute do
543
638
  service.list_object_access_controls \
544
- bucket_name, file_name, user_project: user_project(user_project)
639
+ bucket_name, file_name, user_project: user_project(user_project),
640
+ options: options
545
641
  end
546
642
  end
547
643
 
548
644
  ##
549
645
  # Creates a new file ACL.
550
646
  def insert_file_acl bucket_name, file_name, entity, role,
551
- generation: nil, user_project: nil
647
+ generation: nil, user_project: nil,
648
+ options: {}
649
+ if options[:retries].nil?
650
+ options = options.merge({ retries: 0 })
651
+ end
552
652
  params = { entity: entity, role: role }.delete_if { |_k, v| v.nil? }
553
653
  new_acl = Google::Apis::StorageV1::ObjectAccessControl.new(**params)
554
654
  execute do
555
655
  service.insert_object_access_control \
556
656
  bucket_name, file_name, new_acl,
557
- generation: generation, user_project: user_project(user_project)
657
+ generation: generation, user_project: user_project(user_project),
658
+ options: options
558
659
  end
559
660
  end
560
661
 
561
662
  ##
562
663
  # Permanently deletes a file ACL.
563
664
  def delete_file_acl bucket_name, file_name, entity, generation: nil,
564
- user_project: nil
665
+ user_project: nil, options: {}
666
+ if options[:retries].nil?
667
+ options = options.merge({ retries: 0 })
668
+ end
565
669
  execute do
566
670
  service.delete_object_access_control \
567
671
  bucket_name, file_name, entity,
568
- generation: generation, user_project: user_project(user_project)
672
+ generation: generation, user_project: user_project(user_project),
673
+ options: options
569
674
  end
570
675
  end
571
676
 
@@ -573,32 +678,42 @@ module Google
573
678
  # Creates a new HMAC key for the specified service account.
574
679
  # Returns Google::Apis::StorageV1::HmacKey.
575
680
  def create_hmac_key service_account_email, project_id: nil,
576
- user_project: nil
681
+ user_project: nil, options: {}
682
+
683
+ if options[:retries].nil?
684
+ options = options.merge({ retries: 0 })
685
+ end
686
+
577
687
  execute do
578
688
  service.create_project_hmac_key \
579
689
  (project_id || @project), service_account_email,
580
- user_project: user_project(user_project)
690
+ user_project: user_project(user_project),
691
+ options: options
581
692
  end
582
693
  end
583
694
 
584
695
  ##
585
696
  # Deletes an HMAC key. Key must be in the INACTIVE state.
586
- def delete_hmac_key access_id, project_id: nil, user_project: nil
697
+ def delete_hmac_key access_id, project_id: nil, user_project: nil,
698
+ options: {}
587
699
  execute do
588
700
  service.delete_project_hmac_key \
589
701
  (project_id || @project), access_id,
590
- user_project: user_project(user_project)
702
+ user_project: user_project(user_project),
703
+ options: options
591
704
  end
592
705
  end
593
706
 
594
707
  ##
595
708
  # Retrieves an HMAC key's metadata.
596
709
  # Returns Google::Apis::StorageV1::HmacKeyMetadata.
597
- def get_hmac_key access_id, project_id: nil, user_project: nil
710
+ def get_hmac_key access_id, project_id: nil, user_project: nil,
711
+ options: {}
598
712
  execute do
599
713
  service.get_project_hmac_key \
600
714
  (project_id || @project), access_id,
601
- user_project: user_project(user_project)
715
+ user_project: user_project(user_project),
716
+ options: options
602
717
  end
603
718
  end
604
719
 
@@ -607,14 +722,15 @@ module Google
607
722
  # Returns Google::Apis::StorageV1::HmacKeysMetadata.
608
723
  def list_hmac_keys max: nil, token: nil, service_account_email: nil,
609
724
  project_id: nil, show_deleted_keys: nil,
610
- user_project: nil
725
+ user_project: nil, options: {}
611
726
  execute do
612
727
  service.list_project_hmac_keys \
613
728
  (project_id || @project),
614
729
  max_results: max, page_token: token,
615
730
  service_account_email: service_account_email,
616
731
  show_deleted_keys: show_deleted_keys,
617
- user_project: user_project(user_project)
732
+ user_project: user_project(user_project),
733
+ options: options
618
734
  end
619
735
  end
620
736
 
@@ -623,11 +739,44 @@ module Google
623
739
  # for valid states.
624
740
  # Returns Google::Apis::StorageV1::HmacKeyMetadata.
625
741
  def update_hmac_key access_id, hmac_key_metadata_object,
626
- project_id: nil, user_project: nil
742
+ project_id: nil, user_project: nil,
743
+ options: {}
627
744
  execute do
628
745
  service.update_project_hmac_key \
629
746
  (project_id || @project), access_id, hmac_key_metadata_object,
630
- user_project: user_project(user_project)
747
+ user_project: user_project(user_project),
748
+ options: options
749
+ end
750
+ end
751
+
752
+ ##
753
+ # Updates a bucket, including its ACL metadata.
754
+ def update_bucket bucket_name,
755
+ bucket_gapi = nil,
756
+ predefined_acl: nil,
757
+ predefined_default_acl: nil,
758
+ if_metageneration_match: nil,
759
+ if_metageneration_not_match: nil,
760
+ user_project: nil,
761
+ options: {}
762
+ bucket_gapi ||= Google::Apis::StorageV1::Bucket.new
763
+ bucket_gapi.acl = [] if predefined_acl
764
+ bucket_gapi.default_object_acl = [] if predefined_default_acl
765
+
766
+ if options[:retries].nil?
767
+ is_idempotent = retry? if_metageneration_match: if_metageneration_match
768
+ options = is_idempotent ? {} : { retries: 0 }
769
+ end
770
+
771
+ execute do
772
+ service.update_bucket bucket_name,
773
+ bucket_gapi,
774
+ predefined_acl: predefined_acl,
775
+ predefined_default_object_acl: predefined_default_acl,
776
+ if_metageneration_match: if_metageneration_match,
777
+ if_metageneration_not_match: if_metageneration_not_match,
778
+ user_project: user_project(user_project),
779
+ options: options
631
780
  end
632
781
  end
633
782
 
@@ -763,163 +912,11 @@ module Google
763
912
  rescue Google::Apis::Error => e
764
913
  raise Google::Cloud::Error.from_error(e)
765
914
  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
915
 
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)
916
+ def retry? query_params
917
+ query_params.any? { |_key, val| !val.nil? }
920
918
  end
921
919
  end
922
920
  end
923
921
  end
924
- # rubocop:enable all
925
922
  end