google-cloud-storage 1.29.2 → 1.33.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 +55 -0
- data/CONTRIBUTING.md +3 -4
- data/lib/google/cloud/storage/bucket.rb +344 -76
- data/lib/google/cloud/storage/bucket/acl.rb +12 -14
- data/lib/google/cloud/storage/bucket/cors.rb +4 -1
- data/lib/google/cloud/storage/bucket/lifecycle.rb +11 -11
- data/lib/google/cloud/storage/bucket/list.rb +3 -3
- data/lib/google/cloud/storage/credentials.rb +16 -14
- data/lib/google/cloud/storage/file.rb +223 -32
- data/lib/google/cloud/storage/file/acl.rb +181 -20
- data/lib/google/cloud/storage/file/list.rb +3 -3
- data/lib/google/cloud/storage/file/signer_v2.rb +2 -4
- data/lib/google/cloud/storage/file/signer_v4.rb +11 -9
- data/lib/google/cloud/storage/file/verifier.rb +2 -2
- data/lib/google/cloud/storage/hmac_key/list.rb +3 -3
- data/lib/google/cloud/storage/policy.rb +2 -2
- data/lib/google/cloud/storage/policy/binding.rb +5 -3
- data/lib/google/cloud/storage/policy/bindings.rb +2 -2
- data/lib/google/cloud/storage/policy/condition.rb +4 -2
- data/lib/google/cloud/storage/post_object.rb +2 -1
- data/lib/google/cloud/storage/project.rb +18 -6
- data/lib/google/cloud/storage/service.rb +193 -64
- data/lib/google/cloud/storage/version.rb +1 -1
- metadata +34 -14
@@ -212,8 +212,8 @@ module Google
|
|
212
212
|
def deep_dup
|
213
213
|
warn "DEPRECATED: Storage::PolicyV1#deep_dup"
|
214
214
|
dup.tap do |p|
|
215
|
-
roles_dup = p.roles.
|
216
|
-
|
215
|
+
roles_dup = p.roles.transform_values do |v|
|
216
|
+
v.dup rescue value
|
217
217
|
end
|
218
218
|
p.instance_variable_set :@roles, roles_dup
|
219
219
|
end
|
@@ -89,7 +89,9 @@ module Google
|
|
89
89
|
# end
|
90
90
|
#
|
91
91
|
class Binding
|
92
|
-
attr_reader :role
|
92
|
+
attr_reader :role
|
93
|
+
attr_reader :members
|
94
|
+
attr_reader :condition
|
93
95
|
|
94
96
|
##
|
95
97
|
# Creates a Binding object.
|
@@ -128,8 +130,8 @@ module Google
|
|
128
130
|
raise ArgumentError, "members is empty, must be provided" if @members.empty?
|
129
131
|
|
130
132
|
condition = Condition.new(**condition) if condition.is_a? Hash
|
131
|
-
if condition
|
132
|
-
raise ArgumentError, "expected Condition, not #{condition.inspect}"
|
133
|
+
if condition && !(condition.is_a? Condition)
|
134
|
+
raise ArgumentError, "expected Condition, not #{condition.inspect}"
|
133
135
|
end
|
134
136
|
@condition = condition
|
135
137
|
end
|
@@ -70,7 +70,9 @@ module Google
|
|
70
70
|
# end
|
71
71
|
#
|
72
72
|
class Condition
|
73
|
-
attr_reader :title
|
73
|
+
attr_reader :title
|
74
|
+
attr_reader :description
|
75
|
+
attr_reader :expression
|
74
76
|
|
75
77
|
##
|
76
78
|
# Creates a Condition object.
|
@@ -83,7 +85,7 @@ module Google
|
|
83
85
|
# one attributes, and statements are combined using logic operators,
|
84
86
|
# following CEL language specification. Required.
|
85
87
|
#
|
86
|
-
def initialize title:, description: nil
|
88
|
+
def initialize title:, expression:, description: nil
|
87
89
|
@title = String title
|
88
90
|
@description = String description
|
89
91
|
@expression = String expression
|
@@ -165,6 +165,11 @@ module Google
|
|
165
165
|
# without verifying the bucket resource exists on the Storage service.
|
166
166
|
# Calls made on this object will raise errors if the bucket resource
|
167
167
|
# does not exist. Default is `false`.
|
168
|
+
# @param [Integer] if_metageneration_match Makes the operation conditional
|
169
|
+
# on whether the bucket's current metageneration matches the given value.
|
170
|
+
# @param [Integer] if_metageneration_not_match Makes the operation
|
171
|
+
# conditional on whether the bucket's current metageneration does not
|
172
|
+
# match the given value.
|
168
173
|
# @param [Boolean, String] user_project If this parameter is set to
|
169
174
|
# `true`, transit costs for operations on the requested bucket or a
|
170
175
|
# file it contains will be billed to the current project for this
|
@@ -208,12 +213,19 @@ module Google
|
|
208
213
|
# user_project: "my-other-project"
|
209
214
|
# files = bucket.files # Billed to "my-other-project"
|
210
215
|
#
|
211
|
-
def bucket bucket_name,
|
216
|
+
def bucket bucket_name,
|
217
|
+
skip_lookup: false,
|
218
|
+
if_metageneration_match: nil,
|
219
|
+
if_metageneration_not_match: nil,
|
220
|
+
user_project: nil
|
212
221
|
if skip_lookup
|
213
222
|
return Bucket.new_lazy bucket_name, service,
|
214
223
|
user_project: user_project
|
215
224
|
end
|
216
|
-
gapi = service.get_bucket bucket_name,
|
225
|
+
gapi = service.get_bucket bucket_name,
|
226
|
+
if_metageneration_match: if_metageneration_match,
|
227
|
+
if_metageneration_not_match: if_metageneration_not_match,
|
228
|
+
user_project: user_project
|
217
229
|
Bucket.from_gapi gapi, service, user_project: user_project
|
218
230
|
rescue Google::Cloud::NotFoundError
|
219
231
|
nil
|
@@ -611,11 +623,11 @@ module Google
|
|
611
623
|
# scopes = ["https://www.googleapis.com/auth/iam"]
|
612
624
|
# iam_client.authorization = Google::Auth.get_application_default scopes
|
613
625
|
#
|
614
|
-
# request =
|
615
|
-
#
|
616
|
-
#
|
626
|
+
# request = Google::Apis::IamcredentialsV1::SignBlobRequest.new(
|
627
|
+
# payload: string_to_sign
|
628
|
+
# )
|
617
629
|
# resource = "projects/-/serviceAccounts/#{issuer}"
|
618
|
-
# response = iam_client.sign_service_account_blob resource, request
|
630
|
+
# response = iam_client.sign_service_account_blob resource, request
|
619
631
|
# response.signed_blob
|
620
632
|
# end
|
621
633
|
#
|
@@ -83,9 +83,14 @@ module Google
|
|
83
83
|
##
|
84
84
|
# Retrieves bucket by name.
|
85
85
|
# Returns Google::Apis::StorageV1::Bucket.
|
86
|
-
def get_bucket bucket_name,
|
86
|
+
def get_bucket bucket_name,
|
87
|
+
if_metageneration_match: nil,
|
88
|
+
if_metageneration_not_match: nil,
|
89
|
+
user_project: nil
|
87
90
|
execute do
|
88
91
|
service.get_bucket bucket_name,
|
92
|
+
if_metageneration_match: if_metageneration_match,
|
93
|
+
if_metageneration_not_match: if_metageneration_not_match,
|
89
94
|
user_project: user_project(user_project)
|
90
95
|
end
|
91
96
|
end
|
@@ -106,26 +111,38 @@ module Google
|
|
106
111
|
|
107
112
|
##
|
108
113
|
# Updates a bucket, including its ACL metadata.
|
109
|
-
def patch_bucket bucket_name,
|
110
|
-
|
114
|
+
def patch_bucket bucket_name,
|
115
|
+
bucket_gapi = nil,
|
116
|
+
predefined_acl: nil,
|
117
|
+
predefined_default_acl: nil,
|
118
|
+
if_metageneration_match: nil,
|
119
|
+
if_metageneration_not_match: nil,
|
120
|
+
user_project: nil
|
111
121
|
bucket_gapi ||= Google::Apis::StorageV1::Bucket.new
|
112
122
|
bucket_gapi.acl = [] if predefined_acl
|
113
123
|
bucket_gapi.default_object_acl = [] if predefined_default_acl
|
114
124
|
|
115
125
|
execute do
|
116
|
-
service.patch_bucket
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
126
|
+
service.patch_bucket bucket_name,
|
127
|
+
bucket_gapi,
|
128
|
+
predefined_acl: predefined_acl,
|
129
|
+
predefined_default_object_acl: predefined_default_acl,
|
130
|
+
if_metageneration_match: if_metageneration_match,
|
131
|
+
if_metageneration_not_match: if_metageneration_not_match,
|
132
|
+
user_project: user_project(user_project)
|
121
133
|
end
|
122
134
|
end
|
123
135
|
|
124
136
|
##
|
125
137
|
# Permanently deletes an empty bucket.
|
126
|
-
def delete_bucket bucket_name,
|
138
|
+
def delete_bucket bucket_name,
|
139
|
+
if_metageneration_match: nil,
|
140
|
+
if_metageneration_not_match: nil,
|
141
|
+
user_project: nil
|
127
142
|
execute do
|
128
143
|
service.delete_bucket bucket_name,
|
144
|
+
if_metageneration_match: if_metageneration_match,
|
145
|
+
if_metageneration_not_match: if_metageneration_not_match,
|
129
146
|
user_project: user_project(user_project)
|
130
147
|
end
|
131
148
|
end
|
@@ -290,41 +307,83 @@ module Google
|
|
290
307
|
|
291
308
|
##
|
292
309
|
# Inserts a new file for the given bucket
|
293
|
-
def insert_file bucket_name,
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
310
|
+
def insert_file bucket_name,
|
311
|
+
source,
|
312
|
+
path = nil,
|
313
|
+
acl: nil,
|
314
|
+
cache_control: nil,
|
315
|
+
content_disposition: nil,
|
316
|
+
content_encoding: nil,
|
317
|
+
content_language: nil,
|
318
|
+
content_type: nil,
|
319
|
+
custom_time: nil,
|
320
|
+
crc32c: nil,
|
321
|
+
md5: nil,
|
322
|
+
metadata: nil,
|
323
|
+
storage_class: nil,
|
324
|
+
key: nil,
|
325
|
+
kms_key: nil,
|
326
|
+
temporary_hold: nil,
|
327
|
+
event_based_hold: nil,
|
328
|
+
if_generation_match: nil,
|
329
|
+
if_generation_not_match: nil,
|
330
|
+
if_metageneration_match: nil,
|
331
|
+
if_metageneration_not_match: nil,
|
299
332
|
user_project: nil
|
300
|
-
params =
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
333
|
+
params = {
|
334
|
+
cache_control: cache_control,
|
335
|
+
content_type: content_type,
|
336
|
+
custom_time: custom_time,
|
337
|
+
content_disposition: content_disposition,
|
338
|
+
md5_hash: md5,
|
339
|
+
content_encoding: content_encoding,
|
340
|
+
crc32c: crc32c,
|
341
|
+
content_language: content_language,
|
342
|
+
metadata: metadata,
|
343
|
+
storage_class: storage_class,
|
344
|
+
temporary_hold: temporary_hold,
|
345
|
+
event_based_hold: event_based_hold
|
346
|
+
}.delete_if { |_k, v| v.nil? }
|
307
347
|
file_obj = Google::Apis::StorageV1::Object.new(**params)
|
308
348
|
content_type ||= mime_type_for(path || Pathname(source).to_path)
|
309
349
|
|
310
350
|
execute do
|
311
|
-
service.insert_object
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
351
|
+
service.insert_object bucket_name,
|
352
|
+
file_obj,
|
353
|
+
name: path,
|
354
|
+
predefined_acl: acl,
|
355
|
+
upload_source: source,
|
356
|
+
content_encoding: content_encoding,
|
357
|
+
content_type: content_type,
|
358
|
+
if_generation_match: if_generation_match,
|
359
|
+
if_generation_not_match: if_generation_not_match,
|
360
|
+
if_metageneration_match: if_metageneration_match,
|
361
|
+
if_metageneration_not_match: if_metageneration_not_match,
|
362
|
+
kms_key_name: kms_key,
|
363
|
+
user_project: user_project(user_project),
|
364
|
+
options: key_options(key)
|
317
365
|
end
|
318
366
|
end
|
319
367
|
|
320
368
|
##
|
321
369
|
# Retrieves an object or its metadata.
|
322
|
-
def get_file bucket_name,
|
370
|
+
def get_file bucket_name,
|
371
|
+
file_path,
|
372
|
+
generation: nil,
|
373
|
+
if_generation_match: nil,
|
374
|
+
if_generation_not_match: nil,
|
375
|
+
if_metageneration_match: nil,
|
376
|
+
if_metageneration_not_match: nil,
|
377
|
+
key: nil,
|
323
378
|
user_project: nil
|
324
379
|
execute do
|
325
380
|
service.get_object \
|
326
381
|
bucket_name, file_path,
|
327
382
|
generation: generation,
|
383
|
+
if_generation_match: if_generation_match,
|
384
|
+
if_generation_not_match: if_generation_not_match,
|
385
|
+
if_metageneration_match: if_metageneration_match,
|
386
|
+
if_metageneration_not_match: if_metageneration_not_match,
|
328
387
|
user_project: user_project(user_project),
|
329
388
|
options: key_options(key)
|
330
389
|
end
|
@@ -332,42 +391,76 @@ module Google
|
|
332
391
|
|
333
392
|
## Rewrite a file from source bucket/object to a
|
334
393
|
# destination bucket/object.
|
335
|
-
def rewrite_file source_bucket_name,
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
394
|
+
def rewrite_file source_bucket_name,
|
395
|
+
source_file_path,
|
396
|
+
destination_bucket_name,
|
397
|
+
destination_file_path,
|
398
|
+
file_gapi = nil,
|
399
|
+
source_key: nil,
|
400
|
+
destination_key: nil,
|
401
|
+
destination_kms_key: nil,
|
402
|
+
acl: nil,
|
403
|
+
generation: nil,
|
404
|
+
if_generation_match: nil,
|
405
|
+
if_generation_not_match: nil,
|
406
|
+
if_metageneration_match: nil,
|
407
|
+
if_metageneration_not_match: nil,
|
408
|
+
if_source_generation_match: nil,
|
409
|
+
if_source_generation_not_match: nil,
|
410
|
+
if_source_metageneration_match: nil,
|
411
|
+
if_source_metageneration_not_match: nil,
|
412
|
+
token: nil,
|
413
|
+
user_project: nil
|
340
414
|
key_options = rewrite_key_options source_key, destination_key
|
341
415
|
execute do
|
342
|
-
service.rewrite_object
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
416
|
+
service.rewrite_object source_bucket_name,
|
417
|
+
source_file_path,
|
418
|
+
destination_bucket_name,
|
419
|
+
destination_file_path,
|
420
|
+
file_gapi,
|
421
|
+
destination_kms_key_name: destination_kms_key,
|
422
|
+
destination_predefined_acl: acl,
|
423
|
+
source_generation: generation,
|
424
|
+
if_generation_match: if_generation_match,
|
425
|
+
if_generation_not_match: if_generation_not_match,
|
426
|
+
if_metageneration_match: if_metageneration_match,
|
427
|
+
if_metageneration_not_match: if_metageneration_not_match,
|
428
|
+
if_source_generation_match: if_source_generation_match,
|
429
|
+
if_source_generation_not_match: if_source_generation_not_match,
|
430
|
+
if_source_metageneration_match: if_source_metageneration_match,
|
431
|
+
if_source_metageneration_not_match: if_source_metageneration_not_match,
|
432
|
+
rewrite_token: token,
|
433
|
+
user_project: user_project(user_project),
|
434
|
+
options: key_options
|
352
435
|
end
|
353
436
|
end
|
354
437
|
|
355
438
|
## Copy a file from source bucket/object to a
|
356
439
|
# destination bucket/object.
|
357
|
-
def compose_file bucket_name,
|
358
|
-
|
440
|
+
def compose_file bucket_name,
|
441
|
+
source_files,
|
442
|
+
destination_path,
|
443
|
+
destination_gapi,
|
444
|
+
acl: nil,
|
445
|
+
key: nil,
|
446
|
+
if_source_generation_match: nil,
|
447
|
+
if_generation_match: nil,
|
448
|
+
if_metageneration_match: nil,
|
449
|
+
user_project: nil
|
359
450
|
|
360
|
-
|
361
|
-
|
362
|
-
|
451
|
+
source_objects = compose_file_source_objects source_files, if_source_generation_match
|
452
|
+
compose_req = Google::Apis::StorageV1::ComposeRequest.new source_objects: source_objects,
|
453
|
+
destination: destination_gapi
|
363
454
|
|
364
455
|
execute do
|
365
|
-
service.compose_object
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
456
|
+
service.compose_object bucket_name,
|
457
|
+
destination_path,
|
458
|
+
compose_req,
|
459
|
+
destination_predefined_acl: acl,
|
460
|
+
if_generation_match: if_generation_match,
|
461
|
+
if_metageneration_match: if_metageneration_match,
|
462
|
+
user_project: user_project(user_project),
|
463
|
+
options: key_options(key)
|
371
464
|
end
|
372
465
|
end
|
373
466
|
|
@@ -396,24 +489,48 @@ module Google
|
|
396
489
|
|
397
490
|
##
|
398
491
|
# Updates a file's metadata.
|
399
|
-
def patch_file bucket_name,
|
400
|
-
|
492
|
+
def patch_file bucket_name,
|
493
|
+
file_path,
|
494
|
+
file_gapi = nil,
|
495
|
+
generation: nil,
|
496
|
+
if_generation_match: nil,
|
497
|
+
if_generation_not_match: nil,
|
498
|
+
if_metageneration_match: nil,
|
499
|
+
if_metageneration_not_match: nil,
|
500
|
+
predefined_acl: nil,
|
501
|
+
user_project: nil
|
401
502
|
file_gapi ||= Google::Apis::StorageV1::Object.new
|
402
503
|
execute do
|
403
|
-
service.patch_object
|
404
|
-
|
405
|
-
|
406
|
-
|
504
|
+
service.patch_object bucket_name,
|
505
|
+
file_path,
|
506
|
+
file_gapi,
|
507
|
+
generation: generation,
|
508
|
+
if_generation_match: if_generation_match,
|
509
|
+
if_generation_not_match: if_generation_not_match,
|
510
|
+
if_metageneration_match: if_metageneration_match,
|
511
|
+
if_metageneration_not_match: if_metageneration_not_match,
|
512
|
+
predefined_acl: predefined_acl,
|
513
|
+
user_project: user_project(user_project)
|
407
514
|
end
|
408
515
|
end
|
409
516
|
|
410
517
|
##
|
411
518
|
# Permanently deletes a file.
|
412
|
-
def delete_file bucket_name,
|
519
|
+
def delete_file bucket_name,
|
520
|
+
file_path,
|
521
|
+
generation: nil,
|
522
|
+
if_generation_match: nil,
|
523
|
+
if_generation_not_match: nil,
|
524
|
+
if_metageneration_match: nil,
|
525
|
+
if_metageneration_not_match: nil,
|
413
526
|
user_project: nil
|
414
527
|
execute do
|
415
528
|
service.delete_object bucket_name, file_path,
|
416
529
|
generation: generation,
|
530
|
+
if_generation_match: if_generation_match,
|
531
|
+
if_generation_not_match: if_generation_not_match,
|
532
|
+
if_metageneration_match: if_metageneration_match,
|
533
|
+
if_metageneration_not_match: if_metageneration_not_match,
|
417
534
|
user_project: user_project(user_project)
|
418
535
|
end
|
419
536
|
end
|
@@ -615,8 +732,8 @@ module Google
|
|
615
732
|
"false" => "NONE" }[str_or_bool.to_s.downcase]
|
616
733
|
end
|
617
734
|
|
618
|
-
def compose_file_source_objects source_files
|
619
|
-
source_files.map do |file|
|
735
|
+
def compose_file_source_objects source_files, if_source_generation_match
|
736
|
+
source_objects = source_files.map do |file|
|
620
737
|
if file.is_a? Google::Cloud::Storage::File
|
621
738
|
Google::Apis::StorageV1::ComposeRequest::SourceObject.new \
|
622
739
|
name: file.name,
|
@@ -626,6 +743,18 @@ module Google
|
|
626
743
|
name: file
|
627
744
|
end
|
628
745
|
end
|
746
|
+
return source_objects unless if_source_generation_match
|
747
|
+
if source_files.count != if_source_generation_match.count
|
748
|
+
raise ArgumentError, "if provided, if_source_generation_match length must match sources length"
|
749
|
+
end
|
750
|
+
if_source_generation_match.each_with_index do |generation, i|
|
751
|
+
next unless generation
|
752
|
+
object_preconditions = Google::Apis::StorageV1::ComposeRequest::SourceObject::ObjectPreconditions.new(
|
753
|
+
if_generation_match: generation
|
754
|
+
)
|
755
|
+
source_objects[i].object_preconditions = object_preconditions
|
756
|
+
end
|
757
|
+
source_objects
|
629
758
|
end
|
630
759
|
|
631
760
|
def execute
|