google-cloud-storage 1.25.1 → 1.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: ab43474a1a6a25a439d96a67b8664caff72861d3d121c927d5c11623ae570cab
4
- data.tar.gz: f2e6378f9708fc079f2ce3539947e5587eb57263b2d96c8877c93d1b07b30abd
2
+ SHA1:
3
+ metadata.gz: 5141d81168421311ea103c5d466e2f0a1e6a6b6d
4
+ data.tar.gz: 352c5ac1297c6919c8a71d80bd61a24697692bd2
5
5
  SHA512:
6
- metadata.gz: d40dfe073d42be6d3098a5c5e8779c4c52a7407b77f159e435e8c76ffe1cc59fc037591bcbc1b00ebaea9763d6085c7a9e639549eaacd89ea1444c1cd81a75e3
7
- data.tar.gz: 16c8f515149d0794c40a474fb43d6c1859ff427b1ab5c75c6f4610959c49e3ed1a2c8d3a0060be58ded02f34867437fcaf81c1e2a8e00a8320af2fff470e5b34
6
+ metadata.gz: 7bec28a4b4eebf986b43b9d06115955cc44ed03430f657b5f5eb9a2aff1ba26e77adcbbac9f2a57536f1734fda1c795664e65532f3476dcd085703aa8dc167b8
7
+ data.tar.gz: 894e70a45cf36a63158e07059a84a13e3a668d4730dab612a8acca3fdf532fa97e74e20a06bb86c037343e54c468a53fa16e2eaefbbe25e1cb9c0c198d007e82
@@ -102,8 +102,14 @@ To configure your system for this, simply:
102
102
  2. Authenticate using OAuth 2.0 `$ gcloud auth login`
103
103
  3. Write code as if already authenticated.
104
104
 
105
- **NOTE:** This is _not_ recommended for running in production. The Cloud SDK
106
- *should* only be used during development.
105
+ **NOTE:** The use of Cloud SDK credentials is _not_ recommended for running in
106
+ production. The Cloud SDK *should* only be used during development.
107
+
108
+ **NOTE:** The use of Cloud SDK credentials may not support certain methods such as
109
+ those that produce
110
+ [signed URLs](https://cloud.google.com/storage/docs/access-control/signed-urls) and
111
+ post objects. For these methods, authentication using a service account JSON key file
112
+ is required.
107
113
 
108
114
  [gce-how-to]: https://cloud.google.com/compute/docs/authentication#using
109
115
  [dev-console]: https://console.cloud.google.com/project
@@ -1,5 +1,61 @@
1
1
  # Release History
2
2
 
3
+ ### 1.28.0 / 2020-08-26
4
+
5
+ * Add Object Lifecycle Management fields
6
+ * Add custom_time_before to Lifecycle::Rule
7
+ * Add days_since_custom_time to Lifecycle::Rule
8
+ * Add days_since_noncurrent_time to Lifecycle::Rule
9
+ * Add noncurrent_time_before to Lifecycle::Rule
10
+ * Add File#custom_time and #custom_time=
11
+
12
+ ### 1.27.0 / 2020-07-29
13
+
14
+ #### Features
15
+
16
+ * Add support for signing URLs with IAMCredentials SignBlob API
17
+ * Add signer parameter accepting Procs to the following methods:
18
+ * Project#signed_url
19
+ * Bucket#generate_signed_post_policy_v4
20
+ * Bucket#post_object
21
+ * Bucket#signed_url
22
+ * File#signed_url
23
+ * Update signer aliases signing_key and private_key to similarly support Procs
24
+
25
+ #### Documentation
26
+
27
+ * Update documentation of SignedUrlUnavailable
28
+
29
+ ### 1.26.2 / 2020-05-28
30
+
31
+ #### Documentation
32
+
33
+ * Fix a few broken links
34
+
35
+ ### 1.26.1 / 2020-05-06
36
+
37
+ #### Bug Fixes
38
+
39
+ * Add missing bucket condition in SignerV4#post_object
40
+ * Ensure bucket is not returned in PostObject fields
41
+
42
+ ### 1.26.0 / 2020-04-06
43
+
44
+ #### Features
45
+
46
+ * Update V4 Signature support in Project#signed_url, Bucket#signed_url and File#signed_url
47
+ * Add scheme, virtual_hosted_style and bucket_bound_hostname to #signed_url methods
48
+ * Add support for V4 query param encoding and ordering
49
+ * Convert tabs in V4 to single whitespace character
50
+ * Set payload in V4 to X-Goog-Content-SHA256 if present
51
+ * Fix method param default value GET for #signed_url
52
+ * Add support for V4 Signature POST Policies
53
+ * Add Bucket#generate_signed_post_policy_v4
54
+
55
+ #### Bug Fixes
56
+
57
+ * Address keyword argument warnings in Ruby 2.7 and later
58
+
3
59
  ### 1.25.1 / 2020-01-06
4
60
 
5
61
  #### Documentation
@@ -24,14 +24,8 @@ improved, *please* create a new issue on GitHub so we can talk about it.
24
24
 
25
25
  - [New issue][gh-ruby]
26
26
 
27
- Or, you can ask questions on the [Google Cloud Platform Slack][slack-ruby]. You
28
- can use the "ruby" channel for general Ruby questions, or use the
29
- "google-cloud-ruby" channel if you have questions about this gem in particular.
30
-
31
27
  [so-ruby]: http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby+storage
32
28
 
33
- [gh-search-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues?q=label%3A%22api%3A+storage%22
34
-
35
- [gh-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues/new
29
+ [gh-search-ruby]: https://github.com/googleapis/google-cloud-ruby/issues?q=label%3A%22api%3A+storage%22
36
30
 
37
- [slack-ruby]: https://gcp-slack.appspot.com/
31
+ [gh-ruby]: https://github.com/googleapis/google-cloud-ruby/issues/new
@@ -1128,6 +1128,11 @@ module Google
1128
1128
  # @param [String] content_type The
1129
1129
  # [Content-Type](https://tools.ietf.org/html/rfc2616#section-14.17)
1130
1130
  # response header to be returned when the file is downloaded.
1131
+ # @param [DateTime] custom_time A custom time specified by the user for
1132
+ # the file. Once set, custom_time can't be unset, and it can only be
1133
+ # changed to a time in the future. If custom_time must be unset, you
1134
+ # must either perform a rewrite operation, or upload the data again
1135
+ # and create a new file.
1131
1136
  # @param [String] crc32c The CRC32c checksum of the file data, as
1132
1137
  # described in [RFC 4960, Appendix
1133
1138
  # B](http://tools.ietf.org/html/rfc4960#appendix-B).
@@ -1249,27 +1254,33 @@ module Google
1249
1254
  #
1250
1255
  def create_file file, path = nil, acl: nil, cache_control: nil,
1251
1256
  content_disposition: nil, content_encoding: nil,
1252
- content_language: nil, content_type: nil,
1257
+ content_language: nil, content_type: nil, custom_time: nil,
1253
1258
  crc32c: nil, md5: nil, metadata: nil,
1254
1259
  storage_class: nil, encryption_key: nil, kms_key: nil,
1255
1260
  temporary_hold: nil, event_based_hold: nil
1256
1261
  ensure_service!
1257
- options = { acl: File::Acl.predefined_rule_for(acl), md5: md5,
1258
- cache_control: cache_control, content_type: content_type,
1259
- content_disposition: content_disposition, crc32c: crc32c,
1260
- content_encoding: content_encoding, metadata: metadata,
1261
- content_language: content_language, key: encryption_key,
1262
- kms_key: kms_key,
1263
- storage_class: storage_class_for(storage_class),
1264
- temporary_hold: temporary_hold,
1265
- event_based_hold: event_based_hold,
1266
- user_project: user_project }
1267
1262
  ensure_io_or_file_exists! file
1268
1263
  path ||= file.path if file.respond_to? :path
1269
1264
  path ||= file if file.is_a? String
1270
1265
  raise ArgumentError, "must provide path" if path.nil?
1271
1266
 
1272
- gapi = service.insert_file name, file, path, options
1267
+
1268
+ gapi = service.insert_file name, file, path, acl: File::Acl.predefined_rule_for(acl),
1269
+ md5: md5,
1270
+ cache_control: cache_control,
1271
+ content_type: content_type,
1272
+ custom_time: custom_time,
1273
+ content_disposition: content_disposition,
1274
+ crc32c: crc32c,
1275
+ content_encoding: content_encoding,
1276
+ metadata: metadata,
1277
+ content_language: content_language,
1278
+ key: encryption_key,
1279
+ kms_key: kms_key,
1280
+ storage_class: storage_class_for(storage_class),
1281
+ temporary_hold: temporary_hold,
1282
+ event_based_hold: event_based_hold,
1283
+ user_project: user_project
1273
1284
  File.from_gapi gapi, service, user_project: user_project
1274
1285
  end
1275
1286
  alias upload_file create_file
@@ -1368,9 +1379,6 @@ module Google
1368
1379
  raise ArgumentError, "must provide at least two source files"
1369
1380
  end
1370
1381
 
1371
- options = { acl: File::Acl.predefined_rule_for(acl),
1372
- key: encryption_key,
1373
- user_project: user_project }
1374
1382
  destination_gapi = nil
1375
1383
  if block_given?
1376
1384
  destination_gapi = API::Object.new
@@ -1378,8 +1386,11 @@ module Google
1378
1386
  yield updater
1379
1387
  updater.check_for_changed_metadata!
1380
1388
  end
1381
- gapi = service.compose_file name, sources, destination,
1382
- destination_gapi, options
1389
+
1390
+ acl_rule = File::Acl.predefined_rule_for acl
1391
+ gapi = service.compose_file name, sources, destination, destination_gapi, acl: acl_rule,
1392
+ key: encryption_key,
1393
+ user_project: user_project
1383
1394
  File.from_gapi gapi, service, user_project: user_project
1384
1395
  end
1385
1396
  alias compose_file compose
@@ -1401,7 +1412,7 @@ module Google
1401
1412
  # A {SignedUrlUnavailable} is raised if the service account credentials
1402
1413
  # are missing. Service account credentials are acquired by following the
1403
1414
  # steps in [Service Account Authentication](
1404
- # https://cloud.google.com/storage/docs/authentication#service_accounts).
1415
+ # https://cloud.google.com/iam/docs/service-accounts).
1405
1416
  #
1406
1417
  # @see https://cloud.google.com/storage/docs/access-control/signed-urls
1407
1418
  # Signed URLs guide
@@ -1428,10 +1439,22 @@ module Google
1428
1439
  # use the signed URL.
1429
1440
  # @param [String] issuer Service Account's Client Email.
1430
1441
  # @param [String] client_email Service Account's Client Email.
1431
- # @param [OpenSSL::PKey::RSA, String] signing_key Service Account's
1432
- # Private Key.
1433
- # @param [OpenSSL::PKey::RSA, String] private_key Service Account's
1434
- # Private Key.
1442
+ # @param [OpenSSL::PKey::RSA, String, Proc] signing_key Service Account's
1443
+ # Private Key or a Proc that accepts a single String parameter and returns a
1444
+ # RSA SHA256 signature using a valid Google Service Account Private Key.
1445
+ # @param [OpenSSL::PKey::RSA, String, Proc] private_key Service Account's
1446
+ # Private Key or a Proc that accepts a single String parameter and returns a
1447
+ # RSA SHA256 signature using a valid Google Service Account Private Key.
1448
+ # @param [OpenSSL::PKey::RSA, String, Proc] signer Service Account's
1449
+ # Private Key or a Proc that accepts a single String parameter and returns a
1450
+ # RSA SHA256 signature using a valid Google Service Account Private Key.
1451
+ #
1452
+ # When using this method in environments such as GAE Flexible Environment,
1453
+ # GKE, or Cloud Functions where the private key is unavailable, it may be
1454
+ # necessary to provide a Proc (or lambda) via the signer parameter. This
1455
+ # Proc should return a signature created using a RPC call to the
1456
+ # [Service Account Credentials signBlob](https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signBlob)
1457
+ # method as shown in the example below.
1435
1458
  # @param [Hash] query Query string parameters to include in the signed
1436
1459
  # URL. The given parameters are not verified by the signature.
1437
1460
  #
@@ -1440,11 +1463,29 @@ module Google
1440
1463
  # using the URL, but only when the file resource is missing the
1441
1464
  # corresponding values. (These values can be permanently set using
1442
1465
  # {File#content_disposition=} and {File#content_type=}.)
1466
+ # @param [String] scheme The URL scheme. The default value is `HTTPS`.
1467
+ # @param [Boolean] virtual_hosted_style Whether to use a virtual hosted-style
1468
+ # hostname, which adds the bucket into the host portion of the URI rather
1469
+ # than the path, e.g. `https://mybucket.storage.googleapis.com/...`.
1470
+ # For V4 signing, this also sets the `host` header in the canonicalized
1471
+ # extension headers to the virtual hosted-style host, unless that header is
1472
+ # supplied via the `headers` param. The default value of `false` uses the
1473
+ # form of `https://storage.googleapis.com/mybucket`.
1474
+ # @param [String] bucket_bound_hostname Use a bucket-bound hostname, which
1475
+ # replaces the `storage.googleapis.com` host with the name of a `CNAME`
1476
+ # bucket, e.g. a bucket named `gcs-subdomain.my.domain.tld`, or a Google
1477
+ # Cloud Load Balancer which routes to a bucket you own, e.g.
1478
+ # `my-load-balancer-domain.tld`.
1443
1479
  # @param [Symbol, String] version The version of the signed credential
1444
1480
  # to create. Must be one of `:v2` or `:v4`. The default value is
1445
1481
  # `:v2`.
1446
1482
  #
1447
- # @return [String]
1483
+ # @return [String] The signed URL.
1484
+ #
1485
+ # @raise [SignedUrlUnavailable] If the service account credentials
1486
+ # are missing. Service account credentials are acquired by following the
1487
+ # steps in [Service Account Authentication](
1488
+ # https://cloud.google.com/iam/docs/service-accounts).
1448
1489
  #
1449
1490
  # @example
1450
1491
  # require "google/cloud/storage"
@@ -1475,6 +1516,40 @@ module Google
1475
1516
  # issuer: "service-account@gcloud.com",
1476
1517
  # signing_key: key
1477
1518
  #
1519
+ # @example Using Cloud IAMCredentials signBlob to create the signature:
1520
+ # require "google/cloud/storage"
1521
+ # require "google/apis/iamcredentials_v1"
1522
+ # require "googleauth"
1523
+ #
1524
+ # # Issuer is the service account email that the Signed URL will be signed with
1525
+ # # and any permission granted in the Signed URL must be granted to the
1526
+ # # Google Service Account.
1527
+ # issuer = "service-account@project-id.iam.gserviceaccount.com"
1528
+ #
1529
+ # # Create a lambda that accepts the string_to_sign
1530
+ # signer = lambda do |string_to_sign|
1531
+ # IAMCredentials = Google::Apis::IamcredentialsV1
1532
+ # iam_client = IAMCredentials::IAMCredentialsService.new
1533
+ #
1534
+ # # Get the environment configured authorization
1535
+ # scopes = ["https://www.googleapis.com/auth/iam"]
1536
+ # iam_client.authorization = Google::Auth.get_application_default scopes
1537
+ #
1538
+ # request = {
1539
+ # "payload": string_to_sign,
1540
+ # }
1541
+ # resource = "projects/-/serviceAccounts/#{issuer}"
1542
+ # response = iam_client.sign_service_account_blob resource, request, {}
1543
+ # response.signed_blob
1544
+ # end
1545
+ #
1546
+ # storage = Google::Cloud::Storage.new
1547
+ #
1548
+ # bucket_name = "my-todo-app"
1549
+ # file_path = "avatars/heidi/400x400.png"
1550
+ # url = storage.signed_url bucket_name, file_path,
1551
+ # method: "GET", issuer: issuer,
1552
+ # signer: signer
1478
1553
  # @example Using the `headers` option:
1479
1554
  # require "google/cloud/storage"
1480
1555
  #
@@ -1510,28 +1585,52 @@ module Google
1510
1585
  # bucket = storage.bucket "my-todo-app"
1511
1586
  # list_files_url = bucket.signed_url version: :v4
1512
1587
  #
1513
- def signed_url path = nil, method: nil, expires: nil, content_type: nil,
1514
- content_md5: nil, headers: nil, issuer: nil,
1515
- client_email: nil, signing_key: nil, private_key: nil,
1516
- query: nil, version: nil
1588
+ def signed_url path = nil,
1589
+ method: "GET",
1590
+ expires: nil,
1591
+ content_type: nil,
1592
+ content_md5: nil,
1593
+ headers: nil,
1594
+ issuer: nil,
1595
+ client_email: nil,
1596
+ signing_key: nil,
1597
+ private_key: nil,
1598
+ signer: nil,
1599
+ query: nil,
1600
+ scheme: "HTTPS",
1601
+ virtual_hosted_style: nil,
1602
+ bucket_bound_hostname: nil,
1603
+ version: nil
1517
1604
  ensure_service!
1518
1605
  version ||= :v2
1519
1606
  case version.to_sym
1520
1607
  when :v2
1521
- signer = File::SignerV2.from_bucket self, path
1522
- signer.signed_url method: method, expires: expires,
1523
- headers: headers, content_type: content_type,
1524
- content_md5: content_md5, issuer: issuer,
1525
- client_email: client_email,
1526
- signing_key: signing_key,
1527
- private_key: private_key, query: query
1608
+ sign = File::SignerV2.from_bucket self, path
1609
+ sign.signed_url method: method,
1610
+ expires: expires,
1611
+ headers: headers,
1612
+ content_type: content_type,
1613
+ content_md5: content_md5,
1614
+ issuer: issuer,
1615
+ client_email: client_email,
1616
+ signing_key: signing_key,
1617
+ private_key: private_key,
1618
+ signer: signer,
1619
+ query: query
1528
1620
  when :v4
1529
- signer = File::SignerV4.from_bucket self, path
1530
- signer.signed_url method: method, expires: expires,
1531
- headers: headers, issuer: issuer,
1532
- client_email: client_email,
1533
- signing_key: signing_key,
1534
- private_key: private_key, query: query
1621
+ sign = File::SignerV4.from_bucket self, path
1622
+ sign.signed_url method: method,
1623
+ expires: expires,
1624
+ headers: headers,
1625
+ issuer: issuer,
1626
+ client_email: client_email,
1627
+ signing_key: signing_key,
1628
+ private_key: private_key,
1629
+ signer: signer,
1630
+ query: query,
1631
+ scheme: scheme,
1632
+ virtual_hosted_style: virtual_hosted_style,
1633
+ bucket_bound_hostname: bucket_bound_hostname
1535
1634
  else
1536
1635
  raise ArgumentError, "version '#{version}' not supported"
1537
1636
  end
@@ -1552,28 +1651,45 @@ module Google
1552
1651
  # A {SignedUrlUnavailable} is raised if the service account credentials
1553
1652
  # are missing. Service account credentials are acquired by following the
1554
1653
  # steps in [Service Account Authentication](
1555
- # https://cloud.google.com/storage/docs/authentication#service_accounts).
1654
+ # https://cloud.google.com/iam/docs/service-accounts).
1556
1655
  #
1557
1656
  # @see https://cloud.google.com/storage/docs/xml-api/post-object
1558
1657
  #
1559
1658
  # @param [String] path Path to the file in Google Cloud Storage.
1560
1659
  # @param [Hash] policy The security policy that describes what
1561
- # can and cannot be uploaded in the form. When provided,
1562
- # the PostObject fields will include a Signature based on the JSON
1563
- # representation of this Hash and the same policy in Base64 format.
1660
+ # can and cannot be uploaded in the form. When provided, the PostObject
1661
+ # fields will include a signature based on the JSON representation of
1662
+ # this hash and the same policy in Base64 format.
1663
+ #
1564
1664
  # If you do not provide a security policy, requests are considered
1565
1665
  # to be anonymous and will only work with buckets that have granted
1566
- # WRITE or FULL_CONTROL permission to anonymous users.
1666
+ # `WRITE` or `FULL_CONTROL` permission to anonymous users.
1567
1667
  # See [Policy Document](https://cloud.google.com/storage/docs/xml-api/post-object#policydocument)
1568
1668
  # for more information.
1569
1669
  # @param [String] issuer Service Account's Client Email.
1570
1670
  # @param [String] client_email Service Account's Client Email.
1571
- # @param [OpenSSL::PKey::RSA, String] signing_key Service Account's
1572
- # Private Key.
1573
- # @param [OpenSSL::PKey::RSA, String] private_key Service Account's
1574
- # Private Key.
1575
- #
1576
- # @return [PostObject]
1671
+ # @param [OpenSSL::PKey::RSA, String, Proc] signing_key Service Account's
1672
+ # Private Key or a Proc that accepts a single String parameter and returns a
1673
+ # RSA SHA256 signature using a valid Google Service Account Private Key.
1674
+ # @param [OpenSSL::PKey::RSA, String, Proc] private_key Service Account's
1675
+ # Private Key or a Proc that accepts a single String parameter and returns a
1676
+ # RSA SHA256 signature using a valid Google Service Account Private Key.
1677
+ # @param [OpenSSL::PKey::RSA, String, Proc] signer Service Account's
1678
+ # Private Key or a Proc that accepts a single String parameter and returns a
1679
+ # RSA SHA256 signature using a valid Google Service Account Private Key.
1680
+ #
1681
+ # When using this method in environments such as GAE Flexible Environment,
1682
+ # GKE, or Cloud Functions where the private key is unavailable, it may be
1683
+ # necessary to provide a Proc (or lambda) via the signer parameter. This
1684
+ # Proc should return a signature created using a RPC call to the
1685
+ # [Service Account Credentials signBlob](https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signBlob)
1686
+ # 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.
1688
+ #
1689
+ # @raise [SignedUrlUnavailable] If the service account credentials
1690
+ # are missing. Service account credentials are acquired by following the
1691
+ # steps in [Service Account Authentication](
1692
+ # https://cloud.google.com/iam/docs/service-accounts).
1577
1693
  #
1578
1694
  # @example
1579
1695
  # require "google/cloud/storage"
@@ -1633,15 +1749,213 @@ module Google
1633
1749
  # post.fields[:signature] #=> "ABC...XYZ="
1634
1750
  # post.fields[:policy] #=> "ABC...XYZ="
1635
1751
  #
1636
- def post_object path, policy: nil, issuer: nil,
1637
- client_email: nil, signing_key: nil,
1638
- private_key: nil
1752
+ # @example Using Cloud IAMCredentials signBlob to create the signature:
1753
+ # require "google/cloud/storage"
1754
+ # require "google/apis/iamcredentials_v1"
1755
+ # require "googleauth"
1756
+ #
1757
+ # # Issuer is the service account email that the Signed URL will be signed with
1758
+ # # and any permission granted in the Signed URL must be granted to the
1759
+ # # Google Service Account.
1760
+ # issuer = "service-account@project-id.iam.gserviceaccount.com"
1761
+ #
1762
+ # # Create a lambda that accepts the string_to_sign
1763
+ # signer = lambda do |string_to_sign|
1764
+ # IAMCredentials = Google::Apis::IamcredentialsV1
1765
+ # iam_client = IAMCredentials::IAMCredentialsService.new
1766
+ #
1767
+ # # Get the environment configured authorization
1768
+ # scopes = ["https://www.googleapis.com/auth/iam"]
1769
+ # iam_client.authorization = Google::Auth.get_application_default scopes
1770
+ #
1771
+ # request = {
1772
+ # "payload": string_to_sign,
1773
+ # }
1774
+ # resource = "projects/-/serviceAccounts/#{issuer}"
1775
+ # response = iam_client.sign_service_account_blob resource, request, {}
1776
+ # response.signed_blob
1777
+ # end
1778
+ #
1779
+ # storage = Google::Cloud::Storage.new
1780
+ #
1781
+ # bucket = storage.bucket "my-todo-app"
1782
+ # post = bucket.post_object "avatars/heidi/400x400.png",
1783
+ # issuer: issuer,
1784
+ # signer: signer
1785
+ #
1786
+ # post.url #=> "https://storage.googleapis.com"
1787
+ # post.fields[:key] #=> "my-todo-app/avatars/heidi/400x400.png"
1788
+ # post.fields[:GoogleAccessId] #=> "0123456789@gserviceaccount.com"
1789
+ # post.fields[:signature] #=> "ABC...XYZ="
1790
+ # post.fields[:policy] #=> "ABC...XYZ="
1791
+ #
1792
+ def post_object path,
1793
+ policy: nil,
1794
+ issuer: nil,
1795
+ client_email: nil,
1796
+ signing_key: nil,
1797
+ private_key: nil,
1798
+ signer: nil
1639
1799
  ensure_service!
1800
+ sign = File::SignerV2.from_bucket self, path
1801
+ sign.post_object issuer: issuer,
1802
+ client_email: client_email,
1803
+ signing_key: signing_key,
1804
+ private_key: private_key,
1805
+ signer: signer,
1806
+ policy: policy
1807
+ end
1640
1808
 
1641
- signer = File::SignerV2.from_bucket self, path
1642
- signer.post_object issuer: issuer, client_email: client_email,
1643
- signing_key: signing_key, private_key: private_key,
1644
- policy: policy
1809
+ ##
1810
+ # Generate a PostObject that includes the fields and url to
1811
+ # upload objects via html forms.
1812
+ #
1813
+ # Generating a PostObject requires service account credentials,
1814
+ # either by connecting with a service account when calling
1815
+ # {Google::Cloud.storage}, or by passing in the service account
1816
+ # `issuer` and `signing_key` values. Although the private key can
1817
+ # be passed as a string for convenience, creating and storing
1818
+ # an instance of `OpenSSL::PKey::RSA` is more efficient
1819
+ # when making multiple calls to `generate_signed_post_policy_v4`.
1820
+ #
1821
+ # A {SignedUrlUnavailable} is raised if the service account credentials
1822
+ # are missing. Service account credentials are acquired by following the
1823
+ # steps in [Service Account Authentication](
1824
+ # https://cloud.google.com/iam/docs/service-accounts).
1825
+ #
1826
+ # @see https://cloud.google.com/storage/docs/xml-api/post-object
1827
+ #
1828
+ # @param [String] path Path to the file in Google Cloud Storage.
1829
+ # @param [String] issuer Service Account's Client Email.
1830
+ # @param [String] client_email Service Account's Client Email.
1831
+ # @param [OpenSSL::PKey::RSA, String, Proc] signing_key Service Account's
1832
+ # Private Key or a Proc that accepts a single String parameter and returns a
1833
+ # RSA SHA256 signature using a valid Google Service Account Private Key.
1834
+ # @param [OpenSSL::PKey::RSA, String, Proc] private_key Service Account's
1835
+ # Private Key or a Proc that accepts a single String parameter and returns a
1836
+ # RSA SHA256 signature using a valid Google Service Account Private Key.
1837
+ # @param [OpenSSL::PKey::RSA, String, Proc] signer Service Account's
1838
+ # Private Key or a Proc that accepts a single String parameter and returns a
1839
+ # RSA SHA256 signature using a valid Google Service Account Private Key.
1840
+ #
1841
+ # When using this method in environments such as GAE Flexible Environment,
1842
+ # GKE, or Cloud Functions where the private key is unavailable, it may be
1843
+ # necessary to provide a Proc (or lambda) via the signer parameter. This
1844
+ # Proc should return a signature created using a RPC call to the
1845
+ # [Service Account Credentials signBlob](https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signBlob)
1846
+ # method as shown in the example below.
1847
+ # @param [Integer] expires The number of seconds until the URL expires.
1848
+ # The default is 604800 (7 days).
1849
+ # @param [Hash] fields User-supplied form fields such as `acl`,
1850
+ # `cache-control`, `success_action_status`, and `success_action_redirect`.
1851
+ # @param [Array<Hash|Array>] conditions User-supplied policy conditions.
1852
+ # @param [String] scheme The URL scheme. The default value is `HTTPS`.
1853
+ # @param [Boolean] virtual_hosted_style Whether to use a virtual hosted-style
1854
+ # hostname, which adds the bucket into the host portion of the URI rather
1855
+ # than the path, e.g. `https://mybucket.storage.googleapis.com/...`.
1856
+ # The default value of `false` uses the
1857
+ # form of `https://storage.googleapis.com/mybucket`.
1858
+ # @param [String] bucket_bound_hostname Use a bucket-bound hostname, which
1859
+ # replaces the `storage.googleapis.com` host with the name of a `CNAME`
1860
+ # bucket, e.g. a bucket named `gcs-subdomain.my.domain.tld`, or a Google
1861
+ # Cloud Load Balancer which routes to a bucket you own, e.g.
1862
+ # `my-load-balancer-domain.tld`.
1863
+ #
1864
+ # @return [PostObject] An object containing the URL, fields, and values needed to upload files via html forms.
1865
+ #
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).
1870
+ #
1871
+ # @example
1872
+ # require "google/cloud/storage"
1873
+ #
1874
+ # storage = Google::Cloud::Storage.new
1875
+ #
1876
+ # bucket = storage.bucket "my-todo-app"
1877
+ #
1878
+ # conditions = [["starts-with", "$acl","public"]]
1879
+ # post = bucket.generate_signed_post_policy_v4 "avatars/heidi/400x400.png", expires: 10,
1880
+ # conditions: conditions
1881
+ #
1882
+ # post.url #=> "https://storage.googleapis.com/my-todo-app/"
1883
+ # post.fields["key"] #=> "my-todo-app/avatars/heidi/400x400.png"
1884
+ # post.fields["policy"] #=> "ABC...XYZ"
1885
+ # post.fields["x-goog-algorithm"] #=> "GOOG4-RSA-SHA256"
1886
+ # post.fields["x-goog-credential"] #=> "cred@pid.iam.gserviceaccount.com/20200123/auto/storage/goog4_request"
1887
+ # post.fields["x-goog-date"] #=> "20200128T000000Z"
1888
+ # post.fields["x-goog-signature"] #=> "4893a0e...cd82"
1889
+ #
1890
+ # @example Using Cloud IAMCredentials signBlob to create the signature:
1891
+ # require "google/cloud/storage"
1892
+ # require "google/apis/iamcredentials_v1"
1893
+ # require "googleauth"
1894
+ #
1895
+ # # Issuer is the service account email that the Signed URL will be signed with
1896
+ # # and any permission granted in the Signed URL must be granted to the
1897
+ # # Google Service Account.
1898
+ # issuer = "service-account@project-id.iam.gserviceaccount.com"
1899
+ #
1900
+ # # Create a lambda that accepts the string_to_sign
1901
+ # signer = lambda do |string_to_sign|
1902
+ # IAMCredentials = Google::Apis::IamcredentialsV1
1903
+ # iam_client = IAMCredentials::IAMCredentialsService.new
1904
+ #
1905
+ # # Get the environment configured authorization
1906
+ # scopes = ["https://www.googleapis.com/auth/iam"]
1907
+ # iam_client.authorization = Google::Auth.get_application_default scopes
1908
+ #
1909
+ # request = {
1910
+ # "payload": string_to_sign,
1911
+ # }
1912
+ # resource = "projects/-/serviceAccounts/#{issuer}"
1913
+ # response = iam_client.sign_service_account_blob resource, request, {}
1914
+ # response.signed_blob
1915
+ # end
1916
+ #
1917
+ # storage = Google::Cloud::Storage.new
1918
+ #
1919
+ # bucket = storage.bucket "my-todo-app"
1920
+ # 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
+ # )
1925
+ #
1926
+ # post.url #=> "https://storage.googleapis.com/my-todo-app/"
1927
+ # post.fields["key"] #=> "my-todo-app/avatars/heidi/400x400.png"
1928
+ # post.fields["policy"] #=> "ABC...XYZ"
1929
+ # post.fields["x-goog-algorithm"] #=> "GOOG4-RSA-SHA256"
1930
+ # post.fields["x-goog-credential"] #=> "cred@pid.iam.gserviceaccount.com/20200123/auto/storage/goog4_request"
1931
+ # post.fields["x-goog-date"] #=> "20200128T000000Z"
1932
+ # post.fields["x-goog-signature"] #=> "4893a0e...cd82"
1933
+ #
1934
+ def generate_signed_post_policy_v4 path,
1935
+ issuer: nil,
1936
+ client_email: nil,
1937
+ signing_key: nil,
1938
+ private_key: nil,
1939
+ signer: nil,
1940
+ expires: nil,
1941
+ fields: nil,
1942
+ conditions: nil,
1943
+ scheme: "https",
1944
+ virtual_hosted_style: nil,
1945
+ bucket_bound_hostname: nil
1946
+ ensure_service!
1947
+ sign = File::SignerV4.from_bucket self, path
1948
+ sign.post_object issuer: issuer,
1949
+ client_email: client_email,
1950
+ signing_key: signing_key,
1951
+ private_key: private_key,
1952
+ signer: signer,
1953
+ expires: expires,
1954
+ fields: fields,
1955
+ conditions: conditions,
1956
+ scheme: scheme,
1957
+ virtual_hosted_style: virtual_hosted_style,
1958
+ bucket_bound_hostname: bucket_bound_hostname
1645
1959
  end
1646
1960
 
1647
1961
  ##
@@ -2125,11 +2439,12 @@ module Google
2125
2439
  def create_notification topic, custom_attrs: nil, event_types: nil,
2126
2440
  prefix: nil, payload: nil
2127
2441
  ensure_service!
2128
- options = { custom_attrs: custom_attrs, event_types: event_types,
2129
- prefix: prefix, payload: payload,
2130
- user_project: user_project }
2131
2442
 
2132
- gapi = service.insert_notification name, topic, options
2443
+ gapi = service.insert_notification name, topic, custom_attrs: custom_attrs,
2444
+ event_types: event_types,
2445
+ prefix: prefix,
2446
+ payload: payload,
2447
+ user_project: user_project
2133
2448
  Notification.from_gapi name, gapi, service, user_project: user_project
2134
2449
  end
2135
2450
  alias new_notification create_notification
@@ -2215,7 +2530,7 @@ module Google
2215
2530
  patch_args = Hash[attributes.map do |attr|
2216
2531
  [attr, @gapi.send(attr)]
2217
2532
  end]
2218
- patch_gapi = API::Bucket.new patch_args
2533
+ patch_gapi = API::Bucket.new(**patch_args)
2219
2534
  @gapi = service.patch_bucket name, patch_gapi,
2220
2535
  user_project: user_project
2221
2536
  @lazy = nil