google-cloud-storage 1.29.1 → 1.32.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: 9d4a2aa4fb9f98b7c0e842d436fe23e66d44af1f47afaba5cb3feea37dc7a04e
4
- data.tar.gz: 53e4761ea01664572d9e5f39d90d41ef2726cf9879ef8cda51b77c395e5fa4a2
3
+ metadata.gz: 10f1fa9dd485d8891fa159b09b463fcf20d5320fd759f2dc92164c0a6f4647af
4
+ data.tar.gz: 1734495bde125925f45fdaf9a2c2a9da421d9cb38c5b7ac1e5785a869594c09f
5
5
  SHA512:
6
- metadata.gz: 378453a678dd7d46d92454773c8c564a206dfbfdaa7ac35b828f889e7c0b378d7beaf951d631dd0a8714bb105db9221d53a8536d2ed8a89a323799f932bf1cb7
7
- data.tar.gz: 9707109d71ed6e4f0fb07d0260cfb5ece5f5f1018731b0b2a9ff3a369dd84804c4e154572589d34329fb962b3ee62fa120e8b4faad274ab6635c98ee5f760f4d
6
+ metadata.gz: 614c067fa9c914e07acf1473e36a78cb04fa6070ddd2d1d96fee3693a2b6cc650a9005af515cdcbb9e6db9c1816985656977934fb5f3fe75248730673dbda675
7
+ data.tar.gz: b3f43b0193147e89de327734384e3a3b3581abfe921e0efcfdfd094e0373a76fb719f079fde3c3e6351216d2b9150af3b1a7a46249d35f7e170168a41e28175f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,55 @@
1
1
  # Release History
2
2
 
3
+ ### 1.32.0 / 2021-06-22
4
+
5
+ #### Features
6
+
7
+ * Add sources_if_generation_match to Bucket#compose
8
+ * Add support for (meta)generation preconditions to File operations
9
+ * Add if_(meta)generation_match options to Bucket#compose
10
+ * Add if_(meta)generation_(not_)match options to Bucket#create_file
11
+ * Add if_(meta)generation_(not_)match options to Bucket#file
12
+ * Add if_(meta)generation_(not_)match options to File#delete.
13
+ * Add if_(meta)generation_(not_)match options to File#rewrite
14
+ * Add generation and if_(meta)generation_(not_)match options to File#update
15
+ * Add generation and if_(meta)generation_(not_)match options to File::Acl predefined_acl methods
16
+
17
+ #### Bug Fixes
18
+
19
+ * Expand googleauth dependency to support future 1.x versions
20
+ * Update File::Verifier to test for File#to_path
21
+
22
+ ### 1.31.1 / 2021-05-19
23
+
24
+ #### Documentation
25
+
26
+ * Update IAMCredentialsService#sign_service_account_blob examples
27
+
28
+ ### 1.31.0 / 2021-03-10
29
+
30
+ #### Features
31
+
32
+ * Drop support for Ruby 2.4 and add support for Ruby 3.0
33
+
34
+ ### 1.30.0 / 2021-01-13
35
+
36
+ #### Features
37
+
38
+ * Replace google-api-client with specific client gems
39
+ * Remove google-api-client
40
+ * Add google-apis-iamcredentials_v1
41
+ * Add google-apis-storage_v1
42
+
43
+ #### Documentation
44
+
45
+ * Update Bucket#generate_signed_post_policy_v4 documentation
46
+
47
+ ### 1.29.2 / 2020-12-14
48
+
49
+ #### Bug Fixes
50
+
51
+ * Fix support for #generate_signed_post_policy_v4 conditions
52
+
3
53
  ### 1.29.1 / 2020-10-05
4
54
 
5
55
  #### 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).
@@ -45,7 +45,7 @@ there is a small amount of setup:
45
45
 
46
46
  ```sh
47
47
  $ cd google-cloud-storage/
48
- $ bundle exec rake bundleupdate
48
+ $ bundle install
49
49
  ```
50
50
 
51
51
  ## Console
@@ -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
 
@@ -905,6 +941,12 @@ module Google
905
941
  # completely mutable and will be included in the request. (See
906
942
  # {Bucket::Cors})
907
943
  #
944
+ # @param [Integer] if_metageneration_match Makes the operation conditional
945
+ # on whether the bucket's current metageneration matches the given value.
946
+ # @param [Integer] if_metageneration_not_match Makes the operation
947
+ # conditional on whether the bucket's current metageneration does not
948
+ # match the given value.
949
+ #
908
950
  # @yield [bucket] a block yielding a delegate object for updating the
909
951
  # file
910
952
  #
@@ -936,14 +978,27 @@ module Google
936
978
  # end
937
979
  # end
938
980
  #
939
- def update
981
+ # @example With a `if_metageneration_match` precondition:
982
+ # require "google/cloud/storage"
983
+ #
984
+ # storage = Google::Cloud::Storage.new
985
+ #
986
+ # bucket = storage.bucket "my-todo-app"
987
+ # bucket.update if_metageneration_match: 6 do |b|
988
+ # b.website_main = "index.html"
989
+ # end
990
+ #
991
+ def update if_metageneration_match: nil, if_metageneration_not_match: nil
940
992
  updater = Updater.new @gapi
941
993
  yield updater
942
994
  # Add check for mutable cors
943
995
  updater.check_for_changed_labels!
944
996
  updater.check_for_mutable_cors!
945
997
  updater.check_for_mutable_lifecycle!
946
- patch_gapi! updater.updates unless updater.updates.empty?
998
+ return if updater.updates.empty?
999
+ patch_gapi! updater.updates,
1000
+ if_metageneration_match: if_metageneration_match,
1001
+ if_metageneration_not_match: if_metageneration_not_match
947
1002
  end
948
1003
 
949
1004
  ##
@@ -953,6 +1008,12 @@ module Google
953
1008
  # The API call to delete the bucket may be retried under certain
954
1009
  # conditions. See {Google::Cloud#storage} to control this behavior.
955
1010
  #
1011
+ # @param [Integer] if_metageneration_match Makes the operation conditional
1012
+ # on whether the bucket's current metageneration matches the given value.
1013
+ # @param [Integer] if_metageneration_not_match Makes the operation
1014
+ # conditional on whether the bucket's current metageneration does not
1015
+ # match the given value.
1016
+ #
956
1017
  # @return [Boolean] Returns `true` if the bucket was deleted.
957
1018
  #
958
1019
  # @example
@@ -963,10 +1024,12 @@ module Google
963
1024
  # bucket = storage.bucket "my-bucket"
964
1025
  # bucket.delete
965
1026
  #
966
- def delete
1027
+ def delete if_metageneration_match: nil, if_metageneration_not_match: nil
967
1028
  ensure_service!
968
- service.delete_bucket name, user_project: user_project
969
- true
1029
+ service.delete_bucket name,
1030
+ if_metageneration_match: if_metageneration_match,
1031
+ if_metageneration_not_match: if_metageneration_not_match,
1032
+ user_project: user_project
970
1033
  end
971
1034
 
972
1035
  ##
@@ -1040,6 +1103,19 @@ module Google
1040
1103
  # @param [String] path Name (path) of the file.
1041
1104
  # @param [Integer] generation When present, selects a specific revision
1042
1105
  # of this object. Default is the latest version.
1106
+ # @param [Integer] if_generation_match Makes the operation conditional
1107
+ # on whether the file's current generation matches the given value.
1108
+ # Setting to 0 makes the operation succeed only if there are no live
1109
+ # versions of the file.
1110
+ # @param [Integer] if_generation_not_match Makes the operation conditional
1111
+ # on whether the file's current generation does not match the given
1112
+ # value. If no live file exists, the precondition fails. Setting to 0
1113
+ # makes the operation succeed only if there is a live version of the file.
1114
+ # @param [Integer] if_metageneration_match Makes the operation conditional
1115
+ # on whether the file's current metageneration matches the given value.
1116
+ # @param [Integer] if_metageneration_not_match Makes the operation
1117
+ # conditional on whether the file's current metageneration does not
1118
+ # match the given value.
1043
1119
  # @param [Boolean] skip_lookup Optionally create a Bucket object
1044
1120
  # without verifying the bucket resource exists on the Storage service.
1045
1121
  # Calls made on this object will raise errors if the bucket resource
@@ -1061,7 +1137,14 @@ module Google
1061
1137
  # file = bucket.file "path/to/my-file.ext"
1062
1138
  # puts file.name
1063
1139
  #
1064
- def file path, generation: nil, skip_lookup: nil, encryption_key: nil
1140
+ def file path,
1141
+ generation: nil,
1142
+ if_generation_match: nil,
1143
+ if_generation_not_match: nil,
1144
+ if_metageneration_match: nil,
1145
+ if_metageneration_not_match: nil,
1146
+ skip_lookup: nil,
1147
+ encryption_key: nil
1065
1148
  ensure_service!
1066
1149
  if skip_lookup
1067
1150
  return File.new_lazy name, path, service,
@@ -1069,6 +1152,10 @@ module Google
1069
1152
  user_project: user_project
1070
1153
  end
1071
1154
  gapi = service.get_file name, path, generation: generation,
1155
+ if_generation_match: if_generation_match,
1156
+ if_generation_not_match: if_generation_not_match,
1157
+ if_metageneration_match: if_metageneration_match,
1158
+ if_metageneration_not_match: if_metageneration_not_match,
1072
1159
  key: encryption_key,
1073
1160
  user_project: user_project
1074
1161
  File.from_gapi gapi, service, user_project: user_project
@@ -1179,6 +1266,19 @@ module Google
1179
1266
  # the same location as the bucket.The Service Account associated with
1180
1267
  # your project requires access to this encryption key. Do not provide
1181
1268
  # if `encryption_key` is used.
1269
+ # @param [Integer] if_generation_match Makes the operation conditional
1270
+ # on whether the file's current generation matches the given value.
1271
+ # Setting to 0 makes the operation succeed only if there are no live
1272
+ # versions of the file.
1273
+ # @param [Integer] if_generation_not_match Makes the operation conditional
1274
+ # on whether the file's current generation does not match the given
1275
+ # value. If no live file exists, the precondition fails. Setting to 0
1276
+ # makes the operation succeed only if there is a live version of the file.
1277
+ # @param [Integer] if_metageneration_match Makes the operation conditional
1278
+ # on whether the file's current metageneration matches the given value.
1279
+ # @param [Integer] if_metageneration_not_match Makes the operation
1280
+ # conditional on whether the file's current metageneration does not
1281
+ # match the given value.
1182
1282
  #
1183
1283
  # @return [Google::Cloud::Storage::File]
1184
1284
  #
@@ -1262,12 +1362,27 @@ module Google
1262
1362
  # file.download "path/to/downloaded/gzipped.txt",
1263
1363
  # skip_decompress: true
1264
1364
  #
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
1365
+ def create_file file,
1366
+ path = nil,
1367
+ acl: nil,
1368
+ cache_control: nil,
1369
+ content_disposition: nil,
1370
+ content_encoding: nil,
1371
+ content_language: nil,
1372
+ content_type: nil,
1373
+ custom_time: nil,
1374
+ crc32c: nil,
1375
+ md5: nil,
1376
+ metadata: nil,
1377
+ storage_class: nil,
1378
+ encryption_key: nil,
1379
+ kms_key: nil,
1380
+ temporary_hold: nil,
1381
+ event_based_hold: nil,
1382
+ if_generation_match: nil,
1383
+ if_generation_not_match: nil,
1384
+ if_metageneration_match: nil,
1385
+ if_metageneration_not_match: nil
1271
1386
  ensure_service!
1272
1387
  ensure_io_or_file_exists! file
1273
1388
  path ||= file.path if file.respond_to? :path
@@ -1275,22 +1390,29 @@ module Google
1275
1390
  raise ArgumentError, "must provide path" if path.nil?
1276
1391
 
1277
1392
 
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
1393
+ gapi = service.insert_file name,
1394
+ file,
1395
+ path,
1396
+ acl: File::Acl.predefined_rule_for(acl),
1397
+ md5: md5,
1398
+ cache_control: cache_control,
1399
+ content_type: content_type,
1400
+ custom_time: custom_time,
1401
+ content_disposition: content_disposition,
1402
+ crc32c: crc32c,
1403
+ content_encoding: content_encoding,
1404
+ metadata: metadata,
1405
+ content_language: content_language,
1406
+ key: encryption_key,
1407
+ kms_key: kms_key,
1408
+ storage_class: storage_class_for(storage_class),
1409
+ temporary_hold: temporary_hold,
1410
+ event_based_hold: event_based_hold,
1411
+ if_generation_match: if_generation_match,
1412
+ if_generation_not_match: if_generation_not_match,
1413
+ if_metageneration_match: if_metageneration_match,
1414
+ if_metageneration_not_match: if_metageneration_not_match,
1415
+ user_project: user_project
1294
1416
  File.from_gapi gapi, service, user_project: user_project
1295
1417
  end
1296
1418
  alias upload_file create_file
@@ -1334,6 +1456,16 @@ module Google
1334
1456
  # used. All source files must have been encrypted with the same key,
1335
1457
  # and the resulting destination file will also be encrypted with the
1336
1458
  # key.
1459
+ # @param [Array<Integer>] if_source_generation_match Makes the operation
1460
+ # conditional on whether the source files' current generations match the
1461
+ # given values. The list must match `sources` item-to-item.
1462
+ # @param [Integer] if_generation_match Makes the operation conditional
1463
+ # on whether the destination file's current generation matches the
1464
+ # given value. Setting to 0 makes the operation succeed only if there
1465
+ # are no live versions of the file.
1466
+ # @param [Integer] if_metageneration_match Makes the operation conditional
1467
+ # on whether the destination file's current metageneration matches the
1468
+ # given value.
1337
1469
  #
1338
1470
  # @yield [file] A block yielding a delegate file object for setting the
1339
1471
  # properties of the destination file.
@@ -1382,7 +1514,13 @@ module Google
1382
1514
  #
1383
1515
  # new_file = bucket.compose [file_1, file_2], "path/to/new-file.ext"
1384
1516
  #
1385
- def compose sources, destination, acl: nil, encryption_key: nil
1517
+ def compose sources,
1518
+ destination,
1519
+ acl: nil,
1520
+ encryption_key: nil,
1521
+ if_source_generation_match: nil,
1522
+ if_generation_match: nil,
1523
+ if_metageneration_match: nil
1386
1524
  ensure_service!
1387
1525
  sources = Array sources
1388
1526
  if sources.size < 2
@@ -1398,9 +1536,16 @@ module Google
1398
1536
  end
1399
1537
 
1400
1538
  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
1539
+ gapi = service.compose_file name,
1540
+ sources,
1541
+ destination,
1542
+ destination_gapi,
1543
+ acl: acl_rule,
1544
+ key: encryption_key,
1545
+ if_source_generation_match: if_source_generation_match,
1546
+ if_generation_match: if_generation_match,
1547
+ if_metageneration_match: if_metageneration_match,
1548
+ user_project: user_project
1404
1549
  File.from_gapi gapi, service, user_project: user_project
1405
1550
  end
1406
1551
  alias compose_file compose
@@ -1545,11 +1690,11 @@ module Google
1545
1690
  # scopes = ["https://www.googleapis.com/auth/iam"]
1546
1691
  # iam_client.authorization = Google::Auth.get_application_default scopes
1547
1692
  #
1548
- # request = {
1549
- # "payload": string_to_sign,
1550
- # }
1693
+ # request = Google::Apis::IamcredentialsV1::SignBlobRequest.new(
1694
+ # payload: string_to_sign
1695
+ # )
1551
1696
  # resource = "projects/-/serviceAccounts/#{issuer}"
1552
- # response = iam_client.sign_service_account_blob resource, request, {}
1697
+ # response = iam_client.sign_service_account_blob resource, request
1553
1698
  # response.signed_blob
1554
1699
  # end
1555
1700
  #
@@ -1647,8 +1792,8 @@ module Google
1647
1792
  end
1648
1793
 
1649
1794
  ##
1650
- # Generate a PostObject that includes the fields and url to
1651
- # upload objects via html forms.
1795
+ # Generate a PostObject that includes the fields and URL to
1796
+ # upload objects via HTML forms.
1652
1797
  #
1653
1798
  # Generating a PostObject requires service account credentials,
1654
1799
  # either by connecting with a service account when calling
@@ -1694,7 +1839,7 @@ module Google
1694
1839
  # Proc should return a signature created using a RPC call to the
1695
1840
  # [Service Account Credentials signBlob](https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signBlob)
1696
1841
  # 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.
1842
+ # @return [PostObject] An object containing the URL, fields, and values needed to upload files via HTML forms.
1698
1843
  #
1699
1844
  # @raise [SignedUrlUnavailable] If the service account credentials
1700
1845
  # are missing. Service account credentials are acquired by following the
@@ -1778,11 +1923,11 @@ module Google
1778
1923
  # scopes = ["https://www.googleapis.com/auth/iam"]
1779
1924
  # iam_client.authorization = Google::Auth.get_application_default scopes
1780
1925
  #
1781
- # request = {
1782
- # "payload": string_to_sign,
1783
- # }
1926
+ # request = Google::Apis::IamcredentialsV1::SignBlobRequest.new(
1927
+ # payload: string_to_sign
1928
+ # )
1784
1929
  # resource = "projects/-/serviceAccounts/#{issuer}"
1785
- # response = iam_client.sign_service_account_blob resource, request, {}
1930
+ # response = iam_client.sign_service_account_blob resource, request
1786
1931
  # response.signed_blob
1787
1932
  # end
1788
1933
  #
@@ -1817,10 +1962,14 @@ module Google
1817
1962
  end
1818
1963
 
1819
1964
  ##
1820
- # Generate a PostObject that includes the fields and url to
1821
- # upload objects via html forms.
1965
+ # Generate a `PostObject` that includes the fields and URL to
1966
+ # upload objects via HTML forms. The resulting `PostObject` is
1967
+ # based on a policy document created from the method arguments.
1968
+ # This policy provides authorization to ensure that the HTML
1969
+ # form can upload files into the bucket. See [Signatures -
1970
+ # Policy document](https://cloud.google.com/storage/docs/authentication/signatures#policy-document).
1822
1971
  #
1823
- # Generating a PostObject requires service account credentials,
1972
+ # Generating a `PostObject` requires service account credentials,
1824
1973
  # either by connecting with a service account when calling
1825
1974
  # {Google::Cloud.storage}, or by passing in the service account
1826
1975
  # `issuer` and `signing_key` values. Although the private key can
@@ -1833,6 +1982,8 @@ module Google
1833
1982
  # steps in [Service Account Authentication](
1834
1983
  # https://cloud.google.com/iam/docs/service-accounts).
1835
1984
  #
1985
+ # @see https://cloud.google.com/storage/docs/authentication/signatures#policy-document Signatures -
1986
+ # Policy document
1836
1987
  # @see https://cloud.google.com/storage/docs/xml-api/post-object
1837
1988
  #
1838
1989
  # @param [String] path Path to the file in Google Cloud Storage.
@@ -1856,9 +2007,14 @@ module Google
1856
2007
  # method as shown in the example below.
1857
2008
  # @param [Integer] expires The number of seconds until the URL expires.
1858
2009
  # The default is 604800 (7 days).
1859
- # @param [Hash] fields User-supplied form fields such as `acl`,
2010
+ # @param [Hash{String => String}] fields User-supplied form fields such as `acl`,
1860
2011
  # `cache-control`, `success_action_status`, and `success_action_redirect`.
1861
- # @param [Array<Hash|Array>] conditions User-supplied policy conditions.
2012
+ # Optional. See [Upload an object with HTML forms - Form
2013
+ # fields](https://cloud.google.com/storage/docs/xml-api/post-object-forms#form_fields).
2014
+ # @param [Array<Hash{String => String}|Array<String>>] conditions An array of
2015
+ # policy conditions that every upload must satisfy. For example:
2016
+ # `[["eq", "$Content-Type", "image/jpeg"]]`. Optional. See [Signatures - Policy
2017
+ # document](https://cloud.google.com/storage/docs/authentication/signatures#policy-document).
1862
2018
  # @param [String] scheme The URL scheme. The default value is `HTTPS`.
1863
2019
  # @param [Boolean] virtual_hosted_style Whether to use a virtual hosted-style
1864
2020
  # hostname, which adds the bucket into the host portion of the URI rather
@@ -1871,12 +2027,12 @@ module Google
1871
2027
  # Cloud Load Balancer which routes to a bucket you own, e.g.
1872
2028
  # `my-load-balancer-domain.tld`.
1873
2029
  #
1874
- # @return [PostObject] An object containing the URL, fields, and values needed to upload files via html forms.
2030
+ # @return [PostObject] An object containing the URL, fields, and values needed to
2031
+ # upload files via HTML forms.
1875
2032
  #
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).
2033
+ # @raise [SignedUrlUnavailable] If the service account credentials are missing.
2034
+ # Service account credentials are acquired by following the steps in [Service
2035
+ # Account Authentication](https://cloud.google.com/iam/docs/service-accounts).
1880
2036
  #
1881
2037
  # @example
1882
2038
  # require "google/cloud/storage"
@@ -1886,8 +2042,9 @@ module Google
1886
2042
  # bucket = storage.bucket "my-todo-app"
1887
2043
  #
1888
2044
  # conditions = [["starts-with", "$acl","public"]]
1889
- # post = bucket.generate_signed_post_policy_v4 "avatars/heidi/400x400.png", expires: 10,
1890
- # conditions: conditions
2045
+ # post = bucket.generate_signed_post_policy_v4 "avatars/heidi/400x400.png",
2046
+ # expires: 10,
2047
+ # conditions: conditions
1891
2048
  #
1892
2049
  # post.url #=> "https://storage.googleapis.com/my-todo-app/"
1893
2050
  # post.fields["key"] #=> "my-todo-app/avatars/heidi/400x400.png"
@@ -1916,11 +2073,11 @@ module Google
1916
2073
  # scopes = ["https://www.googleapis.com/auth/iam"]
1917
2074
  # iam_client.authorization = Google::Auth.get_application_default scopes
1918
2075
  #
1919
- # request = {
1920
- # "payload": string_to_sign,
1921
- # }
2076
+ # request = Google::Apis::IamcredentialsV1::SignBlobRequest.new(
2077
+ # payload: string_to_sign
2078
+ # )
1922
2079
  # resource = "projects/-/serviceAccounts/#{issuer}"
1923
- # response = iam_client.sign_service_account_blob resource, request, {}
2080
+ # response = iam_client.sign_service_account_blob resource, request
1924
2081
  # response.signed_blob
1925
2082
  # end
1926
2083
  #
@@ -1928,10 +2085,11 @@ module Google
1928
2085
  #
1929
2086
  # bucket = storage.bucket "my-todo-app"
1930
2087
  # 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
- # )
2088
+ # post = bucket.generate_signed_post_policy_v4 "avatars/heidi/400x400.png",
2089
+ # expires: 10,
2090
+ # conditions: conditions,
2091
+ # issuer: issuer,
2092
+ # signer: signer
1935
2093
  #
1936
2094
  # post.url #=> "https://storage.googleapis.com/my-todo-app/"
1937
2095
  # post.fields["key"] #=> "my-todo-app/avatars/heidi/400x400.png"
@@ -2533,7 +2691,10 @@ module Google
2533
2691
  reload!
2534
2692
  end
2535
2693
 
2536
- def patch_gapi! *attributes
2694
+ def patch_gapi! attributes,
2695
+ if_metageneration_match: nil,
2696
+ if_metageneration_not_match: nil
2697
+ attributes = Array(attributes)
2537
2698
  attributes.flatten!
2538
2699
  return if attributes.empty?
2539
2700
  ensure_service!
@@ -2541,7 +2702,10 @@ module Google
2541
2702
  [attr, @gapi.send(attr)]
2542
2703
  end]
2543
2704
  patch_gapi = API::Bucket.new(**patch_args)
2544
- @gapi = service.patch_bucket name, patch_gapi,
2705
+ @gapi = service.patch_bucket name,
2706
+ patch_gapi,
2707
+ if_metageneration_match: if_metageneration_match,
2708
+ if_metageneration_not_match: if_metageneration_not_match,
2545
2709
  user_project: user_project
2546
2710
  @lazy = nil
2547
2711
  self
@@ -2559,9 +2723,11 @@ module Google
2559
2723
  # Yielded to a block to accumulate changes for a patch request.
2560
2724
  class Updater < Bucket
2561
2725
  attr_reader :updates
2726
+
2562
2727
  ##
2563
2728
  # Create an Updater object.
2564
2729
  def initialize gapi
2730
+ super()
2565
2731
  @updates = []
2566
2732
  @gapi = gapi
2567
2733
  @labels = @gapi.labels.to_h.dup