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