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