google-cloud-storage 1.30.0 → 1.39.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/AUTHENTICATION.md +2 -1
- data/CHANGELOG.md +106 -0
- data/CONTRIBUTING.md +3 -4
- data/OVERVIEW.md +30 -0
- 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 +99 -21
- data/lib/google/cloud/storage/bucket/list.rb +3 -3
- data/lib/google/cloud/storage/bucket.rb +421 -62
- data/lib/google/cloud/storage/credentials.rb +16 -14
- 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 +3 -5
- data/lib/google/cloud/storage/file/signer_v4.rb +12 -10
- data/lib/google/cloud/storage/file/verifier.rb +2 -2
- data/lib/google/cloud/storage/file.rb +223 -32
- data/lib/google/cloud/storage/hmac_key/list.rb +3 -3
- 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/policy.rb +2 -2
- data/lib/google/cloud/storage/post_object.rb +2 -1
- data/lib/google/cloud/storage/project.rb +38 -18
- data/lib/google/cloud/storage/service.rb +352 -284
- 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 +24 -18
@@ -279,7 +279,7 @@ module Google
|
|
279
279
|
#
|
280
280
|
# @return [String]
|
281
281
|
#
|
282
|
-
# @see https://cloud.google.com/storage/docs/
|
282
|
+
# @see https://cloud.google.com/storage/docs/locations
|
283
283
|
#
|
284
284
|
def location
|
285
285
|
@gapi.location
|
@@ -301,6 +301,20 @@ module Google
|
|
301
301
|
@gapi.location_type
|
302
302
|
end
|
303
303
|
|
304
|
+
##
|
305
|
+
# Returns the list of regional locations for custom dual-region buckets.
|
306
|
+
#
|
307
|
+
# @return [String, nil] Returns nil if the property has not been set before creation,
|
308
|
+
# if the bucket's resource has not been loaded from the server,
|
309
|
+
# or if the bucket is not a dual-regions bucket.
|
310
|
+
|
311
|
+
# @see https://cloud.google.com/storage/docs/json_api/v1/buckets and
|
312
|
+
# https://cloud.google.com/storage/docs/locations
|
313
|
+
#
|
314
|
+
def data_locations
|
315
|
+
@gapi.custom_placement_config&.data_locations
|
316
|
+
end
|
317
|
+
|
304
318
|
##
|
305
319
|
# The destination bucket name for the bucket's logs.
|
306
320
|
#
|
@@ -309,12 +323,15 @@ module Google
|
|
309
323
|
# @see https://cloud.google.com/storage/docs/access-logs Access Logs
|
310
324
|
#
|
311
325
|
def logging_bucket
|
312
|
-
@gapi.logging
|
326
|
+
@gapi.logging&.log_bucket
|
313
327
|
end
|
314
328
|
|
315
329
|
##
|
316
330
|
# Updates the destination bucket for the bucket's logs.
|
317
331
|
#
|
332
|
+
# To pass metageneration preconditions, call this method within a
|
333
|
+
# block passed to {#update}.
|
334
|
+
#
|
318
335
|
# @see https://cloud.google.com/storage/docs/access-logs Access Logs
|
319
336
|
#
|
320
337
|
# @param [String] logging_bucket The bucket to hold the logging output
|
@@ -333,7 +350,7 @@ module Google
|
|
333
350
|
# @return [String]
|
334
351
|
#
|
335
352
|
def logging_prefix
|
336
|
-
@gapi.logging
|
353
|
+
@gapi.logging&.log_object_prefix
|
337
354
|
end
|
338
355
|
|
339
356
|
##
|
@@ -344,6 +361,9 @@ module Google
|
|
344
361
|
# By default, the object prefix is the name of the bucket for which the
|
345
362
|
# logs are enabled.
|
346
363
|
#
|
364
|
+
# To pass metageneration preconditions, call this method within a
|
365
|
+
# block passed to {#update}.
|
366
|
+
#
|
347
367
|
# @see https://cloud.google.com/storage/docs/access-logs Access Logs
|
348
368
|
#
|
349
369
|
# @param [String] logging_prefix The logging object prefix.
|
@@ -377,6 +397,9 @@ module Google
|
|
377
397
|
# For more information, see [Storage
|
378
398
|
# Classes](https://cloud.google.com/storage/docs/storage-classes).
|
379
399
|
#
|
400
|
+
# To pass metageneration preconditions, call this method within a
|
401
|
+
# block passed to {#update}.
|
402
|
+
#
|
380
403
|
# @param [Symbol, String] new_storage_class Storage class of the bucket.
|
381
404
|
#
|
382
405
|
def storage_class= new_storage_class
|
@@ -392,7 +415,7 @@ module Google
|
|
392
415
|
# @return [Boolean]
|
393
416
|
#
|
394
417
|
def versioning?
|
395
|
-
@gapi.versioning
|
418
|
+
@gapi.versioning&.enabled?
|
396
419
|
end
|
397
420
|
|
398
421
|
##
|
@@ -400,6 +423,9 @@ module Google
|
|
400
423
|
# Versioning](https://cloud.google.com/storage/docs/object-versioning)
|
401
424
|
# is enabled for the bucket.
|
402
425
|
#
|
426
|
+
# To pass metageneration preconditions, call this method within a
|
427
|
+
# block passed to {#update}.
|
428
|
+
#
|
403
429
|
# @param [Boolean] new_versioning true if versioning is to be enabled
|
404
430
|
# for the bucket.
|
405
431
|
#
|
@@ -422,12 +448,15 @@ module Google
|
|
422
448
|
# @return [String] The main page suffix.
|
423
449
|
#
|
424
450
|
def website_main
|
425
|
-
@gapi.website
|
451
|
+
@gapi.website&.main_page_suffix
|
426
452
|
end
|
427
453
|
|
428
454
|
##
|
429
455
|
# Updates the main page suffix for a static website.
|
430
456
|
#
|
457
|
+
# To pass metageneration preconditions, call this method within a
|
458
|
+
# block passed to {#update}.
|
459
|
+
#
|
431
460
|
# @see https://cloud.google.com/storage/docs/website-configuration#step4
|
432
461
|
# How to Host a Static Website
|
433
462
|
#
|
@@ -449,7 +478,7 @@ module Google
|
|
449
478
|
# @return [String]
|
450
479
|
#
|
451
480
|
def website_404
|
452
|
-
@gapi.website
|
481
|
+
@gapi.website&.not_found_page
|
453
482
|
end
|
454
483
|
|
455
484
|
##
|
@@ -467,6 +496,9 @@ module Google
|
|
467
496
|
##
|
468
497
|
# Updates the hash of user-provided labels.
|
469
498
|
#
|
499
|
+
# To pass metageneration preconditions, call this method within a
|
500
|
+
# block passed to {#update}.
|
501
|
+
#
|
470
502
|
# @param [Hash(String => String)] labels The user-provided labels.
|
471
503
|
#
|
472
504
|
def labels= labels
|
@@ -478,6 +510,9 @@ module Google
|
|
478
510
|
# Updates the page returned from a static website served from the bucket
|
479
511
|
# when a site visitor requests a resource that does not exist.
|
480
512
|
#
|
513
|
+
# To pass metageneration preconditions, call this method within a
|
514
|
+
# block passed to {#update}.
|
515
|
+
#
|
481
516
|
# @see https://cloud.google.com/storage/docs/website-configuration#step4
|
482
517
|
# How to Host a Static Website
|
483
518
|
#
|
@@ -498,7 +533,7 @@ module Google
|
|
498
533
|
# the bucket.
|
499
534
|
#
|
500
535
|
def requester_pays
|
501
|
-
@gapi.billing
|
536
|
+
@gapi.billing&.requester_pays
|
502
537
|
end
|
503
538
|
alias requester_pays? requester_pays
|
504
539
|
|
@@ -509,6 +544,9 @@ module Google
|
|
509
544
|
# {Project#bucket} and {Project#buckets} to indicate the project to
|
510
545
|
# which the access costs should be billed.
|
511
546
|
#
|
547
|
+
# To pass metageneration preconditions, call this method within a
|
548
|
+
# block passed to {#update}.
|
549
|
+
#
|
512
550
|
# @param [Boolean] new_requester_pays When set to `true`, requester pays
|
513
551
|
# is enabled for the bucket.
|
514
552
|
#
|
@@ -550,13 +588,16 @@ module Google
|
|
550
588
|
# bucket.default_kms_key #=> kms_key_name
|
551
589
|
#
|
552
590
|
def default_kms_key
|
553
|
-
@gapi.encryption
|
591
|
+
@gapi.encryption&.default_kms_key_name
|
554
592
|
end
|
555
593
|
|
556
594
|
##
|
557
595
|
# Set the Cloud KMS encryption key that will be used to protect files.
|
558
596
|
# For example: `projects/a/locations/b/keyRings/c/cryptoKeys/d`
|
559
597
|
#
|
598
|
+
# To pass metageneration preconditions, call this method within a
|
599
|
+
# block passed to {#update}.
|
600
|
+
#
|
560
601
|
# @param [String, nil] new_default_kms_key New Cloud KMS key name, or
|
561
602
|
# `nil` to delete the Cloud KMS encryption key.
|
562
603
|
#
|
@@ -599,7 +640,7 @@ module Google
|
|
599
640
|
# retention policy exists for the bucket.
|
600
641
|
#
|
601
642
|
def retention_period
|
602
|
-
@gapi.retention_policy
|
643
|
+
@gapi.retention_policy&.retention_period
|
603
644
|
end
|
604
645
|
|
605
646
|
##
|
@@ -617,6 +658,9 @@ module Google
|
|
617
658
|
# See also: {#lock_retention_policy!}, {#retention_period},
|
618
659
|
# {#retention_effective_at}, and {#retention_policy_locked?}.
|
619
660
|
#
|
661
|
+
# To pass metageneration preconditions, call this method within a
|
662
|
+
# block passed to {#update}.
|
663
|
+
#
|
620
664
|
# @param [Integer, nil] new_retention_period The retention period
|
621
665
|
# defined in seconds. The value must be between 0 and 100 years (in
|
622
666
|
# seconds), or `nil`.
|
@@ -658,7 +702,7 @@ module Google
|
|
658
702
|
# policy, if a policy exists.
|
659
703
|
#
|
660
704
|
def retention_effective_at
|
661
|
-
@gapi.retention_policy
|
705
|
+
@gapi.retention_policy&.effective_time
|
662
706
|
end
|
663
707
|
|
664
708
|
##
|
@@ -715,6 +759,9 @@ module Google
|
|
715
759
|
#
|
716
760
|
# See {File#event_based_hold?} and {File#set_event_based_hold!}.
|
717
761
|
#
|
762
|
+
# To pass metageneration preconditions, call this method within a
|
763
|
+
# block passed to {#update}.
|
764
|
+
#
|
718
765
|
# @param [Boolean] new_default_event_based_hold The default event-based
|
719
766
|
# hold field for the bucket.
|
720
767
|
#
|
@@ -808,7 +855,7 @@ module Google
|
|
808
855
|
# bucket.uniform_bucket_level_access? # true
|
809
856
|
#
|
810
857
|
def uniform_bucket_level_access?
|
811
|
-
return false unless @gapi.iam_configuration
|
858
|
+
return false unless @gapi.iam_configuration&.uniform_bucket_level_access
|
812
859
|
!@gapi.iam_configuration.uniform_bucket_level_access.enabled.nil? &&
|
813
860
|
@gapi.iam_configuration.uniform_bucket_level_access.enabled
|
814
861
|
end
|
@@ -823,6 +870,9 @@ module Google
|
|
823
870
|
# Before enabling uniform bucket-level access please review [uniform bucket-level
|
824
871
|
# access](https://cloud.google.com/storage/docs/uniform-bucket-level-access).
|
825
872
|
#
|
873
|
+
# To pass metageneration preconditions, call this method within a
|
874
|
+
# block passed to {#update}.
|
875
|
+
#
|
826
876
|
# @param [Boolean] new_uniform_bucket_level_access When set to `true`, uniform bucket-level access is enabled in
|
827
877
|
# the bucket's IAM configuration.
|
828
878
|
#
|
@@ -870,7 +920,7 @@ module Google
|
|
870
920
|
# puts bucket.uniform_bucket_level_access_locked_at
|
871
921
|
#
|
872
922
|
def uniform_bucket_level_access_locked_at
|
873
|
-
return nil unless @gapi.iam_configuration
|
923
|
+
return nil unless @gapi.iam_configuration&.uniform_bucket_level_access
|
874
924
|
@gapi.iam_configuration.uniform_bucket_level_access.locked_time
|
875
925
|
end
|
876
926
|
|
@@ -895,6 +945,166 @@ module Google
|
|
895
945
|
uniform_bucket_level_access_locked_at
|
896
946
|
end
|
897
947
|
|
948
|
+
##
|
949
|
+
# The value for Public Access Prevention in the bucket's IAM configuration. Currently, `inherited` and
|
950
|
+
# `enforced` are supported. When set to `enforced`, Public Access Prevention is enforced in the bucket's IAM
|
951
|
+
# configuration. This value can be modified by calling {#public_access_prevention=}.
|
952
|
+
#
|
953
|
+
# @return [String, nil] Currently, `inherited` and `enforced` are supported. Returns `nil` if the bucket has
|
954
|
+
# no IAM configuration.
|
955
|
+
#
|
956
|
+
# @example
|
957
|
+
# require "google/cloud/storage"
|
958
|
+
#
|
959
|
+
# storage = Google::Cloud::Storage.new
|
960
|
+
#
|
961
|
+
# bucket = storage.bucket "my-bucket"
|
962
|
+
#
|
963
|
+
# bucket.public_access_prevention = :enforced
|
964
|
+
# bucket.public_access_prevention #=> "enforced"
|
965
|
+
#
|
966
|
+
def public_access_prevention
|
967
|
+
@gapi.iam_configuration&.public_access_prevention
|
968
|
+
end
|
969
|
+
|
970
|
+
##
|
971
|
+
# Sets the value for Public Access Prevention in the bucket's IAM configuration. This value can be queried by
|
972
|
+
# calling {#public_access_prevention}.
|
973
|
+
#
|
974
|
+
# @param [Symbol, String] new_public_access_prevention The bucket's new Public Access Prevention configuration.
|
975
|
+
# Currently, `inherited` and `enforced` are supported. When set to `enforced`, Public Access
|
976
|
+
# Prevention is enforced in the bucket's IAM configuration.
|
977
|
+
#
|
978
|
+
# @example Set Public Access Prevention to enforced:
|
979
|
+
# require "google/cloud/storage"
|
980
|
+
#
|
981
|
+
# storage = Google::Cloud::Storage.new
|
982
|
+
#
|
983
|
+
# bucket = storage.bucket "my-bucket"
|
984
|
+
#
|
985
|
+
# bucket.public_access_prevention = :enforced
|
986
|
+
# bucket.public_access_prevention #=> "enforced"
|
987
|
+
#
|
988
|
+
# @example Set Public Access Prevention to inherited:
|
989
|
+
# require "google/cloud/storage"
|
990
|
+
#
|
991
|
+
# storage = Google::Cloud::Storage.new
|
992
|
+
#
|
993
|
+
# bucket = storage.bucket "my-bucket"
|
994
|
+
#
|
995
|
+
# bucket.public_access_prevention = :inherited
|
996
|
+
# bucket.public_access_prevention #=> "inherited"
|
997
|
+
#
|
998
|
+
def public_access_prevention= new_public_access_prevention
|
999
|
+
@gapi.iam_configuration ||= API::Bucket::IamConfiguration.new
|
1000
|
+
@gapi.iam_configuration.public_access_prevention = new_public_access_prevention.to_s
|
1001
|
+
patch_gapi! :iam_configuration
|
1002
|
+
end
|
1003
|
+
|
1004
|
+
##
|
1005
|
+
# Whether the bucket's file IAM configuration enforces Public Access Prevention. The default is `false`. This
|
1006
|
+
# value can be modified by calling {Bucket#public_access_prevention=}.
|
1007
|
+
#
|
1008
|
+
# @return [Boolean] Returns `false` if the bucket has no IAM configuration or if Public Access Prevention is
|
1009
|
+
# not `enforced` in the IAM configuration. Returns `true` if Public Access Prevention is `enforced` in the IAM
|
1010
|
+
# configuration.
|
1011
|
+
#
|
1012
|
+
# @example
|
1013
|
+
# require "google/cloud/storage"
|
1014
|
+
#
|
1015
|
+
# storage = Google::Cloud::Storage.new
|
1016
|
+
#
|
1017
|
+
# bucket = storage.bucket "my-bucket"
|
1018
|
+
#
|
1019
|
+
# bucket.public_access_prevention = :enforced
|
1020
|
+
# bucket.public_access_prevention_enforced? # true
|
1021
|
+
#
|
1022
|
+
def public_access_prevention_enforced?
|
1023
|
+
return false unless @gapi.iam_configuration&.public_access_prevention
|
1024
|
+
@gapi.iam_configuration.public_access_prevention.to_s == "enforced"
|
1025
|
+
end
|
1026
|
+
|
1027
|
+
##
|
1028
|
+
# Whether the value for Public Access Prevention in the bucket's IAM configuration is `inherited`. The default
|
1029
|
+
# is `false`. This value can be modified by calling {Bucket#public_access_prevention=}.
|
1030
|
+
#
|
1031
|
+
# @return [Boolean] Returns `false` if the bucket has no IAM configuration or if Public Access Prevention is
|
1032
|
+
# not `inherited` in the IAM configuration. Returns `true` if Public Access Prevention is `inherited` in
|
1033
|
+
# the IAM configuration.
|
1034
|
+
#
|
1035
|
+
# @example
|
1036
|
+
# require "google/cloud/storage"
|
1037
|
+
#
|
1038
|
+
# storage = Google::Cloud::Storage.new
|
1039
|
+
#
|
1040
|
+
# bucket = storage.bucket "my-bucket"
|
1041
|
+
#
|
1042
|
+
# bucket.public_access_prevention = :inherited
|
1043
|
+
# bucket.public_access_prevention_inherited? # true
|
1044
|
+
#
|
1045
|
+
def public_access_prevention_inherited?
|
1046
|
+
return false unless @gapi.iam_configuration&.public_access_prevention
|
1047
|
+
["inherited", "unspecified"].include? @gapi.iam_configuration.public_access_prevention.to_s
|
1048
|
+
end
|
1049
|
+
|
1050
|
+
alias public_access_prevention_unspecified? public_access_prevention_inherited?
|
1051
|
+
|
1052
|
+
##
|
1053
|
+
# Recovery Point Objective (RPO) is another attribute of a bucket, it measures how long it takes for a set of
|
1054
|
+
# updates to be asynchronously copied to the other region.
|
1055
|
+
# Currently, `DEFAULT` and `ASYNC_TURBO` are supported. When set to `ASYNC_TURBO`, Turbo Replication is enabled
|
1056
|
+
# for a bucket. `DEFAULT` is used to reset rpo on an existing bucket with rpo set to `ASYNC_TURBO`.
|
1057
|
+
# This value can be modified by calling {#rpo=}.
|
1058
|
+
#
|
1059
|
+
# @return [String, nil] Currently, `DEFAULT` and `ASYNC_TURBO` are supported. Returns `nil` if the bucket has
|
1060
|
+
# no RPO.
|
1061
|
+
#
|
1062
|
+
# @example
|
1063
|
+
# require "google/cloud/storage"
|
1064
|
+
#
|
1065
|
+
# storage = Google::Cloud::Storage.new
|
1066
|
+
#
|
1067
|
+
# bucket = storage.bucket "my-bucket"
|
1068
|
+
#
|
1069
|
+
# bucket.rpo = :DEFAULT
|
1070
|
+
# bucket.rpo #=> "DEFAULT"
|
1071
|
+
#
|
1072
|
+
def rpo
|
1073
|
+
@gapi.rpo
|
1074
|
+
end
|
1075
|
+
|
1076
|
+
##
|
1077
|
+
# Sets the value for Recovery Point Objective (RPO) in the bucket. This value can be queried by calling {#rpo}.
|
1078
|
+
#
|
1079
|
+
# @param [Symbol, String] new_rpo The bucket's new Recovery Point Objective metadata.
|
1080
|
+
# Currently, `DEFAULT` and `ASYNC_TURBO` are supported. When set to `ASYNC_TURBO`, Turbo Replication
|
1081
|
+
# is enabled for a bucket.
|
1082
|
+
#
|
1083
|
+
# @example Set RPO to DEFAULT:
|
1084
|
+
# require "google/cloud/storage"
|
1085
|
+
#
|
1086
|
+
# storage = Google::Cloud::Storage.new
|
1087
|
+
#
|
1088
|
+
# bucket = storage.bucket "my-bucket"
|
1089
|
+
#
|
1090
|
+
# bucket.rpo = :DEFAULT
|
1091
|
+
# bucket.rpo #=> "DEFAULT"
|
1092
|
+
#
|
1093
|
+
# @example Set RPO to ASYNC_TURBO:
|
1094
|
+
# require "google/cloud/storage"
|
1095
|
+
#
|
1096
|
+
# storage = Google::Cloud::Storage.new
|
1097
|
+
#
|
1098
|
+
# bucket = storage.bucket "my-bucket"
|
1099
|
+
#
|
1100
|
+
# bucket.rpo = :ASYNC_TURBO
|
1101
|
+
# bucket.rpo #=> "ASYNC_TURBO"
|
1102
|
+
#
|
1103
|
+
def rpo= new_rpo
|
1104
|
+
@gapi.rpo = new_rpo&.to_s
|
1105
|
+
patch_gapi! :rpo
|
1106
|
+
end
|
1107
|
+
|
898
1108
|
##
|
899
1109
|
# Updates the bucket with changes made in the given block in a single
|
900
1110
|
# PATCH request. The following attributes may be set: {#cors},
|
@@ -905,6 +1115,12 @@ module Google
|
|
905
1115
|
# completely mutable and will be included in the request. (See
|
906
1116
|
# {Bucket::Cors})
|
907
1117
|
#
|
1118
|
+
# @param [Integer] if_metageneration_match Makes the operation conditional
|
1119
|
+
# on whether the bucket's current metageneration matches the given value.
|
1120
|
+
# @param [Integer] if_metageneration_not_match Makes the operation
|
1121
|
+
# conditional on whether the bucket's current metageneration does not
|
1122
|
+
# match the given value.
|
1123
|
+
#
|
908
1124
|
# @yield [bucket] a block yielding a delegate object for updating the
|
909
1125
|
# file
|
910
1126
|
#
|
@@ -936,14 +1152,27 @@ module Google
|
|
936
1152
|
# end
|
937
1153
|
# end
|
938
1154
|
#
|
939
|
-
|
1155
|
+
# @example With a `if_metageneration_match` precondition:
|
1156
|
+
# require "google/cloud/storage"
|
1157
|
+
#
|
1158
|
+
# storage = Google::Cloud::Storage.new
|
1159
|
+
#
|
1160
|
+
# bucket = storage.bucket "my-todo-app"
|
1161
|
+
# bucket.update if_metageneration_match: 6 do |b|
|
1162
|
+
# b.website_main = "index.html"
|
1163
|
+
# end
|
1164
|
+
#
|
1165
|
+
def update if_metageneration_match: nil, if_metageneration_not_match: nil
|
940
1166
|
updater = Updater.new @gapi
|
941
1167
|
yield updater
|
942
1168
|
# Add check for mutable cors
|
943
1169
|
updater.check_for_changed_labels!
|
944
1170
|
updater.check_for_mutable_cors!
|
945
1171
|
updater.check_for_mutable_lifecycle!
|
946
|
-
|
1172
|
+
return if updater.updates.empty?
|
1173
|
+
patch_gapi! updater.updates,
|
1174
|
+
if_metageneration_match: if_metageneration_match,
|
1175
|
+
if_metageneration_not_match: if_metageneration_not_match
|
947
1176
|
end
|
948
1177
|
|
949
1178
|
##
|
@@ -953,6 +1182,12 @@ module Google
|
|
953
1182
|
# The API call to delete the bucket may be retried under certain
|
954
1183
|
# conditions. See {Google::Cloud#storage} to control this behavior.
|
955
1184
|
#
|
1185
|
+
# @param [Integer] if_metageneration_match Makes the operation conditional
|
1186
|
+
# on whether the bucket's current metageneration matches the given value.
|
1187
|
+
# @param [Integer] if_metageneration_not_match Makes the operation
|
1188
|
+
# conditional on whether the bucket's current metageneration does not
|
1189
|
+
# match the given value.
|
1190
|
+
#
|
956
1191
|
# @return [Boolean] Returns `true` if the bucket was deleted.
|
957
1192
|
#
|
958
1193
|
# @example
|
@@ -963,10 +1198,12 @@ module Google
|
|
963
1198
|
# bucket = storage.bucket "my-bucket"
|
964
1199
|
# bucket.delete
|
965
1200
|
#
|
966
|
-
def delete
|
1201
|
+
def delete if_metageneration_match: nil, if_metageneration_not_match: nil
|
967
1202
|
ensure_service!
|
968
|
-
service.delete_bucket name,
|
969
|
-
|
1203
|
+
service.delete_bucket name,
|
1204
|
+
if_metageneration_match: if_metageneration_match,
|
1205
|
+
if_metageneration_not_match: if_metageneration_not_match,
|
1206
|
+
user_project: user_project
|
970
1207
|
end
|
971
1208
|
|
972
1209
|
##
|
@@ -1040,6 +1277,19 @@ module Google
|
|
1040
1277
|
# @param [String] path Name (path) of the file.
|
1041
1278
|
# @param [Integer] generation When present, selects a specific revision
|
1042
1279
|
# of this object. Default is the latest version.
|
1280
|
+
# @param [Integer] if_generation_match Makes the operation conditional
|
1281
|
+
# on whether the file's current generation matches the given value.
|
1282
|
+
# Setting to 0 makes the operation succeed only if there are no live
|
1283
|
+
# versions of the file.
|
1284
|
+
# @param [Integer] if_generation_not_match Makes the operation conditional
|
1285
|
+
# on whether the file's current generation does not match the given
|
1286
|
+
# value. If no live file exists, the precondition fails. Setting to 0
|
1287
|
+
# makes the operation succeed only if there is a live version of the file.
|
1288
|
+
# @param [Integer] if_metageneration_match Makes the operation conditional
|
1289
|
+
# on whether the file's current metageneration matches the given value.
|
1290
|
+
# @param [Integer] if_metageneration_not_match Makes the operation
|
1291
|
+
# conditional on whether the file's current metageneration does not
|
1292
|
+
# match the given value.
|
1043
1293
|
# @param [Boolean] skip_lookup Optionally create a Bucket object
|
1044
1294
|
# without verifying the bucket resource exists on the Storage service.
|
1045
1295
|
# Calls made on this object will raise errors if the bucket resource
|
@@ -1061,7 +1311,14 @@ module Google
|
|
1061
1311
|
# file = bucket.file "path/to/my-file.ext"
|
1062
1312
|
# puts file.name
|
1063
1313
|
#
|
1064
|
-
def file path,
|
1314
|
+
def file path,
|
1315
|
+
generation: nil,
|
1316
|
+
if_generation_match: nil,
|
1317
|
+
if_generation_not_match: nil,
|
1318
|
+
if_metageneration_match: nil,
|
1319
|
+
if_metageneration_not_match: nil,
|
1320
|
+
skip_lookup: nil,
|
1321
|
+
encryption_key: nil
|
1065
1322
|
ensure_service!
|
1066
1323
|
if skip_lookup
|
1067
1324
|
return File.new_lazy name, path, service,
|
@@ -1069,6 +1326,10 @@ module Google
|
|
1069
1326
|
user_project: user_project
|
1070
1327
|
end
|
1071
1328
|
gapi = service.get_file name, path, generation: generation,
|
1329
|
+
if_generation_match: if_generation_match,
|
1330
|
+
if_generation_not_match: if_generation_not_match,
|
1331
|
+
if_metageneration_match: if_metageneration_match,
|
1332
|
+
if_metageneration_not_match: if_metageneration_not_match,
|
1072
1333
|
key: encryption_key,
|
1073
1334
|
user_project: user_project
|
1074
1335
|
File.from_gapi gapi, service, user_project: user_project
|
@@ -1143,16 +1404,34 @@ module Google
|
|
1143
1404
|
# changed to a time in the future. If custom_time must be unset, you
|
1144
1405
|
# must either perform a rewrite operation, or upload the data again
|
1145
1406
|
# and create a new file.
|
1407
|
+
# @param [Symbol, nil] checksum The type of checksum for the client to
|
1408
|
+
# automatically calculate and send with the create request to verify
|
1409
|
+
# the integrity of the object. If provided, Cloud Storage will only
|
1410
|
+
# create the file if the value calculated by the client matches the
|
1411
|
+
# value calculated by the service.
|
1412
|
+
#
|
1413
|
+
# Acceptable values are:
|
1414
|
+
#
|
1415
|
+
# * `md5` - Calculate and provide a checksum using the MD5 hash.
|
1416
|
+
# * `crc32c` - Calculate and provide a checksum using the CRC32c hash.
|
1417
|
+
# * `all` - Calculate and provide checksums for all available verifications.
|
1418
|
+
#
|
1419
|
+
# Optional. The default is `nil`. Do not provide if also providing a
|
1420
|
+
# corresponding `crc32c` or `md5` argument. See
|
1421
|
+
# [Validation](https://cloud.google.com/storage/docs/hashes-etags)
|
1422
|
+
# for more information.
|
1146
1423
|
# @param [String] crc32c The CRC32c checksum of the file data, as
|
1147
1424
|
# described in [RFC 4960, Appendix
|
1148
1425
|
# B](http://tools.ietf.org/html/rfc4960#appendix-B).
|
1149
1426
|
# If provided, Cloud Storage will only create the file if the value
|
1150
|
-
# matches the value calculated by the service.
|
1427
|
+
# matches the value calculated by the service. Do not provide if also
|
1428
|
+
# providing a `checksum: :crc32c` or `checksum: :all` argument. See
|
1151
1429
|
# [Validation](https://cloud.google.com/storage/docs/hashes-etags)
|
1152
1430
|
# for more information.
|
1153
1431
|
# @param [String] md5 The MD5 hash of the file data. If provided, Cloud
|
1154
1432
|
# Storage will only create the file if the value matches the value
|
1155
|
-
# calculated by the service.
|
1433
|
+
# calculated by the service. Do not provide if also providing a
|
1434
|
+
# `checksum: :md5` or `checksum: :all` argument. See
|
1156
1435
|
# [Validation](https://cloud.google.com/storage/docs/hashes-etags) for
|
1157
1436
|
# more information.
|
1158
1437
|
# @param [Hash] metadata A hash of custom, user-provided web-safe keys
|
@@ -1179,6 +1458,19 @@ module Google
|
|
1179
1458
|
# the same location as the bucket.The Service Account associated with
|
1180
1459
|
# your project requires access to this encryption key. Do not provide
|
1181
1460
|
# if `encryption_key` is used.
|
1461
|
+
# @param [Integer] if_generation_match Makes the operation conditional
|
1462
|
+
# on whether the file's current generation matches the given value.
|
1463
|
+
# Setting to 0 makes the operation succeed only if there are no live
|
1464
|
+
# versions of the file.
|
1465
|
+
# @param [Integer] if_generation_not_match Makes the operation conditional
|
1466
|
+
# on whether the file's current generation does not match the given
|
1467
|
+
# value. If no live file exists, the precondition fails. Setting to 0
|
1468
|
+
# makes the operation succeed only if there is a live version of the file.
|
1469
|
+
# @param [Integer] if_metageneration_match Makes the operation conditional
|
1470
|
+
# on whether the file's current metageneration matches the given value.
|
1471
|
+
# @param [Integer] if_metageneration_not_match Makes the operation
|
1472
|
+
# conditional on whether the file's current metageneration does not
|
1473
|
+
# match the given value.
|
1182
1474
|
#
|
1183
1475
|
# @return [Google::Cloud::Storage::File]
|
1184
1476
|
#
|
@@ -1262,35 +1554,59 @@ module Google
|
|
1262
1554
|
# file.download "path/to/downloaded/gzipped.txt",
|
1263
1555
|
# skip_decompress: true
|
1264
1556
|
#
|
1265
|
-
def create_file file,
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1557
|
+
def create_file file,
|
1558
|
+
path = nil,
|
1559
|
+
acl: nil,
|
1560
|
+
cache_control: nil,
|
1561
|
+
content_disposition: nil,
|
1562
|
+
content_encoding: nil,
|
1563
|
+
content_language: nil,
|
1564
|
+
content_type: nil,
|
1565
|
+
custom_time: nil,
|
1566
|
+
checksum: nil,
|
1567
|
+
crc32c: nil,
|
1568
|
+
md5: nil,
|
1569
|
+
metadata: nil,
|
1570
|
+
storage_class: nil,
|
1571
|
+
encryption_key: nil,
|
1572
|
+
kms_key: nil,
|
1573
|
+
temporary_hold: nil,
|
1574
|
+
event_based_hold: nil,
|
1575
|
+
if_generation_match: nil,
|
1576
|
+
if_generation_not_match: nil,
|
1577
|
+
if_metageneration_match: nil,
|
1578
|
+
if_metageneration_not_match: nil
|
1271
1579
|
ensure_service!
|
1272
1580
|
ensure_io_or_file_exists! file
|
1273
1581
|
path ||= file.path if file.respond_to? :path
|
1274
1582
|
path ||= file if file.is_a? String
|
1275
1583
|
raise ArgumentError, "must provide path" if path.nil?
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1584
|
+
crc32c = crc32c_for file, checksum, crc32c
|
1585
|
+
md5 = md5_for file, checksum, md5
|
1586
|
+
|
1587
|
+
gapi = service.insert_file name,
|
1588
|
+
file,
|
1589
|
+
path,
|
1590
|
+
acl: File::Acl.predefined_rule_for(acl),
|
1591
|
+
md5: md5,
|
1592
|
+
cache_control: cache_control,
|
1593
|
+
content_type: content_type,
|
1594
|
+
custom_time: custom_time,
|
1595
|
+
content_disposition: content_disposition,
|
1596
|
+
crc32c: crc32c,
|
1597
|
+
content_encoding: content_encoding,
|
1598
|
+
metadata: metadata,
|
1599
|
+
content_language: content_language,
|
1600
|
+
key: encryption_key,
|
1601
|
+
kms_key: kms_key,
|
1602
|
+
storage_class: storage_class_for(storage_class),
|
1603
|
+
temporary_hold: temporary_hold,
|
1604
|
+
event_based_hold: event_based_hold,
|
1605
|
+
if_generation_match: if_generation_match,
|
1606
|
+
if_generation_not_match: if_generation_not_match,
|
1607
|
+
if_metageneration_match: if_metageneration_match,
|
1608
|
+
if_metageneration_not_match: if_metageneration_not_match,
|
1609
|
+
user_project: user_project
|
1294
1610
|
File.from_gapi gapi, service, user_project: user_project
|
1295
1611
|
end
|
1296
1612
|
alias upload_file create_file
|
@@ -1334,6 +1650,16 @@ module Google
|
|
1334
1650
|
# used. All source files must have been encrypted with the same key,
|
1335
1651
|
# and the resulting destination file will also be encrypted with the
|
1336
1652
|
# key.
|
1653
|
+
# @param [Array<Integer>] if_source_generation_match Makes the operation
|
1654
|
+
# conditional on whether the source files' current generations match the
|
1655
|
+
# given values. The list must match `sources` item-to-item.
|
1656
|
+
# @param [Integer] if_generation_match Makes the operation conditional
|
1657
|
+
# on whether the destination file's current generation matches the
|
1658
|
+
# given value. Setting to 0 makes the operation succeed only if there
|
1659
|
+
# are no live versions of the file.
|
1660
|
+
# @param [Integer] if_metageneration_match Makes the operation conditional
|
1661
|
+
# on whether the destination file's current metageneration matches the
|
1662
|
+
# given value.
|
1337
1663
|
#
|
1338
1664
|
# @yield [file] A block yielding a delegate file object for setting the
|
1339
1665
|
# properties of the destination file.
|
@@ -1382,7 +1708,13 @@ module Google
|
|
1382
1708
|
#
|
1383
1709
|
# new_file = bucket.compose [file_1, file_2], "path/to/new-file.ext"
|
1384
1710
|
#
|
1385
|
-
def compose sources,
|
1711
|
+
def compose sources,
|
1712
|
+
destination,
|
1713
|
+
acl: nil,
|
1714
|
+
encryption_key: nil,
|
1715
|
+
if_source_generation_match: nil,
|
1716
|
+
if_generation_match: nil,
|
1717
|
+
if_metageneration_match: nil
|
1386
1718
|
ensure_service!
|
1387
1719
|
sources = Array sources
|
1388
1720
|
if sources.size < 2
|
@@ -1398,9 +1730,16 @@ module Google
|
|
1398
1730
|
end
|
1399
1731
|
|
1400
1732
|
acl_rule = File::Acl.predefined_rule_for acl
|
1401
|
-
gapi = service.compose_file name,
|
1402
|
-
|
1403
|
-
|
1733
|
+
gapi = service.compose_file name,
|
1734
|
+
sources,
|
1735
|
+
destination,
|
1736
|
+
destination_gapi,
|
1737
|
+
acl: acl_rule,
|
1738
|
+
key: encryption_key,
|
1739
|
+
if_source_generation_match: if_source_generation_match,
|
1740
|
+
if_generation_match: if_generation_match,
|
1741
|
+
if_metageneration_match: if_metageneration_match,
|
1742
|
+
user_project: user_project
|
1404
1743
|
File.from_gapi gapi, service, user_project: user_project
|
1405
1744
|
end
|
1406
1745
|
alias compose_file compose
|
@@ -1545,11 +1884,11 @@ module Google
|
|
1545
1884
|
# scopes = ["https://www.googleapis.com/auth/iam"]
|
1546
1885
|
# iam_client.authorization = Google::Auth.get_application_default scopes
|
1547
1886
|
#
|
1548
|
-
# request =
|
1549
|
-
#
|
1550
|
-
#
|
1887
|
+
# request = Google::Apis::IamcredentialsV1::SignBlobRequest.new(
|
1888
|
+
# payload: string_to_sign
|
1889
|
+
# )
|
1551
1890
|
# resource = "projects/-/serviceAccounts/#{issuer}"
|
1552
|
-
# response = iam_client.sign_service_account_blob resource, request
|
1891
|
+
# response = iam_client.sign_service_account_blob resource, request
|
1553
1892
|
# response.signed_blob
|
1554
1893
|
# end
|
1555
1894
|
#
|
@@ -1778,11 +2117,11 @@ module Google
|
|
1778
2117
|
# scopes = ["https://www.googleapis.com/auth/iam"]
|
1779
2118
|
# iam_client.authorization = Google::Auth.get_application_default scopes
|
1780
2119
|
#
|
1781
|
-
# request =
|
1782
|
-
#
|
1783
|
-
#
|
2120
|
+
# request = Google::Apis::IamcredentialsV1::SignBlobRequest.new(
|
2121
|
+
# payload: string_to_sign
|
2122
|
+
# )
|
1784
2123
|
# resource = "projects/-/serviceAccounts/#{issuer}"
|
1785
|
-
# response = iam_client.sign_service_account_blob resource, request
|
2124
|
+
# response = iam_client.sign_service_account_blob resource, request
|
1786
2125
|
# response.signed_blob
|
1787
2126
|
# end
|
1788
2127
|
#
|
@@ -1928,11 +2267,11 @@ module Google
|
|
1928
2267
|
# scopes = ["https://www.googleapis.com/auth/iam"]
|
1929
2268
|
# iam_client.authorization = Google::Auth.get_application_default scopes
|
1930
2269
|
#
|
1931
|
-
# request =
|
1932
|
-
#
|
1933
|
-
#
|
2270
|
+
# request = Google::Apis::IamcredentialsV1::SignBlobRequest.new(
|
2271
|
+
# payload: string_to_sign
|
2272
|
+
# )
|
1934
2273
|
# resource = "projects/-/serviceAccounts/#{issuer}"
|
1935
|
-
# response = iam_client.sign_service_account_blob resource, request
|
2274
|
+
# response = iam_client.sign_service_account_blob resource, request
|
1936
2275
|
# response.signed_blob
|
1937
2276
|
# end
|
1938
2277
|
#
|
@@ -2546,7 +2885,10 @@ module Google
|
|
2546
2885
|
reload!
|
2547
2886
|
end
|
2548
2887
|
|
2549
|
-
def patch_gapi!
|
2888
|
+
def patch_gapi! attributes,
|
2889
|
+
if_metageneration_match: nil,
|
2890
|
+
if_metageneration_not_match: nil
|
2891
|
+
attributes = Array(attributes)
|
2550
2892
|
attributes.flatten!
|
2551
2893
|
return if attributes.empty?
|
2552
2894
|
ensure_service!
|
@@ -2554,7 +2896,10 @@ module Google
|
|
2554
2896
|
[attr, @gapi.send(attr)]
|
2555
2897
|
end]
|
2556
2898
|
patch_gapi = API::Bucket.new(**patch_args)
|
2557
|
-
@gapi = service.patch_bucket name,
|
2899
|
+
@gapi = service.patch_bucket name,
|
2900
|
+
patch_gapi,
|
2901
|
+
if_metageneration_match: if_metageneration_match,
|
2902
|
+
if_metageneration_not_match: if_metageneration_not_match,
|
2558
2903
|
user_project: user_project
|
2559
2904
|
@lazy = nil
|
2560
2905
|
self
|
@@ -2568,13 +2913,27 @@ module Google
|
|
2568
2913
|
raise ArgumentError, "cannot find file #{file}"
|
2569
2914
|
end
|
2570
2915
|
|
2916
|
+
def crc32c_for source, checksum, crc32c
|
2917
|
+
return crc32c unless [:crc32c, :all].include? checksum
|
2918
|
+
raise ArgumentError, "'checksum: :crc32c' or 'checksum: :all' is present with 'crc32c' arg" if crc32c
|
2919
|
+
File::Verifier.crc32c_for source
|
2920
|
+
end
|
2921
|
+
|
2922
|
+
def md5_for source, checksum, md5
|
2923
|
+
return md5 unless [:md5, :all].include? checksum
|
2924
|
+
raise ArgumentError, "'checksum: :md5' or 'checksum: :all' is present with 'md5' arg" if md5
|
2925
|
+
File::Verifier.md5_for source
|
2926
|
+
end
|
2927
|
+
|
2571
2928
|
##
|
2572
2929
|
# Yielded to a block to accumulate changes for a patch request.
|
2573
2930
|
class Updater < Bucket
|
2574
2931
|
attr_reader :updates
|
2932
|
+
|
2575
2933
|
##
|
2576
2934
|
# Create an Updater object.
|
2577
2935
|
def initialize gapi
|
2936
|
+
super()
|
2578
2937
|
@updates = []
|
2579
2938
|
@gapi = gapi
|
2580
2939
|
@labels = @gapi.labels.to_h.dup
|