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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad286a8539024ffcee1d0239c7db682e3ddb4b6663e5e172354123fa607b96fc
4
- data.tar.gz: 29e8c237d1f891d46bddea92ff3151a08c11c32e936376f040d50159668a8f69
3
+ metadata.gz: 6900463b2861e35e33cef3bda84de638f0f9e7d80e8424755f5eef311bd20352
4
+ data.tar.gz: 6469082cd9d6b158a71a808874104e20128187c4c611a0fe71dbd80b0f68e54e
5
5
  SHA512:
6
- metadata.gz: b7121fbfee2ad413e88d6edfbe83c535a9b17173d2431919e72fed6e8f4eba4c94f84b64d588ade51f50d8f20556a8bef37c6ad8cdaeaca8d6fb58a280168825
7
- data.tar.gz: 0cb221a85541a6af70d8be63dd137915110eda09295e9711c566ec669bd574376a1f0125c4ebc559efa0a19268569dc74cd2548891400501d9af6bdfe62da8ce
6
+ metadata.gz: 4d32314a8813b66cf6ec488be10c8ac174cb71a54d175cff9f33809a529f4851ff2482a43c646f114c91cac4bf7fbc90cc4135caab85d1a55ab8c732f11c1c5f
7
+ data.tar.gz: '08382f70eb5759b7ccb98ac0bb793bed114bd3fcc24b6ca8e3ecc02af2e60540f1761d36133d8299b043155d260d9a659ab2d5b0cda6a27eb40ead70d7b7d6d1'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,60 @@
1
1
  # Release History
2
2
 
3
+ ### 1.33.0 / 2021-06-29
4
+
5
+ #### Features
6
+
7
+ * Add support for PublicAccessPrevention
8
+ * Add Bucket#public_access_prevention
9
+ * Add Bucket#public_access_prevention=
10
+ * Add Bucket#public_access_prevention_enforced?
11
+ * Add Bucket#public_access_prevention_unspecified?
12
+ * Add samples for PublicAccessPrevention
13
+
14
+ ### 1.32.0 / 2021-06-22
15
+
16
+ #### Features
17
+
18
+ * Add sources_if_generation_match to Bucket#compose
19
+ * Add support for (meta)generation preconditions to File operations
20
+ * Add if_(meta)generation_match options to Bucket#compose
21
+ * Add if_(meta)generation_(not_)match options to Bucket#create_file
22
+ * Add if_(meta)generation_(not_)match options to Bucket#file
23
+ * Add if_(meta)generation_(not_)match options to File#delete.
24
+ * Add if_(meta)generation_(not_)match options to File#rewrite
25
+ * Add generation and if_(meta)generation_(not_)match options to File#update
26
+ * Add generation and if_(meta)generation_(not_)match options to File::Acl predefined_acl methods
27
+
28
+ #### Bug Fixes
29
+
30
+ * Expand googleauth dependency to support future 1.x versions
31
+ * Update File::Verifier to test for File#to_path
32
+
33
+ ### 1.31.1 / 2021-05-19
34
+
35
+ #### Documentation
36
+
37
+ * Update IAMCredentialsService#sign_service_account_blob examples
38
+
39
+ ### 1.31.0 / 2021-03-10
40
+
41
+ #### Features
42
+
43
+ * Drop support for Ruby 2.4 and add support for Ruby 3.0
44
+
45
+ ### 1.30.0 / 2021-01-13
46
+
47
+ #### Features
48
+
49
+ * Replace google-api-client with specific client gems
50
+ * Remove google-api-client
51
+ * Add google-apis-iamcredentials_v1
52
+ * Add google-apis-storage_v1
53
+
54
+ #### Documentation
55
+
56
+ * Update Bucket#generate_signed_post_policy_v4 documentation
57
+
3
58
  ### 1.29.2 / 2020-12-14
4
59
 
5
60
  #### Bug Fixes
data/CONTRIBUTING.md CHANGED
@@ -24,7 +24,7 @@ be able to accept your pull requests.
24
24
  In order to use the google-cloud-storage console and run the project's tests,
25
25
  there is a small amount of setup:
26
26
 
27
- 1. Install Ruby. google-cloud-storage requires Ruby 2.4+. You may choose to
27
+ 1. Install Ruby. google-cloud-storage requires Ruby 2.5+. You may choose to
28
28
  manage your Ruby and gem installations with [RVM](https://rvm.io/),
29
29
  [rbenv](https://github.com/rbenv/rbenv), or
30
30
  [chruby](https://github.com/postmodern/chruby).
@@ -119,15 +119,14 @@ If you alter an example's title, you may encounter breaking tests.
119
119
  ### Storage Acceptance Tests
120
120
 
121
121
  The Storage acceptance tests interact with the live service API. Follow the
122
- instructions in the {file:AUTHENTICATION.md Authentication guide} for enabling
122
+ instructions in the {file:AUTHENTICATION.md Authentication Guide} for enabling
123
123
  the Storage API. Occasionally, some API features may not yet be generally
124
124
  available, making it difficult for some contributors to successfully run the
125
125
  entire acceptance test suite. However, please ensure that you do successfully
126
126
  run acceptance tests for any code areas covered by your pull request.
127
127
 
128
128
  To run the acceptance tests, first create and configure a project in the Google
129
- Developers Console, as described in the {file:AUTHENTICATION.md Authentication
130
- guide}. Be sure to download the JSON KEY file. Make note of the PROJECT_ID and
129
+ Developers Console, as described in the {file:AUTHENTICATION.md Authentication Guide}. Be sure to download the JSON KEY file. Make note of the PROJECT_ID and
131
130
  the KEYFILE location on your system.
132
131
 
133
132
  Before you can run the Storage acceptance tests, you must first create indexes
@@ -309,12 +309,15 @@ module Google
309
309
  # @see https://cloud.google.com/storage/docs/access-logs Access Logs
310
310
  #
311
311
  def logging_bucket
312
- @gapi.logging.log_bucket if @gapi.logging
312
+ @gapi.logging&.log_bucket
313
313
  end
314
314
 
315
315
  ##
316
316
  # Updates the destination bucket for the bucket's logs.
317
317
  #
318
+ # To pass metageneration preconditions, call this method within a
319
+ # block passed to {#update}.
320
+ #
318
321
  # @see https://cloud.google.com/storage/docs/access-logs Access Logs
319
322
  #
320
323
  # @param [String] logging_bucket The bucket to hold the logging output
@@ -333,7 +336,7 @@ module Google
333
336
  # @return [String]
334
337
  #
335
338
  def logging_prefix
336
- @gapi.logging.log_object_prefix if @gapi.logging
339
+ @gapi.logging&.log_object_prefix
337
340
  end
338
341
 
339
342
  ##
@@ -344,6 +347,9 @@ module Google
344
347
  # By default, the object prefix is the name of the bucket for which the
345
348
  # logs are enabled.
346
349
  #
350
+ # To pass metageneration preconditions, call this method within a
351
+ # block passed to {#update}.
352
+ #
347
353
  # @see https://cloud.google.com/storage/docs/access-logs Access Logs
348
354
  #
349
355
  # @param [String] logging_prefix The logging object prefix.
@@ -377,6 +383,9 @@ module Google
377
383
  # For more information, see [Storage
378
384
  # Classes](https://cloud.google.com/storage/docs/storage-classes).
379
385
  #
386
+ # To pass metageneration preconditions, call this method within a
387
+ # block passed to {#update}.
388
+ #
380
389
  # @param [Symbol, String] new_storage_class Storage class of the bucket.
381
390
  #
382
391
  def storage_class= new_storage_class
@@ -392,7 +401,7 @@ module Google
392
401
  # @return [Boolean]
393
402
  #
394
403
  def versioning?
395
- @gapi.versioning.enabled? unless @gapi.versioning.nil?
404
+ @gapi.versioning&.enabled?
396
405
  end
397
406
 
398
407
  ##
@@ -400,6 +409,9 @@ module Google
400
409
  # Versioning](https://cloud.google.com/storage/docs/object-versioning)
401
410
  # is enabled for the bucket.
402
411
  #
412
+ # To pass metageneration preconditions, call this method within a
413
+ # block passed to {#update}.
414
+ #
403
415
  # @param [Boolean] new_versioning true if versioning is to be enabled
404
416
  # for the bucket.
405
417
  #
@@ -422,12 +434,15 @@ module Google
422
434
  # @return [String] The main page suffix.
423
435
  #
424
436
  def website_main
425
- @gapi.website.main_page_suffix if @gapi.website
437
+ @gapi.website&.main_page_suffix
426
438
  end
427
439
 
428
440
  ##
429
441
  # Updates the main page suffix for a static website.
430
442
  #
443
+ # To pass metageneration preconditions, call this method within a
444
+ # block passed to {#update}.
445
+ #
431
446
  # @see https://cloud.google.com/storage/docs/website-configuration#step4
432
447
  # How to Host a Static Website
433
448
  #
@@ -449,7 +464,7 @@ module Google
449
464
  # @return [String]
450
465
  #
451
466
  def website_404
452
- @gapi.website.not_found_page if @gapi.website
467
+ @gapi.website&.not_found_page
453
468
  end
454
469
 
455
470
  ##
@@ -467,6 +482,9 @@ module Google
467
482
  ##
468
483
  # Updates the hash of user-provided labels.
469
484
  #
485
+ # To pass metageneration preconditions, call this method within a
486
+ # block passed to {#update}.
487
+ #
470
488
  # @param [Hash(String => String)] labels The user-provided labels.
471
489
  #
472
490
  def labels= labels
@@ -478,6 +496,9 @@ module Google
478
496
  # Updates the page returned from a static website served from the bucket
479
497
  # when a site visitor requests a resource that does not exist.
480
498
  #
499
+ # To pass metageneration preconditions, call this method within a
500
+ # block passed to {#update}.
501
+ #
481
502
  # @see https://cloud.google.com/storage/docs/website-configuration#step4
482
503
  # How to Host a Static Website
483
504
  #
@@ -498,7 +519,7 @@ module Google
498
519
  # the bucket.
499
520
  #
500
521
  def requester_pays
501
- @gapi.billing.requester_pays if @gapi.billing
522
+ @gapi.billing&.requester_pays
502
523
  end
503
524
  alias requester_pays? requester_pays
504
525
 
@@ -509,6 +530,9 @@ module Google
509
530
  # {Project#bucket} and {Project#buckets} to indicate the project to
510
531
  # which the access costs should be billed.
511
532
  #
533
+ # To pass metageneration preconditions, call this method within a
534
+ # block passed to {#update}.
535
+ #
512
536
  # @param [Boolean] new_requester_pays When set to `true`, requester pays
513
537
  # is enabled for the bucket.
514
538
  #
@@ -550,13 +574,16 @@ module Google
550
574
  # bucket.default_kms_key #=> kms_key_name
551
575
  #
552
576
  def default_kms_key
553
- @gapi.encryption && @gapi.encryption.default_kms_key_name
577
+ @gapi.encryption&.default_kms_key_name
554
578
  end
555
579
 
556
580
  ##
557
581
  # Set the Cloud KMS encryption key that will be used to protect files.
558
582
  # For example: `projects/a/locations/b/keyRings/c/cryptoKeys/d`
559
583
  #
584
+ # To pass metageneration preconditions, call this method within a
585
+ # block passed to {#update}.
586
+ #
560
587
  # @param [String, nil] new_default_kms_key New Cloud KMS key name, or
561
588
  # `nil` to delete the Cloud KMS encryption key.
562
589
  #
@@ -599,7 +626,7 @@ module Google
599
626
  # retention policy exists for the bucket.
600
627
  #
601
628
  def retention_period
602
- @gapi.retention_policy && @gapi.retention_policy.retention_period
629
+ @gapi.retention_policy&.retention_period
603
630
  end
604
631
 
605
632
  ##
@@ -617,6 +644,9 @@ module Google
617
644
  # See also: {#lock_retention_policy!}, {#retention_period},
618
645
  # {#retention_effective_at}, and {#retention_policy_locked?}.
619
646
  #
647
+ # To pass metageneration preconditions, call this method within a
648
+ # block passed to {#update}.
649
+ #
620
650
  # @param [Integer, nil] new_retention_period The retention period
621
651
  # defined in seconds. The value must be between 0 and 100 years (in
622
652
  # seconds), or `nil`.
@@ -658,7 +688,7 @@ module Google
658
688
  # policy, if a policy exists.
659
689
  #
660
690
  def retention_effective_at
661
- @gapi.retention_policy && @gapi.retention_policy.effective_time
691
+ @gapi.retention_policy&.effective_time
662
692
  end
663
693
 
664
694
  ##
@@ -715,6 +745,9 @@ module Google
715
745
  #
716
746
  # See {File#event_based_hold?} and {File#set_event_based_hold!}.
717
747
  #
748
+ # To pass metageneration preconditions, call this method within a
749
+ # block passed to {#update}.
750
+ #
718
751
  # @param [Boolean] new_default_event_based_hold The default event-based
719
752
  # hold field for the bucket.
720
753
  #
@@ -808,7 +841,7 @@ module Google
808
841
  # bucket.uniform_bucket_level_access? # true
809
842
  #
810
843
  def uniform_bucket_level_access?
811
- return false unless @gapi.iam_configuration && @gapi.iam_configuration.uniform_bucket_level_access
844
+ return false unless @gapi.iam_configuration&.uniform_bucket_level_access
812
845
  !@gapi.iam_configuration.uniform_bucket_level_access.enabled.nil? &&
813
846
  @gapi.iam_configuration.uniform_bucket_level_access.enabled
814
847
  end
@@ -823,6 +856,9 @@ module Google
823
856
  # Before enabling uniform bucket-level access please review [uniform bucket-level
824
857
  # access](https://cloud.google.com/storage/docs/uniform-bucket-level-access).
825
858
  #
859
+ # To pass metageneration preconditions, call this method within a
860
+ # block passed to {#update}.
861
+ #
826
862
  # @param [Boolean] new_uniform_bucket_level_access When set to `true`, uniform bucket-level access is enabled in
827
863
  # the bucket's IAM configuration.
828
864
  #
@@ -870,7 +906,7 @@ module Google
870
906
  # puts bucket.uniform_bucket_level_access_locked_at
871
907
  #
872
908
  def uniform_bucket_level_access_locked_at
873
- return nil unless @gapi.iam_configuration && @gapi.iam_configuration.uniform_bucket_level_access
909
+ return nil unless @gapi.iam_configuration&.uniform_bucket_level_access
874
910
  @gapi.iam_configuration.uniform_bucket_level_access.locked_time
875
911
  end
876
912
 
@@ -895,6 +931,108 @@ module Google
895
931
  uniform_bucket_level_access_locked_at
896
932
  end
897
933
 
934
+ ##
935
+ # The value for Public Access Prevention in the bucket's IAM configuration. Currently, `unspecified` and
936
+ # `enforced` are supported. When set to `enforced`, Public Access Prevention is enforced in the bucket's IAM
937
+ # configuration. This value can be modified by calling {#public_access_prevention=}.
938
+ #
939
+ # @return [String, nil] Currently, `unspecified` and `enforced` are supported. Returns `nil` if the bucket has
940
+ # no IAM configuration.
941
+ #
942
+ # @example
943
+ # require "google/cloud/storage"
944
+ #
945
+ # storage = Google::Cloud::Storage.new
946
+ #
947
+ # bucket = storage.bucket "my-bucket"
948
+ #
949
+ # bucket.public_access_prevention = :enforced
950
+ # bucket.public_access_prevention #=> "enforced"
951
+ #
952
+ def public_access_prevention
953
+ @gapi.iam_configuration&.public_access_prevention
954
+ end
955
+
956
+ ##
957
+ # Sets the value for Public Access Prevention in the bucket's IAM configuration. This value can be queried by
958
+ # calling {#public_access_prevention}.
959
+ #
960
+ # @param [Symbol, String] new_public_access_prevention The bucket's new Public Access Prevention configuration.
961
+ # Currently, `unspecified` and `enforced` are supported. When set to `enforced`, Public Access
962
+ # Prevention is enforced in the bucket's IAM configuration.
963
+ #
964
+ # @example Set Public Access Prevention to enforced:
965
+ # require "google/cloud/storage"
966
+ #
967
+ # storage = Google::Cloud::Storage.new
968
+ #
969
+ # bucket = storage.bucket "my-bucket"
970
+ #
971
+ # bucket.public_access_prevention = :enforced
972
+ # bucket.public_access_prevention #=> "enforced"
973
+ #
974
+ # @example Set Public Access Prevention to unspecified:
975
+ # require "google/cloud/storage"
976
+ #
977
+ # storage = Google::Cloud::Storage.new
978
+ #
979
+ # bucket = storage.bucket "my-bucket"
980
+ #
981
+ # bucket.public_access_prevention = :unspecified
982
+ # bucket.public_access_prevention #=> "unspecified"
983
+ #
984
+ def public_access_prevention= new_public_access_prevention
985
+ @gapi.iam_configuration ||= API::Bucket::IamConfiguration.new
986
+ @gapi.iam_configuration.public_access_prevention = new_public_access_prevention.to_s
987
+ patch_gapi! :iam_configuration
988
+ end
989
+
990
+ ##
991
+ # Whether the bucket's file IAM configuration enforces Public Access Prevention. The default is `false`. This
992
+ # value can be modified by calling {Bucket#public_access_prevention=}.
993
+ #
994
+ # @return [Boolean] Returns `false` if the bucket has no IAM configuration or if Public Access Prevention is
995
+ # not `enforced` in the IAM configuration. Returns `true` if Public Access Prevention is `enforced` in the IAM
996
+ # configuration.
997
+ #
998
+ # @example
999
+ # require "google/cloud/storage"
1000
+ #
1001
+ # storage = Google::Cloud::Storage.new
1002
+ #
1003
+ # bucket = storage.bucket "my-bucket"
1004
+ #
1005
+ # bucket.public_access_prevention = :enforced
1006
+ # bucket.public_access_prevention_enforced? # true
1007
+ #
1008
+ def public_access_prevention_enforced?
1009
+ return false unless @gapi.iam_configuration&.public_access_prevention
1010
+ @gapi.iam_configuration.public_access_prevention.to_s == "enforced"
1011
+ end
1012
+
1013
+ ##
1014
+ # Whether the value for Public Access Prevention in the bucket's IAM configuration is `unspecified`. The default
1015
+ # is `false`. This value can be modified by calling {Bucket#public_access_prevention=}.
1016
+ #
1017
+ # @return [Boolean] Returns `false` if the bucket has no IAM configuration or if Public Access Prevention is
1018
+ # not `unspecified` in the IAM configuration. Returns `true` if Public Access Prevention is `unspecified` in
1019
+ # the IAM configuration.
1020
+ #
1021
+ # @example
1022
+ # require "google/cloud/storage"
1023
+ #
1024
+ # storage = Google::Cloud::Storage.new
1025
+ #
1026
+ # bucket = storage.bucket "my-bucket"
1027
+ #
1028
+ # bucket.public_access_prevention = :unspecified
1029
+ # bucket.public_access_prevention_unspecified? # true
1030
+ #
1031
+ def public_access_prevention_unspecified?
1032
+ return false unless @gapi.iam_configuration&.public_access_prevention
1033
+ @gapi.iam_configuration.public_access_prevention.to_s == "unspecified"
1034
+ end
1035
+
898
1036
  ##
899
1037
  # Updates the bucket with changes made in the given block in a single
900
1038
  # PATCH request. The following attributes may be set: {#cors},
@@ -905,6 +1043,12 @@ module Google
905
1043
  # completely mutable and will be included in the request. (See
906
1044
  # {Bucket::Cors})
907
1045
  #
1046
+ # @param [Integer] if_metageneration_match Makes the operation conditional
1047
+ # on whether the bucket's current metageneration matches the given value.
1048
+ # @param [Integer] if_metageneration_not_match Makes the operation
1049
+ # conditional on whether the bucket's current metageneration does not
1050
+ # match the given value.
1051
+ #
908
1052
  # @yield [bucket] a block yielding a delegate object for updating the
909
1053
  # file
910
1054
  #
@@ -936,14 +1080,27 @@ module Google
936
1080
  # end
937
1081
  # end
938
1082
  #
939
- def update
1083
+ # @example With a `if_metageneration_match` precondition:
1084
+ # require "google/cloud/storage"
1085
+ #
1086
+ # storage = Google::Cloud::Storage.new
1087
+ #
1088
+ # bucket = storage.bucket "my-todo-app"
1089
+ # bucket.update if_metageneration_match: 6 do |b|
1090
+ # b.website_main = "index.html"
1091
+ # end
1092
+ #
1093
+ def update if_metageneration_match: nil, if_metageneration_not_match: nil
940
1094
  updater = Updater.new @gapi
941
1095
  yield updater
942
1096
  # Add check for mutable cors
943
1097
  updater.check_for_changed_labels!
944
1098
  updater.check_for_mutable_cors!
945
1099
  updater.check_for_mutable_lifecycle!
946
- patch_gapi! updater.updates unless updater.updates.empty?
1100
+ return if updater.updates.empty?
1101
+ patch_gapi! updater.updates,
1102
+ if_metageneration_match: if_metageneration_match,
1103
+ if_metageneration_not_match: if_metageneration_not_match
947
1104
  end
948
1105
 
949
1106
  ##
@@ -953,6 +1110,12 @@ module Google
953
1110
  # The API call to delete the bucket may be retried under certain
954
1111
  # conditions. See {Google::Cloud#storage} to control this behavior.
955
1112
  #
1113
+ # @param [Integer] if_metageneration_match Makes the operation conditional
1114
+ # on whether the bucket's current metageneration matches the given value.
1115
+ # @param [Integer] if_metageneration_not_match Makes the operation
1116
+ # conditional on whether the bucket's current metageneration does not
1117
+ # match the given value.
1118
+ #
956
1119
  # @return [Boolean] Returns `true` if the bucket was deleted.
957
1120
  #
958
1121
  # @example
@@ -963,10 +1126,12 @@ module Google
963
1126
  # bucket = storage.bucket "my-bucket"
964
1127
  # bucket.delete
965
1128
  #
966
- def delete
1129
+ def delete if_metageneration_match: nil, if_metageneration_not_match: nil
967
1130
  ensure_service!
968
- service.delete_bucket name, user_project: user_project
969
- true
1131
+ service.delete_bucket name,
1132
+ if_metageneration_match: if_metageneration_match,
1133
+ if_metageneration_not_match: if_metageneration_not_match,
1134
+ user_project: user_project
970
1135
  end
971
1136
 
972
1137
  ##
@@ -1040,6 +1205,19 @@ module Google
1040
1205
  # @param [String] path Name (path) of the file.
1041
1206
  # @param [Integer] generation When present, selects a specific revision
1042
1207
  # of this object. Default is the latest version.
1208
+ # @param [Integer] if_generation_match Makes the operation conditional
1209
+ # on whether the file's current generation matches the given value.
1210
+ # Setting to 0 makes the operation succeed only if there are no live
1211
+ # versions of the file.
1212
+ # @param [Integer] if_generation_not_match Makes the operation conditional
1213
+ # on whether the file's current generation does not match the given
1214
+ # value. If no live file exists, the precondition fails. Setting to 0
1215
+ # makes the operation succeed only if there is a live version of the file.
1216
+ # @param [Integer] if_metageneration_match Makes the operation conditional
1217
+ # on whether the file's current metageneration matches the given value.
1218
+ # @param [Integer] if_metageneration_not_match Makes the operation
1219
+ # conditional on whether the file's current metageneration does not
1220
+ # match the given value.
1043
1221
  # @param [Boolean] skip_lookup Optionally create a Bucket object
1044
1222
  # without verifying the bucket resource exists on the Storage service.
1045
1223
  # Calls made on this object will raise errors if the bucket resource
@@ -1061,7 +1239,14 @@ module Google
1061
1239
  # file = bucket.file "path/to/my-file.ext"
1062
1240
  # puts file.name
1063
1241
  #
1064
- def file path, generation: nil, skip_lookup: nil, encryption_key: nil
1242
+ def file path,
1243
+ generation: nil,
1244
+ if_generation_match: nil,
1245
+ if_generation_not_match: nil,
1246
+ if_metageneration_match: nil,
1247
+ if_metageneration_not_match: nil,
1248
+ skip_lookup: nil,
1249
+ encryption_key: nil
1065
1250
  ensure_service!
1066
1251
  if skip_lookup
1067
1252
  return File.new_lazy name, path, service,
@@ -1069,6 +1254,10 @@ module Google
1069
1254
  user_project: user_project
1070
1255
  end
1071
1256
  gapi = service.get_file name, path, generation: generation,
1257
+ if_generation_match: if_generation_match,
1258
+ if_generation_not_match: if_generation_not_match,
1259
+ if_metageneration_match: if_metageneration_match,
1260
+ if_metageneration_not_match: if_metageneration_not_match,
1072
1261
  key: encryption_key,
1073
1262
  user_project: user_project
1074
1263
  File.from_gapi gapi, service, user_project: user_project
@@ -1179,6 +1368,19 @@ module Google
1179
1368
  # the same location as the bucket.The Service Account associated with
1180
1369
  # your project requires access to this encryption key. Do not provide
1181
1370
  # if `encryption_key` is used.
1371
+ # @param [Integer] if_generation_match Makes the operation conditional
1372
+ # on whether the file's current generation matches the given value.
1373
+ # Setting to 0 makes the operation succeed only if there are no live
1374
+ # versions of the file.
1375
+ # @param [Integer] if_generation_not_match Makes the operation conditional
1376
+ # on whether the file's current generation does not match the given
1377
+ # value. If no live file exists, the precondition fails. Setting to 0
1378
+ # makes the operation succeed only if there is a live version of the file.
1379
+ # @param [Integer] if_metageneration_match Makes the operation conditional
1380
+ # on whether the file's current metageneration matches the given value.
1381
+ # @param [Integer] if_metageneration_not_match Makes the operation
1382
+ # conditional on whether the file's current metageneration does not
1383
+ # match the given value.
1182
1384
  #
1183
1385
  # @return [Google::Cloud::Storage::File]
1184
1386
  #
@@ -1262,12 +1464,27 @@ module Google
1262
1464
  # file.download "path/to/downloaded/gzipped.txt",
1263
1465
  # skip_decompress: true
1264
1466
  #
1265
- def create_file file, path = nil, acl: nil, cache_control: nil,
1266
- content_disposition: nil, content_encoding: nil,
1267
- content_language: nil, content_type: nil, custom_time: nil,
1268
- crc32c: nil, md5: nil, metadata: nil,
1269
- storage_class: nil, encryption_key: nil, kms_key: nil,
1270
- temporary_hold: nil, event_based_hold: nil
1467
+ def create_file file,
1468
+ path = nil,
1469
+ acl: nil,
1470
+ cache_control: nil,
1471
+ content_disposition: nil,
1472
+ content_encoding: nil,
1473
+ content_language: nil,
1474
+ content_type: nil,
1475
+ custom_time: nil,
1476
+ crc32c: nil,
1477
+ md5: nil,
1478
+ metadata: nil,
1479
+ storage_class: nil,
1480
+ encryption_key: nil,
1481
+ kms_key: nil,
1482
+ temporary_hold: nil,
1483
+ event_based_hold: nil,
1484
+ if_generation_match: nil,
1485
+ if_generation_not_match: nil,
1486
+ if_metageneration_match: nil,
1487
+ if_metageneration_not_match: nil
1271
1488
  ensure_service!
1272
1489
  ensure_io_or_file_exists! file
1273
1490
  path ||= file.path if file.respond_to? :path
@@ -1275,22 +1492,29 @@ module Google
1275
1492
  raise ArgumentError, "must provide path" if path.nil?
1276
1493
 
1277
1494
 
1278
- gapi = service.insert_file name, file, path, acl: File::Acl.predefined_rule_for(acl),
1279
- md5: md5,
1280
- cache_control: cache_control,
1281
- content_type: content_type,
1282
- custom_time: custom_time,
1283
- content_disposition: content_disposition,
1284
- crc32c: crc32c,
1285
- content_encoding: content_encoding,
1286
- metadata: metadata,
1287
- content_language: content_language,
1288
- key: encryption_key,
1289
- kms_key: kms_key,
1290
- storage_class: storage_class_for(storage_class),
1291
- temporary_hold: temporary_hold,
1292
- event_based_hold: event_based_hold,
1293
- user_project: user_project
1495
+ gapi = service.insert_file name,
1496
+ file,
1497
+ path,
1498
+ acl: File::Acl.predefined_rule_for(acl),
1499
+ md5: md5,
1500
+ cache_control: cache_control,
1501
+ content_type: content_type,
1502
+ custom_time: custom_time,
1503
+ content_disposition: content_disposition,
1504
+ crc32c: crc32c,
1505
+ content_encoding: content_encoding,
1506
+ metadata: metadata,
1507
+ content_language: content_language,
1508
+ key: encryption_key,
1509
+ kms_key: kms_key,
1510
+ storage_class: storage_class_for(storage_class),
1511
+ temporary_hold: temporary_hold,
1512
+ event_based_hold: event_based_hold,
1513
+ if_generation_match: if_generation_match,
1514
+ if_generation_not_match: if_generation_not_match,
1515
+ if_metageneration_match: if_metageneration_match,
1516
+ if_metageneration_not_match: if_metageneration_not_match,
1517
+ user_project: user_project
1294
1518
  File.from_gapi gapi, service, user_project: user_project
1295
1519
  end
1296
1520
  alias upload_file create_file
@@ -1334,6 +1558,16 @@ module Google
1334
1558
  # used. All source files must have been encrypted with the same key,
1335
1559
  # and the resulting destination file will also be encrypted with the
1336
1560
  # key.
1561
+ # @param [Array<Integer>] if_source_generation_match Makes the operation
1562
+ # conditional on whether the source files' current generations match the
1563
+ # given values. The list must match `sources` item-to-item.
1564
+ # @param [Integer] if_generation_match Makes the operation conditional
1565
+ # on whether the destination file's current generation matches the
1566
+ # given value. Setting to 0 makes the operation succeed only if there
1567
+ # are no live versions of the file.
1568
+ # @param [Integer] if_metageneration_match Makes the operation conditional
1569
+ # on whether the destination file's current metageneration matches the
1570
+ # given value.
1337
1571
  #
1338
1572
  # @yield [file] A block yielding a delegate file object for setting the
1339
1573
  # properties of the destination file.
@@ -1382,7 +1616,13 @@ module Google
1382
1616
  #
1383
1617
  # new_file = bucket.compose [file_1, file_2], "path/to/new-file.ext"
1384
1618
  #
1385
- def compose sources, destination, acl: nil, encryption_key: nil
1619
+ def compose sources,
1620
+ destination,
1621
+ acl: nil,
1622
+ encryption_key: nil,
1623
+ if_source_generation_match: nil,
1624
+ if_generation_match: nil,
1625
+ if_metageneration_match: nil
1386
1626
  ensure_service!
1387
1627
  sources = Array sources
1388
1628
  if sources.size < 2
@@ -1398,9 +1638,16 @@ module Google
1398
1638
  end
1399
1639
 
1400
1640
  acl_rule = File::Acl.predefined_rule_for acl
1401
- gapi = service.compose_file name, sources, destination, destination_gapi, acl: acl_rule,
1402
- key: encryption_key,
1403
- user_project: user_project
1641
+ gapi = service.compose_file name,
1642
+ sources,
1643
+ destination,
1644
+ destination_gapi,
1645
+ acl: acl_rule,
1646
+ key: encryption_key,
1647
+ if_source_generation_match: if_source_generation_match,
1648
+ if_generation_match: if_generation_match,
1649
+ if_metageneration_match: if_metageneration_match,
1650
+ user_project: user_project
1404
1651
  File.from_gapi gapi, service, user_project: user_project
1405
1652
  end
1406
1653
  alias compose_file compose
@@ -1545,11 +1792,11 @@ module Google
1545
1792
  # scopes = ["https://www.googleapis.com/auth/iam"]
1546
1793
  # iam_client.authorization = Google::Auth.get_application_default scopes
1547
1794
  #
1548
- # request = {
1549
- # "payload": string_to_sign,
1550
- # }
1795
+ # request = Google::Apis::IamcredentialsV1::SignBlobRequest.new(
1796
+ # payload: string_to_sign
1797
+ # )
1551
1798
  # resource = "projects/-/serviceAccounts/#{issuer}"
1552
- # response = iam_client.sign_service_account_blob resource, request, {}
1799
+ # response = iam_client.sign_service_account_blob resource, request
1553
1800
  # response.signed_blob
1554
1801
  # end
1555
1802
  #
@@ -1647,8 +1894,8 @@ module Google
1647
1894
  end
1648
1895
 
1649
1896
  ##
1650
- # Generate a PostObject that includes the fields and url to
1651
- # upload objects via html forms.
1897
+ # Generate a PostObject that includes the fields and URL to
1898
+ # upload objects via HTML forms.
1652
1899
  #
1653
1900
  # Generating a PostObject requires service account credentials,
1654
1901
  # either by connecting with a service account when calling
@@ -1694,7 +1941,7 @@ module Google
1694
1941
  # Proc should return a signature created using a RPC call to the
1695
1942
  # [Service Account Credentials signBlob](https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signBlob)
1696
1943
  # method as shown in the example below.
1697
- # @return [PostObject] An object containing the URL, fields, and values needed to upload files via html forms.
1944
+ # @return [PostObject] An object containing the URL, fields, and values needed to upload files via HTML forms.
1698
1945
  #
1699
1946
  # @raise [SignedUrlUnavailable] If the service account credentials
1700
1947
  # are missing. Service account credentials are acquired by following the
@@ -1778,11 +2025,11 @@ module Google
1778
2025
  # scopes = ["https://www.googleapis.com/auth/iam"]
1779
2026
  # iam_client.authorization = Google::Auth.get_application_default scopes
1780
2027
  #
1781
- # request = {
1782
- # "payload": string_to_sign,
1783
- # }
2028
+ # request = Google::Apis::IamcredentialsV1::SignBlobRequest.new(
2029
+ # payload: string_to_sign
2030
+ # )
1784
2031
  # resource = "projects/-/serviceAccounts/#{issuer}"
1785
- # response = iam_client.sign_service_account_blob resource, request, {}
2032
+ # response = iam_client.sign_service_account_blob resource, request
1786
2033
  # response.signed_blob
1787
2034
  # end
1788
2035
  #
@@ -1817,10 +2064,14 @@ module Google
1817
2064
  end
1818
2065
 
1819
2066
  ##
1820
- # Generate a PostObject that includes the fields and url to
1821
- # upload objects via html forms.
2067
+ # Generate a `PostObject` that includes the fields and URL to
2068
+ # upload objects via HTML forms. The resulting `PostObject` is
2069
+ # based on a policy document created from the method arguments.
2070
+ # This policy provides authorization to ensure that the HTML
2071
+ # form can upload files into the bucket. See [Signatures -
2072
+ # Policy document](https://cloud.google.com/storage/docs/authentication/signatures#policy-document).
1822
2073
  #
1823
- # Generating a PostObject requires service account credentials,
2074
+ # Generating a `PostObject` requires service account credentials,
1824
2075
  # either by connecting with a service account when calling
1825
2076
  # {Google::Cloud.storage}, or by passing in the service account
1826
2077
  # `issuer` and `signing_key` values. Although the private key can
@@ -1833,6 +2084,8 @@ module Google
1833
2084
  # steps in [Service Account Authentication](
1834
2085
  # https://cloud.google.com/iam/docs/service-accounts).
1835
2086
  #
2087
+ # @see https://cloud.google.com/storage/docs/authentication/signatures#policy-document Signatures -
2088
+ # Policy document
1836
2089
  # @see https://cloud.google.com/storage/docs/xml-api/post-object
1837
2090
  #
1838
2091
  # @param [String] path Path to the file in Google Cloud Storage.
@@ -1856,9 +2109,14 @@ module Google
1856
2109
  # method as shown in the example below.
1857
2110
  # @param [Integer] expires The number of seconds until the URL expires.
1858
2111
  # The default is 604800 (7 days).
1859
- # @param [Hash] fields User-supplied form fields such as `acl`,
2112
+ # @param [Hash{String => String}] fields User-supplied form fields such as `acl`,
1860
2113
  # `cache-control`, `success_action_status`, and `success_action_redirect`.
1861
- # @param [Array<Hash|Array>] conditions User-supplied policy conditions.
2114
+ # Optional. See [Upload an object with HTML forms - Form
2115
+ # fields](https://cloud.google.com/storage/docs/xml-api/post-object-forms#form_fields).
2116
+ # @param [Array<Hash{String => String}|Array<String>>] conditions An array of
2117
+ # policy conditions that every upload must satisfy. For example:
2118
+ # `[["eq", "$Content-Type", "image/jpeg"]]`. Optional. See [Signatures - Policy
2119
+ # document](https://cloud.google.com/storage/docs/authentication/signatures#policy-document).
1862
2120
  # @param [String] scheme The URL scheme. The default value is `HTTPS`.
1863
2121
  # @param [Boolean] virtual_hosted_style Whether to use a virtual hosted-style
1864
2122
  # hostname, which adds the bucket into the host portion of the URI rather
@@ -1871,12 +2129,12 @@ module Google
1871
2129
  # Cloud Load Balancer which routes to a bucket you own, e.g.
1872
2130
  # `my-load-balancer-domain.tld`.
1873
2131
  #
1874
- # @return [PostObject] An object containing the URL, fields, and values needed to upload files via html forms.
2132
+ # @return [PostObject] An object containing the URL, fields, and values needed to
2133
+ # upload files via HTML forms.
1875
2134
  #
1876
- # @raise [SignedUrlUnavailable] If the service account credentials
1877
- # are missing. Service account credentials are acquired by following the
1878
- # steps in [Service Account Authentication](
1879
- # https://cloud.google.com/iam/docs/service-accounts).
2135
+ # @raise [SignedUrlUnavailable] If the service account credentials are missing.
2136
+ # Service account credentials are acquired by following the steps in [Service
2137
+ # Account Authentication](https://cloud.google.com/iam/docs/service-accounts).
1880
2138
  #
1881
2139
  # @example
1882
2140
  # require "google/cloud/storage"
@@ -1886,8 +2144,9 @@ module Google
1886
2144
  # bucket = storage.bucket "my-todo-app"
1887
2145
  #
1888
2146
  # conditions = [["starts-with", "$acl","public"]]
1889
- # post = bucket.generate_signed_post_policy_v4 "avatars/heidi/400x400.png", expires: 10,
1890
- # conditions: conditions
2147
+ # post = bucket.generate_signed_post_policy_v4 "avatars/heidi/400x400.png",
2148
+ # expires: 10,
2149
+ # conditions: conditions
1891
2150
  #
1892
2151
  # post.url #=> "https://storage.googleapis.com/my-todo-app/"
1893
2152
  # post.fields["key"] #=> "my-todo-app/avatars/heidi/400x400.png"
@@ -1916,11 +2175,11 @@ module Google
1916
2175
  # scopes = ["https://www.googleapis.com/auth/iam"]
1917
2176
  # iam_client.authorization = Google::Auth.get_application_default scopes
1918
2177
  #
1919
- # request = {
1920
- # "payload": string_to_sign,
1921
- # }
2178
+ # request = Google::Apis::IamcredentialsV1::SignBlobRequest.new(
2179
+ # payload: string_to_sign
2180
+ # )
1922
2181
  # resource = "projects/-/serviceAccounts/#{issuer}"
1923
- # response = iam_client.sign_service_account_blob resource, request, {}
2182
+ # response = iam_client.sign_service_account_blob resource, request
1924
2183
  # response.signed_blob
1925
2184
  # end
1926
2185
  #
@@ -1928,10 +2187,11 @@ module Google
1928
2187
  #
1929
2188
  # bucket = storage.bucket "my-todo-app"
1930
2189
  # conditions = [["starts-with", "$acl","public"]]
1931
- # post = bucket.generate_signed_post_policy_v4(
1932
- # "avatars/heidi/400x400.png", expires: 10,
1933
- # conditions: conditions, issuer: issuer, signer: signer
1934
- # )
2190
+ # post = bucket.generate_signed_post_policy_v4 "avatars/heidi/400x400.png",
2191
+ # expires: 10,
2192
+ # conditions: conditions,
2193
+ # issuer: issuer,
2194
+ # signer: signer
1935
2195
  #
1936
2196
  # post.url #=> "https://storage.googleapis.com/my-todo-app/"
1937
2197
  # post.fields["key"] #=> "my-todo-app/avatars/heidi/400x400.png"
@@ -2533,7 +2793,10 @@ module Google
2533
2793
  reload!
2534
2794
  end
2535
2795
 
2536
- def patch_gapi! *attributes
2796
+ def patch_gapi! attributes,
2797
+ if_metageneration_match: nil,
2798
+ if_metageneration_not_match: nil
2799
+ attributes = Array(attributes)
2537
2800
  attributes.flatten!
2538
2801
  return if attributes.empty?
2539
2802
  ensure_service!
@@ -2541,7 +2804,10 @@ module Google
2541
2804
  [attr, @gapi.send(attr)]
2542
2805
  end]
2543
2806
  patch_gapi = API::Bucket.new(**patch_args)
2544
- @gapi = service.patch_bucket name, patch_gapi,
2807
+ @gapi = service.patch_bucket name,
2808
+ patch_gapi,
2809
+ if_metageneration_match: if_metageneration_match,
2810
+ if_metageneration_not_match: if_metageneration_not_match,
2545
2811
  user_project: user_project
2546
2812
  @lazy = nil
2547
2813
  self
@@ -2559,9 +2825,11 @@ module Google
2559
2825
  # Yielded to a block to accumulate changes for a patch request.
2560
2826
  class Updater < Bucket
2561
2827
  attr_reader :updates
2828
+
2562
2829
  ##
2563
2830
  # Create an Updater object.
2564
2831
  def initialize gapi
2832
+ super()
2565
2833
  @updates = []
2566
2834
  @gapi = gapi
2567
2835
  @labels = @gapi.labels.to_h.dup