google-cloud-storage 1.26.0 → 1.29.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/AUTHENTICATION.md +8 -2
- data/CHANGELOG.md +54 -0
- data/TROUBLESHOOTING.md +2 -8
- data/lib/google-cloud-storage.rb +1 -0
- data/lib/google/cloud/storage.rb +2 -1
- data/lib/google/cloud/storage/bucket.rb +240 -59
- data/lib/google/cloud/storage/bucket/lifecycle.rb +160 -26
- data/lib/google/cloud/storage/errors.rb +7 -2
- data/lib/google/cloud/storage/file.rb +110 -31
- data/lib/google/cloud/storage/file/signer_v2.rb +21 -12
- data/lib/google/cloud/storage/file/signer_v4.rb +39 -20
- data/lib/google/cloud/storage/project.rb +84 -30
- data/lib/google/cloud/storage/service.rb +4 -3
- data/lib/google/cloud/storage/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe9e2b825a237558161e2fa35c196f56342b43ea1119c15b527fdd1b26445711
|
4
|
+
data.tar.gz: 2c76342e276c10250c9ddcbf14edfc143474ccf4b29e1d869bc3a8a639d4f608
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9ff8d6eb43731e588b0b32df5bb093dc042443543cc63d3e1f060bffd09d011180085254c849ef0393b27447550bb01690b129255e0c02a3e657e8e73e1bd4e
|
7
|
+
data.tar.gz: 991a423b8db899c16adeeb93d095ec9f3176a32cae5d78ab459c9b2bc7f07a52398f7387a7a89336dd2d86e9aeb1beb067853a2b474042b2740333bc6ff3daf7
|
data/AUTHENTICATION.md
CHANGED
@@ -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:**
|
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
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,59 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 1.29.0 / 2020-09-22
|
4
|
+
|
5
|
+
#### Features
|
6
|
+
|
7
|
+
* quota_project can be set via library configuration ([#7656](https://www.github.com/googleapis/google-cloud-ruby/issues/7656))
|
8
|
+
|
9
|
+
#### Bug Fixes
|
10
|
+
|
11
|
+
* Fix encoding of space characters in #signed_url version: :v4
|
12
|
+
* Fix encoding of space characters to use percent encoding (%20) instead of plus sign (+).
|
13
|
+
|
14
|
+
#### Documentation
|
15
|
+
|
16
|
+
* Add custom time to file metadata sample
|
17
|
+
|
18
|
+
### 1.28.0 / 2020-08-26
|
19
|
+
|
20
|
+
* Add Object Lifecycle Management fields
|
21
|
+
* Add custom_time_before to Lifecycle::Rule
|
22
|
+
* Add days_since_custom_time to Lifecycle::Rule
|
23
|
+
* Add days_since_noncurrent_time to Lifecycle::Rule
|
24
|
+
* Add noncurrent_time_before to Lifecycle::Rule
|
25
|
+
* Add File#custom_time and #custom_time=
|
26
|
+
|
27
|
+
### 1.27.0 / 2020-07-29
|
28
|
+
|
29
|
+
#### Features
|
30
|
+
|
31
|
+
* Add support for signing URLs with IAMCredentials SignBlob API
|
32
|
+
* Add signer parameter accepting Procs to the following methods:
|
33
|
+
* Project#signed_url
|
34
|
+
* Bucket#generate_signed_post_policy_v4
|
35
|
+
* Bucket#post_object
|
36
|
+
* Bucket#signed_url
|
37
|
+
* File#signed_url
|
38
|
+
* Update signer aliases signing_key and private_key to similarly support Procs
|
39
|
+
|
40
|
+
#### Documentation
|
41
|
+
|
42
|
+
* Update documentation of SignedUrlUnavailable
|
43
|
+
|
44
|
+
### 1.26.2 / 2020-05-28
|
45
|
+
|
46
|
+
#### Documentation
|
47
|
+
|
48
|
+
* Fix a few broken links
|
49
|
+
|
50
|
+
### 1.26.1 / 2020-05-06
|
51
|
+
|
52
|
+
#### Bug Fixes
|
53
|
+
|
54
|
+
* Add missing bucket condition in SignerV4#post_object
|
55
|
+
* Ensure bucket is not returned in PostObject fields
|
56
|
+
|
3
57
|
### 1.26.0 / 2020-04-06
|
4
58
|
|
5
59
|
#### Features
|
data/TROUBLESHOOTING.md
CHANGED
@@ -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/
|
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
|
-
[
|
31
|
+
[gh-ruby]: https://github.com/googleapis/google-cloud-ruby/issues/new
|
data/lib/google-cloud-storage.rb
CHANGED
@@ -136,6 +136,7 @@ Google::Cloud.configure.add_config! :storage do |config|
|
|
136
136
|
allow_nil: true
|
137
137
|
config.add_alias! :keyfile, :credentials
|
138
138
|
config.add_field! :scope, nil, match: [String, Array]
|
139
|
+
config.add_field! :quota_project, nil, match: String
|
139
140
|
config.add_field! :retries, nil, match: Integer
|
140
141
|
config.add_field! :timeout, nil, match: Integer
|
141
142
|
# TODO: Remove once discovery document is updated.
|
data/lib/google/cloud/storage.rb
CHANGED
@@ -93,7 +93,8 @@ module Google
|
|
93
93
|
Storage::Project.new(
|
94
94
|
Storage::Service.new(
|
95
95
|
project_id, credentials,
|
96
|
-
retries: retries, timeout: timeout, host: endpoint
|
96
|
+
retries: retries, timeout: timeout, host: endpoint,
|
97
|
+
quota_project: configure.quota_project
|
97
98
|
)
|
98
99
|
)
|
99
100
|
end
|
@@ -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,7 +1254,7 @@ 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
|
@@ -1264,6 +1269,7 @@ module Google
|
|
1264
1269
|
md5: md5,
|
1265
1270
|
cache_control: cache_control,
|
1266
1271
|
content_type: content_type,
|
1272
|
+
custom_time: custom_time,
|
1267
1273
|
content_disposition: content_disposition,
|
1268
1274
|
crc32c: crc32c,
|
1269
1275
|
content_encoding: content_encoding,
|
@@ -1406,7 +1412,7 @@ module Google
|
|
1406
1412
|
# A {SignedUrlUnavailable} is raised if the service account credentials
|
1407
1413
|
# are missing. Service account credentials are acquired by following the
|
1408
1414
|
# steps in [Service Account Authentication](
|
1409
|
-
# https://cloud.google.com/
|
1415
|
+
# https://cloud.google.com/iam/docs/service-accounts).
|
1410
1416
|
#
|
1411
1417
|
# @see https://cloud.google.com/storage/docs/access-control/signed-urls
|
1412
1418
|
# Signed URLs guide
|
@@ -1433,10 +1439,22 @@ module Google
|
|
1433
1439
|
# use the signed URL.
|
1434
1440
|
# @param [String] issuer Service Account's Client Email.
|
1435
1441
|
# @param [String] client_email Service Account's Client Email.
|
1436
|
-
# @param [OpenSSL::PKey::RSA, String] signing_key Service Account's
|
1437
|
-
# Private Key
|
1438
|
-
#
|
1439
|
-
#
|
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.
|
1440
1458
|
# @param [Hash] query Query string parameters to include in the signed
|
1441
1459
|
# URL. The given parameters are not verified by the signature.
|
1442
1460
|
#
|
@@ -1462,7 +1480,12 @@ module Google
|
|
1462
1480
|
# to create. Must be one of `:v2` or `:v4`. The default value is
|
1463
1481
|
# `:v2`.
|
1464
1482
|
#
|
1465
|
-
# @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).
|
1466
1489
|
#
|
1467
1490
|
# @example
|
1468
1491
|
# require "google/cloud/storage"
|
@@ -1493,6 +1516,40 @@ module Google
|
|
1493
1516
|
# issuer: "service-account@gcloud.com",
|
1494
1517
|
# signing_key: key
|
1495
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
|
1496
1553
|
# @example Using the `headers` option:
|
1497
1554
|
# require "google/cloud/storage"
|
1498
1555
|
#
|
@@ -1538,6 +1595,7 @@ module Google
|
|
1538
1595
|
client_email: nil,
|
1539
1596
|
signing_key: nil,
|
1540
1597
|
private_key: nil,
|
1598
|
+
signer: nil,
|
1541
1599
|
query: nil,
|
1542
1600
|
scheme: "HTTPS",
|
1543
1601
|
virtual_hosted_style: nil,
|
@@ -1547,30 +1605,32 @@ module Google
|
|
1547
1605
|
version ||= :v2
|
1548
1606
|
case version.to_sym
|
1549
1607
|
when :v2
|
1550
|
-
|
1551
|
-
|
1552
|
-
|
1553
|
-
|
1554
|
-
|
1555
|
-
|
1556
|
-
|
1557
|
-
|
1558
|
-
|
1559
|
-
|
1560
|
-
|
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
|
1561
1620
|
when :v4
|
1562
|
-
|
1563
|
-
|
1564
|
-
|
1565
|
-
|
1566
|
-
|
1567
|
-
|
1568
|
-
|
1569
|
-
|
1570
|
-
|
1571
|
-
|
1572
|
-
|
1573
|
-
|
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
|
1574
1634
|
else
|
1575
1635
|
raise ArgumentError, "version '#{version}' not supported"
|
1576
1636
|
end
|
@@ -1591,7 +1651,7 @@ module Google
|
|
1591
1651
|
# A {SignedUrlUnavailable} is raised if the service account credentials
|
1592
1652
|
# are missing. Service account credentials are acquired by following the
|
1593
1653
|
# steps in [Service Account Authentication](
|
1594
|
-
# https://cloud.google.com/
|
1654
|
+
# https://cloud.google.com/iam/docs/service-accounts).
|
1595
1655
|
#
|
1596
1656
|
# @see https://cloud.google.com/storage/docs/xml-api/post-object
|
1597
1657
|
#
|
@@ -1608,12 +1668,28 @@ module Google
|
|
1608
1668
|
# for more information.
|
1609
1669
|
# @param [String] issuer Service Account's Client Email.
|
1610
1670
|
# @param [String] client_email Service Account's Client Email.
|
1611
|
-
# @param [OpenSSL::PKey::RSA, String] signing_key Service Account's
|
1612
|
-
# Private Key
|
1613
|
-
#
|
1614
|
-
#
|
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.
|
1615
1688
|
#
|
1616
|
-
# @
|
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).
|
1617
1693
|
#
|
1618
1694
|
# @example
|
1619
1695
|
# require "google/cloud/storage"
|
@@ -1673,19 +1749,61 @@ module Google
|
|
1673
1749
|
# post.fields[:signature] #=> "ABC...XYZ="
|
1674
1750
|
# post.fields[:policy] #=> "ABC...XYZ="
|
1675
1751
|
#
|
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
|
+
#
|
1676
1792
|
def post_object path,
|
1677
1793
|
policy: nil,
|
1678
1794
|
issuer: nil,
|
1679
1795
|
client_email: nil,
|
1680
1796
|
signing_key: nil,
|
1681
|
-
private_key: nil
|
1797
|
+
private_key: nil,
|
1798
|
+
signer: nil
|
1682
1799
|
ensure_service!
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
|
1687
|
-
|
1688
|
-
|
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
|
1689
1807
|
end
|
1690
1808
|
|
1691
1809
|
##
|
@@ -1703,17 +1821,29 @@ module Google
|
|
1703
1821
|
# A {SignedUrlUnavailable} is raised if the service account credentials
|
1704
1822
|
# are missing. Service account credentials are acquired by following the
|
1705
1823
|
# steps in [Service Account Authentication](
|
1706
|
-
# https://cloud.google.com/
|
1824
|
+
# https://cloud.google.com/iam/docs/service-accounts).
|
1707
1825
|
#
|
1708
1826
|
# @see https://cloud.google.com/storage/docs/xml-api/post-object
|
1709
1827
|
#
|
1710
1828
|
# @param [String] path Path to the file in Google Cloud Storage.
|
1711
1829
|
# @param [String] issuer Service Account's Client Email.
|
1712
1830
|
# @param [String] client_email Service Account's Client Email.
|
1713
|
-
# @param [OpenSSL::PKey::RSA, String] signing_key Service Account's
|
1714
|
-
# Private Key
|
1715
|
-
#
|
1716
|
-
#
|
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.
|
1717
1847
|
# @param [Integer] expires The number of seconds until the URL expires.
|
1718
1848
|
# The default is 604800 (7 days).
|
1719
1849
|
# @param [Hash] fields User-supplied form fields such as `acl`,
|
@@ -1733,6 +1863,11 @@ module Google
|
|
1733
1863
|
#
|
1734
1864
|
# @return [PostObject] An object containing the URL, fields, and values needed to upload files via html forms.
|
1735
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
|
+
#
|
1736
1871
|
# @example
|
1737
1872
|
# require "google/cloud/storage"
|
1738
1873
|
#
|
@@ -1752,11 +1887,56 @@ module Google
|
|
1752
1887
|
# post.fields["x-goog-date"] #=> "20200128T000000Z"
|
1753
1888
|
# post.fields["x-goog-signature"] #=> "4893a0e...cd82"
|
1754
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
|
+
#
|
1755
1934
|
def generate_signed_post_policy_v4 path,
|
1756
1935
|
issuer: nil,
|
1757
1936
|
client_email: nil,
|
1758
1937
|
signing_key: nil,
|
1759
1938
|
private_key: nil,
|
1939
|
+
signer: nil,
|
1760
1940
|
expires: nil,
|
1761
1941
|
fields: nil,
|
1762
1942
|
conditions: nil,
|
@@ -1764,17 +1944,18 @@ module Google
|
|
1764
1944
|
virtual_hosted_style: nil,
|
1765
1945
|
bucket_bound_hostname: nil
|
1766
1946
|
ensure_service!
|
1767
|
-
|
1768
|
-
|
1769
|
-
|
1770
|
-
|
1771
|
-
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1775
|
-
|
1776
|
-
|
1777
|
-
|
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
|
1778
1959
|
end
|
1779
1960
|
|
1780
1961
|
##
|