google-cloud-storage 1.29.0 → 1.31.1

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: fe9e2b825a237558161e2fa35c196f56342b43ea1119c15b527fdd1b26445711
4
- data.tar.gz: 2c76342e276c10250c9ddcbf14edfc143474ccf4b29e1d869bc3a8a639d4f608
3
+ metadata.gz: 690d38d7f8cccf7a8ad6433b829c02b0e9f9fbaa48198f68ff4c7a661820d93a
4
+ data.tar.gz: 6a8b0782c6ab6cfdf194f0be0b51993e817b182a8a599d67e4c52cab11d98203
5
5
  SHA512:
6
- metadata.gz: a9ff8d6eb43731e588b0b32df5bb093dc042443543cc63d3e1f060bffd09d011180085254c849ef0393b27447550bb01690b129255e0c02a3e657e8e73e1bd4e
7
- data.tar.gz: 991a423b8db899c16adeeb93d095ec9f3176a32cae5d78ab459c9b2bc7f07a52398f7387a7a89336dd2d86e9aeb1beb067853a2b474042b2740333bc6ff3daf7
6
+ metadata.gz: d8b94e1a9426345a436902611e74eb627eff7867eec1546084aaef1dd16e8a8e9af0dea24493572c8142f7dc7b530ed1cb84abf94e6dbb8acc00ef8a04ab9d65
7
+ data.tar.gz: 65162ab2d788531d21efaa23d87e7bdbafcdc8f6c3fd62f556be07f35d440f3055f830ee45cb903443aa695db56cd08b18afa02f3aa6b247b3ba761c1adfe4be
data/CHANGELOG.md CHANGED
@@ -1,5 +1,48 @@
1
1
  # Release History
2
2
 
3
+ ### 1.31.1 / 2021-05-19
4
+
5
+ #### Documentation
6
+
7
+ * Update IAMCredentialsService#sign_service_account_blob examples
8
+
9
+ ### 1.31.0 / 2021-03-10
10
+
11
+ #### Features
12
+
13
+ * Drop support for Ruby 2.4 and add support for Ruby 3.0
14
+
15
+ ### 1.30.0 / 2021-01-13
16
+
17
+ #### Features
18
+
19
+ * Replace google-api-client with specific client gems
20
+ * Remove google-api-client
21
+ * Add google-apis-iamcredentials_v1
22
+ * Add google-apis-storage_v1
23
+
24
+ #### Documentation
25
+
26
+ * Update Bucket#generate_signed_post_policy_v4 documentation
27
+
28
+ ### 1.29.2 / 2020-12-14
29
+
30
+ #### Bug Fixes
31
+
32
+ * Fix support for #generate_signed_post_policy_v4 conditions
33
+
34
+ ### 1.29.1 / 2020-10-05
35
+
36
+ #### Bug Fixes
37
+
38
+ * Fix encoding of space characters in file names in signed_url v4
39
+
40
+ #### Documentation
41
+
42
+ * Update Bucket#default_kms_key= docs
43
+ * Demonstrate deleting the Cloud KMS encryption key
44
+ * Update customer-supplied encryption key docs and examples ([#7851](https://www.github.com/googleapis/google-cloud-ruby/issues/7851))
45
+
3
46
  ### 1.29.0 / 2020-09-22
4
47
 
5
48
  #### Features
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,7 +309,7 @@ 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
  ##
@@ -333,7 +333,7 @@ module Google
333
333
  # @return [String]
334
334
  #
335
335
  def logging_prefix
336
- @gapi.logging.log_object_prefix if @gapi.logging
336
+ @gapi.logging&.log_object_prefix
337
337
  end
338
338
 
339
339
  ##
@@ -392,7 +392,7 @@ module Google
392
392
  # @return [Boolean]
393
393
  #
394
394
  def versioning?
395
- @gapi.versioning.enabled? unless @gapi.versioning.nil?
395
+ @gapi.versioning&.enabled?
396
396
  end
397
397
 
398
398
  ##
@@ -422,7 +422,7 @@ module Google
422
422
  # @return [String] The main page suffix.
423
423
  #
424
424
  def website_main
425
- @gapi.website.main_page_suffix if @gapi.website
425
+ @gapi.website&.main_page_suffix
426
426
  end
427
427
 
428
428
  ##
@@ -449,7 +449,7 @@ module Google
449
449
  # @return [String]
450
450
  #
451
451
  def website_404
452
- @gapi.website.not_found_page if @gapi.website
452
+ @gapi.website&.not_found_page
453
453
  end
454
454
 
455
455
  ##
@@ -498,7 +498,7 @@ module Google
498
498
  # the bucket.
499
499
  #
500
500
  def requester_pays
501
- @gapi.billing.requester_pays if @gapi.billing
501
+ @gapi.billing&.requester_pays
502
502
  end
503
503
  alias requester_pays? requester_pays
504
504
 
@@ -550,14 +550,15 @@ module Google
550
550
  # bucket.default_kms_key #=> kms_key_name
551
551
  #
552
552
  def default_kms_key
553
- @gapi.encryption && @gapi.encryption.default_kms_key_name
553
+ @gapi.encryption&.default_kms_key_name
554
554
  end
555
555
 
556
556
  ##
557
557
  # Set the Cloud KMS encryption key that will be used to protect files.
558
558
  # For example: `projects/a/locations/b/keyRings/c/cryptoKeys/d`
559
559
  #
560
- # @param [String] new_default_kms_key New Cloud KMS key name.
560
+ # @param [String, nil] new_default_kms_key New Cloud KMS key name, or
561
+ # `nil` to delete the Cloud KMS encryption key.
561
562
  #
562
563
  # @example
563
564
  # require "google/cloud/storage"
@@ -571,6 +572,15 @@ module Google
571
572
  #
572
573
  # bucket.default_kms_key = kms_key_name
573
574
  #
575
+ # @example Delete the default Cloud KMS encryption key:
576
+ # require "google/cloud/storage"
577
+ #
578
+ # storage = Google::Cloud::Storage.new
579
+ #
580
+ # bucket = storage.bucket "my-bucket"
581
+ #
582
+ # bucket.default_kms_key = nil
583
+ #
574
584
  def default_kms_key= new_default_kms_key
575
585
  @gapi.encryption = API::Bucket::Encryption.new \
576
586
  default_kms_key_name: new_default_kms_key
@@ -589,7 +599,7 @@ module Google
589
599
  # retention policy exists for the bucket.
590
600
  #
591
601
  def retention_period
592
- @gapi.retention_policy && @gapi.retention_policy.retention_period
602
+ @gapi.retention_policy&.retention_period
593
603
  end
594
604
 
595
605
  ##
@@ -648,7 +658,7 @@ module Google
648
658
  # policy, if a policy exists.
649
659
  #
650
660
  def retention_effective_at
651
- @gapi.retention_policy && @gapi.retention_policy.effective_time
661
+ @gapi.retention_policy&.effective_time
652
662
  end
653
663
 
654
664
  ##
@@ -798,7 +808,7 @@ module Google
798
808
  # bucket.uniform_bucket_level_access? # true
799
809
  #
800
810
  def uniform_bucket_level_access?
801
- return false unless @gapi.iam_configuration && @gapi.iam_configuration.uniform_bucket_level_access
811
+ return false unless @gapi.iam_configuration&.uniform_bucket_level_access
802
812
  !@gapi.iam_configuration.uniform_bucket_level_access.enabled.nil? &&
803
813
  @gapi.iam_configuration.uniform_bucket_level_access.enabled
804
814
  end
@@ -860,7 +870,7 @@ module Google
860
870
  # puts bucket.uniform_bucket_level_access_locked_at
861
871
  #
862
872
  def uniform_bucket_level_access_locked_at
863
- return nil unless @gapi.iam_configuration && @gapi.iam_configuration.uniform_bucket_level_access
873
+ return nil unless @gapi.iam_configuration&.uniform_bucket_level_access
864
874
  @gapi.iam_configuration.uniform_bucket_level_access.locked_time
865
875
  end
866
876
 
@@ -1535,11 +1545,11 @@ module Google
1535
1545
  # scopes = ["https://www.googleapis.com/auth/iam"]
1536
1546
  # iam_client.authorization = Google::Auth.get_application_default scopes
1537
1547
  #
1538
- # request = {
1539
- # "payload": string_to_sign,
1540
- # }
1548
+ # request = Google::Apis::IamcredentialsV1::SignBlobRequest.new(
1549
+ # payload: string_to_sign
1550
+ # )
1541
1551
  # resource = "projects/-/serviceAccounts/#{issuer}"
1542
- # response = iam_client.sign_service_account_blob resource, request, {}
1552
+ # response = iam_client.sign_service_account_blob resource, request
1543
1553
  # response.signed_blob
1544
1554
  # end
1545
1555
  #
@@ -1637,8 +1647,8 @@ module Google
1637
1647
  end
1638
1648
 
1639
1649
  ##
1640
- # Generate a PostObject that includes the fields and url to
1641
- # upload objects via html forms.
1650
+ # Generate a PostObject that includes the fields and URL to
1651
+ # upload objects via HTML forms.
1642
1652
  #
1643
1653
  # Generating a PostObject requires service account credentials,
1644
1654
  # either by connecting with a service account when calling
@@ -1684,7 +1694,7 @@ module Google
1684
1694
  # Proc should return a signature created using a RPC call to the
1685
1695
  # [Service Account Credentials signBlob](https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signBlob)
1686
1696
  # method as shown in the example below.
1687
- # @return [PostObject] An object containing the URL, fields, and values needed to upload files via html forms.
1697
+ # @return [PostObject] An object containing the URL, fields, and values needed to upload files via HTML forms.
1688
1698
  #
1689
1699
  # @raise [SignedUrlUnavailable] If the service account credentials
1690
1700
  # are missing. Service account credentials are acquired by following the
@@ -1768,11 +1778,11 @@ module Google
1768
1778
  # scopes = ["https://www.googleapis.com/auth/iam"]
1769
1779
  # iam_client.authorization = Google::Auth.get_application_default scopes
1770
1780
  #
1771
- # request = {
1772
- # "payload": string_to_sign,
1773
- # }
1781
+ # request = Google::Apis::IamcredentialsV1::SignBlobRequest.new(
1782
+ # payload: string_to_sign
1783
+ # )
1774
1784
  # resource = "projects/-/serviceAccounts/#{issuer}"
1775
- # response = iam_client.sign_service_account_blob resource, request, {}
1785
+ # response = iam_client.sign_service_account_blob resource, request
1776
1786
  # response.signed_blob
1777
1787
  # end
1778
1788
  #
@@ -1807,10 +1817,14 @@ module Google
1807
1817
  end
1808
1818
 
1809
1819
  ##
1810
- # Generate a PostObject that includes the fields and url to
1811
- # upload objects via html forms.
1820
+ # Generate a `PostObject` that includes the fields and URL to
1821
+ # upload objects via HTML forms. The resulting `PostObject` is
1822
+ # based on a policy document created from the method arguments.
1823
+ # This policy provides authorization to ensure that the HTML
1824
+ # form can upload files into the bucket. See [Signatures -
1825
+ # Policy document](https://cloud.google.com/storage/docs/authentication/signatures#policy-document).
1812
1826
  #
1813
- # Generating a PostObject requires service account credentials,
1827
+ # Generating a `PostObject` requires service account credentials,
1814
1828
  # either by connecting with a service account when calling
1815
1829
  # {Google::Cloud.storage}, or by passing in the service account
1816
1830
  # `issuer` and `signing_key` values. Although the private key can
@@ -1823,6 +1837,8 @@ module Google
1823
1837
  # steps in [Service Account Authentication](
1824
1838
  # https://cloud.google.com/iam/docs/service-accounts).
1825
1839
  #
1840
+ # @see https://cloud.google.com/storage/docs/authentication/signatures#policy-document Signatures -
1841
+ # Policy document
1826
1842
  # @see https://cloud.google.com/storage/docs/xml-api/post-object
1827
1843
  #
1828
1844
  # @param [String] path Path to the file in Google Cloud Storage.
@@ -1846,9 +1862,14 @@ module Google
1846
1862
  # method as shown in the example below.
1847
1863
  # @param [Integer] expires The number of seconds until the URL expires.
1848
1864
  # The default is 604800 (7 days).
1849
- # @param [Hash] fields User-supplied form fields such as `acl`,
1865
+ # @param [Hash{String => String}] fields User-supplied form fields such as `acl`,
1850
1866
  # `cache-control`, `success_action_status`, and `success_action_redirect`.
1851
- # @param [Array<Hash|Array>] conditions User-supplied policy conditions.
1867
+ # Optional. See [Upload an object with HTML forms - Form
1868
+ # fields](https://cloud.google.com/storage/docs/xml-api/post-object-forms#form_fields).
1869
+ # @param [Array<Hash{String => String}|Array<String>>] conditions An array of
1870
+ # policy conditions that every upload must satisfy. For example:
1871
+ # `[["eq", "$Content-Type", "image/jpeg"]]`. Optional. See [Signatures - Policy
1872
+ # document](https://cloud.google.com/storage/docs/authentication/signatures#policy-document).
1852
1873
  # @param [String] scheme The URL scheme. The default value is `HTTPS`.
1853
1874
  # @param [Boolean] virtual_hosted_style Whether to use a virtual hosted-style
1854
1875
  # hostname, which adds the bucket into the host portion of the URI rather
@@ -1861,12 +1882,12 @@ module Google
1861
1882
  # Cloud Load Balancer which routes to a bucket you own, e.g.
1862
1883
  # `my-load-balancer-domain.tld`.
1863
1884
  #
1864
- # @return [PostObject] An object containing the URL, fields, and values needed to upload files via html forms.
1885
+ # @return [PostObject] An object containing the URL, fields, and values needed to
1886
+ # upload files via HTML forms.
1865
1887
  #
1866
- # @raise [SignedUrlUnavailable] If the service account credentials
1867
- # are missing. Service account credentials are acquired by following the
1868
- # steps in [Service Account Authentication](
1869
- # https://cloud.google.com/iam/docs/service-accounts).
1888
+ # @raise [SignedUrlUnavailable] If the service account credentials are missing.
1889
+ # Service account credentials are acquired by following the steps in [Service
1890
+ # Account Authentication](https://cloud.google.com/iam/docs/service-accounts).
1870
1891
  #
1871
1892
  # @example
1872
1893
  # require "google/cloud/storage"
@@ -1876,8 +1897,9 @@ module Google
1876
1897
  # bucket = storage.bucket "my-todo-app"
1877
1898
  #
1878
1899
  # conditions = [["starts-with", "$acl","public"]]
1879
- # post = bucket.generate_signed_post_policy_v4 "avatars/heidi/400x400.png", expires: 10,
1880
- # conditions: conditions
1900
+ # post = bucket.generate_signed_post_policy_v4 "avatars/heidi/400x400.png",
1901
+ # expires: 10,
1902
+ # conditions: conditions
1881
1903
  #
1882
1904
  # post.url #=> "https://storage.googleapis.com/my-todo-app/"
1883
1905
  # post.fields["key"] #=> "my-todo-app/avatars/heidi/400x400.png"
@@ -1906,11 +1928,11 @@ module Google
1906
1928
  # scopes = ["https://www.googleapis.com/auth/iam"]
1907
1929
  # iam_client.authorization = Google::Auth.get_application_default scopes
1908
1930
  #
1909
- # request = {
1910
- # "payload": string_to_sign,
1911
- # }
1931
+ # request = Google::Apis::IamcredentialsV1::SignBlobRequest.new(
1932
+ # payload: string_to_sign
1933
+ # )
1912
1934
  # resource = "projects/-/serviceAccounts/#{issuer}"
1913
- # response = iam_client.sign_service_account_blob resource, request, {}
1935
+ # response = iam_client.sign_service_account_blob resource, request
1914
1936
  # response.signed_blob
1915
1937
  # end
1916
1938
  #
@@ -1918,10 +1940,11 @@ module Google
1918
1940
  #
1919
1941
  # bucket = storage.bucket "my-todo-app"
1920
1942
  # conditions = [["starts-with", "$acl","public"]]
1921
- # post = bucket.generate_signed_post_policy_v4(
1922
- # "avatars/heidi/400x400.png", expires: 10,
1923
- # conditions: conditions, issuer: issuer, signer: signer
1924
- # )
1943
+ # post = bucket.generate_signed_post_policy_v4 "avatars/heidi/400x400.png",
1944
+ # expires: 10,
1945
+ # conditions: conditions,
1946
+ # issuer: issuer,
1947
+ # signer: signer
1925
1948
  #
1926
1949
  # post.url #=> "https://storage.googleapis.com/my-todo-app/"
1927
1950
  # post.fields["key"] #=> "my-todo-app/avatars/heidi/400x400.png"
@@ -2549,9 +2572,11 @@ module Google
2549
2572
  # Yielded to a block to accumulate changes for a patch request.
2550
2573
  class Updater < Bucket
2551
2574
  attr_reader :updates
2575
+
2552
2576
  ##
2553
2577
  # Create an Updater object.
2554
2578
  def initialize gapi
2579
+ super()
2555
2580
  @updates = []
2556
2581
  @gapi = gapi
2557
2582
  @labels = @gapi.labels.to_h.dup
@@ -198,7 +198,7 @@ module Google
198
198
  gapi = @service.insert_bucket_acl @bucket, entity, "OWNER",
199
199
  user_project: user_project
200
200
  entity = gapi.entity
201
- @owners.push entity unless @owners.nil?
201
+ @owners&.push entity
202
202
  entity
203
203
  end
204
204
 
@@ -243,7 +243,7 @@ module Google
243
243
  gapi = @service.insert_bucket_acl @bucket, entity, "WRITER",
244
244
  user_project: user_project
245
245
  entity = gapi.entity
246
- @writers.push entity unless @writers.nil?
246
+ @writers&.push entity
247
247
  entity
248
248
  end
249
249
 
@@ -288,7 +288,7 @@ module Google
288
288
  gapi = @service.insert_bucket_acl @bucket, entity, "READER",
289
289
  user_project: user_project
290
290
  entity = gapi.entity
291
- @readers.push entity unless @readers.nil?
291
+ @readers&.push entity
292
292
  entity
293
293
  end
294
294
 
@@ -323,9 +323,9 @@ module Google
323
323
  def delete entity
324
324
  @service.delete_bucket_acl @bucket, entity,
325
325
  user_project: user_project
326
- @owners.delete entity unless @owners.nil?
327
- @writers.delete entity unless @writers.nil?
328
- @readers.delete entity unless @readers.nil?
326
+ @owners&.delete entity
327
+ @writers&.delete entity
328
+ @readers&.delete entity
329
329
  true
330
330
  end
331
331
 
@@ -445,8 +445,7 @@ module Google
445
445
 
446
446
  def entities_from_acls acls, role
447
447
  selected = acls.select { |acl| acl.role == role }
448
- entities = selected.map(&:entity)
449
- entities
448
+ selected.map(&:entity)
450
449
  end
451
450
  end
452
451
 
@@ -614,7 +613,7 @@ module Google
614
613
  gapi = @service.insert_default_acl @bucket, entity, "OWNER",
615
614
  user_project: user_project
616
615
  entity = gapi.entity
617
- @owners.push entity unless @owners.nil?
616
+ @owners&.push entity
618
617
  entity
619
618
  end
620
619
 
@@ -657,7 +656,7 @@ module Google
657
656
  gapi = @service.insert_default_acl @bucket, entity, "READER",
658
657
  user_project: user_project
659
658
  entity = gapi.entity
660
- @readers.push entity unless @readers.nil?
659
+ @readers&.push entity
661
660
  entity
662
661
  end
663
662
 
@@ -690,8 +689,8 @@ module Google
690
689
  def delete entity
691
690
  @service.delete_default_acl @bucket, entity,
692
691
  user_project: user_project
693
- @owners.delete entity unless @owners.nil?
694
- @readers.delete entity unless @readers.nil?
692
+ @owners&.delete entity
693
+ @readers&.delete entity
695
694
  true
696
695
  end
697
696
 
@@ -829,8 +828,7 @@ module Google
829
828
 
830
829
  def entities_from_acls acls, role
831
830
  selected = acls.select { |acl| acl.role == role }
832
- entities = selected.map(&:entity)
833
- entities
831
+ selected.map(&:entity)
834
832
  end
835
833
  end
836
834
  end
@@ -172,7 +172,10 @@ module Google
172
172
  # rule.max_age #=> 3600
173
173
  #
174
174
  class Rule
175
- attr_accessor :origin, :methods, :headers, :max_age
175
+ attr_accessor :origin
176
+ attr_accessor :methods
177
+ attr_accessor :headers
178
+ attr_accessor :max_age
176
179
 
177
180
  # @private
178
181
  def initialize origin, methods, headers: nil, max_age: nil
@@ -371,17 +371,17 @@ module Google
371
371
  # end
372
372
  #
373
373
  class Rule
374
- attr_accessor :action,
375
- :storage_class,
376
- :age,
377
- :created_before,
378
- :custom_time_before,
379
- :days_since_custom_time,
380
- :days_since_noncurrent_time,
381
- :is_live,
382
- :matches_storage_class,
383
- :noncurrent_time_before,
384
- :num_newer_versions
374
+ attr_accessor :action
375
+ attr_accessor :storage_class
376
+ attr_accessor :age
377
+ attr_accessor :created_before
378
+ attr_accessor :custom_time_before
379
+ attr_accessor :days_since_custom_time
380
+ attr_accessor :days_since_noncurrent_time
381
+ attr_accessor :is_live
382
+ attr_accessor :matches_storage_class
383
+ attr_accessor :noncurrent_time_before
384
+ attr_accessor :num_newer_versions
385
385
 
386
386
  # @private
387
387
  def initialize action,
@@ -125,17 +125,17 @@ module Google
125
125
  # puts bucket.name
126
126
  # end
127
127
  #
128
- def all request_limit: nil
128
+ def all request_limit: nil, &block
129
129
  request_limit = request_limit.to_i if request_limit
130
130
  unless block_given?
131
131
  return enum_for :all, request_limit: request_limit
132
132
  end
133
133
  results = self
134
134
  loop do
135
- results.each { |r| yield r }
135
+ results.each(&block)
136
136
  if request_limit
137
137
  request_limit -= 1
138
- break if request_limit < 0
138
+ break if request_limit.negative?
139
139
  end
140
140
  break unless results.next?
141
141
  results = results.next
@@ -38,20 +38,22 @@ module Google
38
38
  # storage.project_id #=> "my-project"
39
39
  #
40
40
  class Credentials < Google::Auth::Credentials
41
- SCOPE = \
42
- ["https://www.googleapis.com/auth/devstorage.full_control"].freeze
43
- PATH_ENV_VARS = %w[STORAGE_CREDENTIALS
44
- STORAGE_KEYFILE
45
- GOOGLE_CLOUD_CREDENTIALS
46
- GOOGLE_CLOUD_KEYFILE
47
- GCLOUD_KEYFILE].freeze
48
- JSON_ENV_VARS = %w[STORAGE_CREDENTIALS_JSON
49
- STORAGE_KEYFILE_JSON
50
- GOOGLE_CLOUD_CREDENTIALS_JSON
51
- GOOGLE_CLOUD_KEYFILE_JSON
52
- GCLOUD_KEYFILE_JSON].freeze
53
- DEFAULT_PATHS = \
54
- ["~/.config/gcloud/application_default_credentials.json"].freeze
41
+ SCOPE = ["https://www.googleapis.com/auth/devstorage.full_control"].freeze
42
+ PATH_ENV_VARS = [
43
+ "STORAGE_CREDENTIALS",
44
+ "STORAGE_KEYFILE",
45
+ "GOOGLE_CLOUD_CREDENTIALS",
46
+ "GOOGLE_CLOUD_KEYFILE",
47
+ "GCLOUD_KEYFILE"
48
+ ].freeze
49
+ JSON_ENV_VARS = [
50
+ "STORAGE_CREDENTIALS_JSON",
51
+ "STORAGE_KEYFILE_JSON",
52
+ "GOOGLE_CLOUD_CREDENTIALS_JSON",
53
+ "GOOGLE_CLOUD_KEYFILE_JSON",
54
+ "GCLOUD_KEYFILE_JSON"
55
+ ].freeze
56
+ DEFAULT_PATHS = ["~/.config/gcloud/application_default_credentials.json"].freeze
55
57
  end
56
58
  end
57
59
  end
@@ -191,7 +191,7 @@ module Google
191
191
  # @return [Integer]
192
192
  #
193
193
  def size
194
- @gapi.size.to_i if @gapi.size
194
+ @gapi.size&.to_i
195
195
  end
196
196
 
197
197
  ##
@@ -412,7 +412,8 @@ module Google
412
412
  # You can use this SHA256 hash to uniquely identify the AES-256
413
413
  # encryption key required to decrypt this file.
414
414
  #
415
- # @return [String]
415
+ # @return [String, nil] The encoded SHA256 hash, or `nil` if there is
416
+ # no customer-supplied encryption key for this file.
416
417
  #
417
418
  def encryption_key_sha256
418
419
  return nil unless @gapi.customer_encryption
@@ -1229,7 +1230,7 @@ module Google
1229
1230
  # cipher.encrypt
1230
1231
  # new_key = cipher.random_key
1231
1232
  #
1232
- # file = bucket.file "path/to/my-file.ext"
1233
+ # file = bucket.file "path/to/my-file.ext", encryption_key: old_key
1233
1234
  # file.rewrite "new-destination-bucket",
1234
1235
  # "path/to/destination/file.ext",
1235
1236
  # encryption_key: old_key,
@@ -1250,7 +1251,7 @@ module Google
1250
1251
  # # Old customer-supplied key was stored securely for later use.
1251
1252
  # old_key = "y\x03\"\x0E\xB6\xD3\x9B\x0E\xAB*\x19\xFAv\xDEY\xBEI..."
1252
1253
  #
1253
- # file = bucket.file "path/to/my-file.ext"
1254
+ # file = bucket.file "path/to/my-file.ext", encryption_key: old_key
1254
1255
  # file.rewrite "new-destination-bucket",
1255
1256
  # "path/to/destination/file.ext",
1256
1257
  # encryption_key: old_key,
@@ -1617,11 +1618,11 @@ module Google
1617
1618
  # scopes = ["https://www.googleapis.com/auth/iam"]
1618
1619
  # iam_client.authorization = Google::Auth.get_application_default scopes
1619
1620
  #
1620
- # request = {
1621
- # "payload": string_to_sign,
1622
- # }
1621
+ # request = Google::Apis::IamcredentialsV1::SignBlobRequest.new(
1622
+ # payload: string_to_sign
1623
+ # )
1623
1624
  # resource = "projects/-/serviceAccounts/#{issuer}"
1624
- # response = iam_client.sign_service_account_blob resource, request, {}
1625
+ # response = iam_client.sign_service_account_blob resource, request
1625
1626
  # response.signed_blob
1626
1627
  # end
1627
1628
  #
@@ -1872,7 +1873,7 @@ module Google
1872
1873
 
1873
1874
  ensure_service!
1874
1875
 
1875
- rewrite_attrs = %i[storage_class kms_key_name]
1876
+ rewrite_attrs = [:storage_class, :kms_key_name]
1876
1877
  @gapi = if attributes.any? { |a| rewrite_attrs.include? a }
1877
1878
  rewrite_gapi \
1878
1879
  bucket, name, update_gapi, user_project: user_project
@@ -1971,6 +1972,7 @@ module Google
1971
1972
  ##
1972
1973
  # @private Create an Updater object.
1973
1974
  def initialize gapi
1975
+ super()
1974
1976
  @updates = []
1975
1977
  @gapi = gapi
1976
1978
  @metadata ||= @gapi.metadata.to_h.dup
@@ -190,7 +190,7 @@ module Google
190
190
  generation: generation,
191
191
  user_project: user_project
192
192
  entity = gapi.entity
193
- @owners.push entity unless @owners.nil?
193
+ @owners&.push entity
194
194
  entity
195
195
  end
196
196
 
@@ -241,7 +241,7 @@ module Google
241
241
  generation: generation,
242
242
  user_project: user_project
243
243
  entity = gapi.entity
244
- @readers.push entity unless @readers.nil?
244
+ @readers&.push entity
245
245
  entity
246
246
  end
247
247
 
@@ -281,8 +281,8 @@ module Google
281
281
  @service.delete_file_acl \
282
282
  @bucket, @file, entity,
283
283
  generation: generation, user_project: user_project
284
- @owners.delete entity unless @owners.nil?
285
- @readers.delete entity unless @readers.nil?
284
+ @owners&.delete entity
285
+ @readers&.delete entity
286
286
  true
287
287
  end
288
288
 
@@ -428,8 +428,7 @@ module Google
428
428
 
429
429
  def entities_from_acls acls, role
430
430
  selected = acls.select { |acl| acl.role == role }
431
- entities = selected.map(&:entity)
432
- entities
431
+ selected.map(&:entity)
433
432
  end
434
433
  end
435
434
  end
@@ -141,17 +141,17 @@ module Google
141
141
  # puts file.name
142
142
  # end
143
143
  #
144
- def all request_limit: nil
144
+ def all request_limit: nil, &block
145
145
  request_limit = request_limit.to_i if request_limit
146
146
  unless block_given?
147
147
  return enum_for :all, request_limit: request_limit
148
148
  end
149
149
  results = self
150
150
  loop do
151
- results.each { |r| yield r }
151
+ results.each(&block)
152
152
  if request_limit
153
153
  request_limit -= 1
154
- break if request_limit < 0
154
+ break if request_limit.negative?
155
155
  end
156
156
  break unless results.next?
157
157
  results = results.next
@@ -147,10 +147,8 @@ module Google
147
147
  "&Expires=#{expires}" \
148
148
  "&Signature=#{url_escape signed_string}"
149
149
 
150
- if query
151
- query.each do |name, value|
152
- url << "&#{url_escape name}=#{url_escape value}"
153
- end
150
+ query&.each do |name, value|
151
+ url << "&#{url_escape name}=#{url_escape value}"
154
152
  end
155
153
 
156
154
  url
@@ -60,7 +60,7 @@ module Google
60
60
 
61
61
  p = {}
62
62
  p["conditions"] = policy_conditions base_fields, conditions, fields
63
- expires ||= 60*60*24
63
+ expires ||= 60 * 60 * 24
64
64
  p["expiration"] = (now + expires).strftime "%Y-%m-%dT%H:%M:%SZ"
65
65
 
66
66
  policy_str = escape_characters p.to_json
@@ -100,7 +100,7 @@ module Google
100
100
 
101
101
  algorithm = "GOOG4-RSA-SHA256"
102
102
  expires = determine_expires expires
103
- credential = issuer + "/" + scope
103
+ credential = "#{issuer}/#{scope}"
104
104
  canonical_query_str = canonical_query query, algorithm, credential, goog_date, expires, signed_headers_str
105
105
 
106
106
  # From AWS: You don't include a payload hash in the Canonical
@@ -129,11 +129,10 @@ module Google
129
129
  end
130
130
 
131
131
  # methods below are public visibility only for unit testing
132
+ # rubocop:disable Style/StringLiterals
132
133
  def escape_characters str
133
134
  str.split("").map do |s|
134
- if !s.ascii_only?
135
- escape_special_unicode s
136
- else
135
+ if s.ascii_only?
137
136
  case s
138
137
  when "\\"
139
138
  '\\'
@@ -152,12 +151,15 @@ module Google
152
151
  else
153
152
  s
154
153
  end
154
+ else
155
+ escape_special_unicode s
155
156
  end
156
157
  end.join
157
158
  end
159
+ # rubocop:enable Style/StringLiterals
158
160
 
159
161
  def escape_special_unicode str
160
- str.unpack("U*").map { |i| '\u' + i.to_s(16).rjust(4, "0") }.join
162
+ str.unpack("U*").map { |i| "\\u#{i.to_s(16).rjust(4, '0')}" }.join
161
163
  end
162
164
 
163
165
  protected
@@ -177,7 +179,7 @@ module Google
177
179
  # Add the bucket to the head of the base_fields. This is not returned in the PostObject fields.
178
180
  conditions.unshift "bucket" => @bucket_name
179
181
  # Add user-provided conditions to the head of the conditions array.
180
- conditions.unshift user_conditions if user_conditions && !user_conditions.empty?
182
+ conditions = user_conditions + conditions if user_conditions
181
183
  if user_fields
182
184
  # Convert each pair in fields hash to a single-entry hash and add it to the head of the conditions array.
183
185
  user_fields.to_a.reverse.each { |f| conditions.unshift Hash[*f] }
@@ -212,14 +214,14 @@ module Google
212
214
  if signer.is_a? Proc
213
215
  lambda do |string_to_sign|
214
216
  sig = signer.call string_to_sign
215
- sig.unpack("H*").first
217
+ sig.unpack1 "H*"
216
218
  end
217
219
  else
218
220
  signer = OpenSSL::PKey::RSA.new signer unless signer.respond_to? :sign
219
221
  # Sign string to sign
220
222
  lambda do |string_to_sign|
221
223
  sig = signer.sign OpenSSL::Digest::SHA256.new, string_to_sign
222
- sig.unpack("H*").first
224
+ sig.unpack1 "H*"
223
225
  end
224
226
  end
225
227
  end
@@ -273,7 +275,7 @@ module Google
273
275
  # Only the characters in the regex set [A-Za-z0-9.~_-] must be left un-escaped; all others must be
274
276
  # percent-encoded using %XX UTF-8 style.
275
277
  def escape_query_param str
276
- CGI.escape(str.to_s).gsub("%7E", "~").gsub("+", "%20")
278
+ CGI.escape(str.to_s).gsub("%7E", "~").gsub "+", "%20"
277
279
  end
278
280
 
279
281
  def host_name virtual_hosted_style, bucket_bound_hostname
@@ -287,7 +289,7 @@ module Google
287
289
  path = []
288
290
  path << "/#{@bucket_name}" if path_style
289
291
  path << "/#{String(@file_name)}" if @file_name && !@file_name.empty?
290
- CGI.escape(path.join).gsub "%2F", "/"
292
+ CGI.escape(path.join).gsub("%2F", "/").gsub "+", "%20"
291
293
  end
292
294
 
293
295
  ##
@@ -359,7 +361,7 @@ module Google
359
361
  end
360
362
  packed_signature = signing_key.sign OpenSSL::Digest::SHA256.new, data
361
363
  end
362
- packed_signature.unpack("H*").first.force_encoding "utf-8"
364
+ packed_signature.unpack1("H*").force_encoding "utf-8"
363
365
  end
364
366
  end
365
367
  end
@@ -131,17 +131,17 @@ module Google
131
131
  # puts key.access_id
132
132
  # end
133
133
  #
134
- def all request_limit: nil
134
+ def all request_limit: nil, &block
135
135
  request_limit = request_limit.to_i if request_limit
136
136
  unless block_given?
137
137
  return enum_for :all, request_limit: request_limit
138
138
  end
139
139
  results = self
140
140
  loop do
141
- results.each { |r| yield r }
141
+ results.each(&block)
142
142
  if request_limit
143
143
  request_limit -= 1
144
- break if request_limit < 0
144
+ break if request_limit.negative?
145
145
  end
146
146
  break unless results.next?
147
147
  results = results.next
@@ -212,8 +212,8 @@ module Google
212
212
  def deep_dup
213
213
  warn "DEPRECATED: Storage::PolicyV1#deep_dup"
214
214
  dup.tap do |p|
215
- roles_dup = p.roles.each_with_object({}) do |(k, v), memo|
216
- memo[k] = v.dup rescue value
215
+ roles_dup = p.roles.transform_values do |v|
216
+ v.dup rescue value
217
217
  end
218
218
  p.instance_variable_set :@roles, roles_dup
219
219
  end
@@ -89,7 +89,9 @@ module Google
89
89
  # end
90
90
  #
91
91
  class Binding
92
- attr_reader :role, :members, :condition
92
+ attr_reader :role
93
+ attr_reader :members
94
+ attr_reader :condition
93
95
 
94
96
  ##
95
97
  # Creates a Binding object.
@@ -128,8 +130,8 @@ module Google
128
130
  raise ArgumentError, "members is empty, must be provided" if @members.empty?
129
131
 
130
132
  condition = Condition.new(**condition) if condition.is_a? Hash
131
- if condition
132
- raise ArgumentError, "expected Condition, not #{condition.inspect}" unless condition.is_a? Condition
133
+ if condition && !(condition.is_a? Condition)
134
+ raise ArgumentError, "expected Condition, not #{condition.inspect}"
133
135
  end
134
136
  @condition = condition
135
137
  end
@@ -168,10 +168,10 @@ module Google
168
168
  # puts binding.role
169
169
  # end
170
170
  #
171
- def each
171
+ def each &block
172
172
  return enum_for :each unless block_given?
173
173
 
174
- @bindings.each { |binding| yield binding }
174
+ @bindings.each(&block)
175
175
  end
176
176
 
177
177
  ##
@@ -70,7 +70,9 @@ module Google
70
70
  # end
71
71
  #
72
72
  class Condition
73
- attr_reader :title, :description, :expression
73
+ attr_reader :title
74
+ attr_reader :description
75
+ attr_reader :expression
74
76
 
75
77
  ##
76
78
  # Creates a Condition object.
@@ -83,7 +85,7 @@ module Google
83
85
  # one attributes, and statements are combined using logic operators,
84
86
  # following CEL language specification. Required.
85
87
  #
86
- def initialize title:, description: nil, expression:
88
+ def initialize title:, expression:, description: nil
87
89
  @title = String title
88
90
  @description = String description
89
91
  @expression = String expression
@@ -59,7 +59,8 @@ module Google
59
59
  # post.fields["x-goog-signature"] #=> "4893a0e...cd82"
60
60
  #
61
61
  class PostObject
62
- attr_reader :url, :fields
62
+ attr_reader :url
63
+ attr_reader :fields
63
64
 
64
65
  # @private
65
66
  def initialize url, fields
@@ -611,11 +611,11 @@ module Google
611
611
  # scopes = ["https://www.googleapis.com/auth/iam"]
612
612
  # iam_client.authorization = Google::Auth.get_application_default scopes
613
613
  #
614
- # request = {
615
- # "payload": string_to_sign,
616
- # }
614
+ # request = Google::Apis::IamcredentialsV1::SignBlobRequest.new(
615
+ # payload: string_to_sign
616
+ # )
617
617
  # resource = "projects/-/serviceAccounts/#{issuer}"
618
- # response = iam_client.sign_service_account_blob resource, request, {}
618
+ # response = iam_client.sign_service_account_blob resource, request
619
619
  # response.signed_blob
620
620
  # end
621
621
  #
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Storage
19
- VERSION = "1.29.0".freeze
19
+ VERSION = "1.31.1".freeze
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.29.0
4
+ version: 1.31.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-09-22 00:00:00.000000000 Z
12
+ date: 2021-05-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core
@@ -26,19 +26,33 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  version: '1.2'
28
28
  - !ruby/object:Gem::Dependency
29
- name: google-api-client
29
+ name: google-apis-iamcredentials_v1
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '0.33'
34
+ version: '0.1'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '0.33'
41
+ version: '0.1'
42
+ - !ruby/object:Gem::Dependency
43
+ name: google-apis-storage_v1
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '0.1'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '0.1'
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: googleauth
44
58
  requirement: !ruby/object:Gem::Requirement
@@ -101,14 +115,14 @@ dependencies:
101
115
  requirements:
102
116
  - - "~>"
103
117
  - !ruby/object:Gem::Version
104
- version: 1.24.0
118
+ version: 1.25.1
105
119
  type: :development
106
120
  prerelease: false
107
121
  version_requirements: !ruby/object:Gem::Requirement
108
122
  requirements:
109
123
  - - "~>"
110
124
  - !ruby/object:Gem::Version
111
- version: 1.24.0
125
+ version: 1.25.1
112
126
  - !ruby/object:Gem::Dependency
113
127
  name: minitest
114
128
  requirement: !ruby/object:Gem::Requirement
@@ -291,14 +305,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
291
305
  requirements:
292
306
  - - ">="
293
307
  - !ruby/object:Gem::Version
294
- version: '2.4'
308
+ version: '2.5'
295
309
  required_rubygems_version: !ruby/object:Gem::Requirement
296
310
  requirements:
297
311
  - - ">="
298
312
  - !ruby/object:Gem::Version
299
313
  version: '0'
300
314
  requirements: []
301
- rubygems_version: 3.1.4
315
+ rubygems_version: 3.2.17
302
316
  signing_key:
303
317
  specification_version: 4
304
318
  summary: API Client library for Google Cloud Storage