google-cloud-storage 1.25.0 → 1.27.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 +4 -4
- data/AUTHENTICATION.md +8 -2
- data/CHANGELOG.md +53 -0
- data/TROUBLESHOOTING.md +2 -8
- data/lib/google/cloud/storage/bucket.rb +379 -70
- data/lib/google/cloud/storage/bucket/lifecycle.rb +5 -5
- data/lib/google/cloud/storage/convert.rb +4 -3
- data/lib/google/cloud/storage/errors.rb +7 -2
- data/lib/google/cloud/storage/file.rb +115 -27
- data/lib/google/cloud/storage/file/list.rb +7 -5
- data/lib/google/cloud/storage/file/signer_v2.rb +21 -12
- data/lib/google/cloud/storage/file/signer_v4.rb +245 -60
- data/lib/google/cloud/storage/policy/binding.rb +3 -2
- data/lib/google/cloud/storage/post_object.rb +18 -1
- data/lib/google/cloud/storage/project.rb +118 -28
- data/lib/google/cloud/storage/service.rb +10 -13
- 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: c1c5fde2ed35606723e05c787ff96fd6ec31d7e06015e09bcac8dc0bc4b9ae05
|
|
4
|
+
data.tar.gz: bf1391389ff711934df5302f65cdf6136bad14b0a00865728da8fe3b549b3cbe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1e7d9a97562357737322928a56f093ed42bc8f8015a06723c5e403c402367a89f56604eeefb2bbbf289a7dce5b84ee055f76f3d6ef6df6d987f7f05ed5eed5fe
|
|
7
|
+
data.tar.gz: 67046c8397a7e7fabf7b0a4d4e6501417ba815b55267e641a0ab51cdb233641e699348629a021763724aaca623e25a901395d77453b78fbc90ae67d4efca17b1
|
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,58 @@
|
|
|
1
1
|
# Release History
|
|
2
2
|
|
|
3
|
+
### 1.27.0 / 2020-07-29
|
|
4
|
+
|
|
5
|
+
#### Features
|
|
6
|
+
|
|
7
|
+
* Add support for signing URLs with IAMCredentials SignBlob API
|
|
8
|
+
* Add signer parameter accepting Procs to the following methods:
|
|
9
|
+
* Project#signed_url
|
|
10
|
+
* Bucket#generate_signed_post_policy_v4
|
|
11
|
+
* Bucket#post_object
|
|
12
|
+
* Bucket#signed_url
|
|
13
|
+
* File#signed_url
|
|
14
|
+
* Update signer aliases signing_key and private_key to similarly support Procs
|
|
15
|
+
|
|
16
|
+
#### Documentation
|
|
17
|
+
|
|
18
|
+
* Update documentation of SignedUrlUnavailable
|
|
19
|
+
|
|
20
|
+
### 1.26.2 / 2020-05-28
|
|
21
|
+
|
|
22
|
+
#### Documentation
|
|
23
|
+
|
|
24
|
+
* Fix a few broken links
|
|
25
|
+
|
|
26
|
+
### 1.26.1 / 2020-05-06
|
|
27
|
+
|
|
28
|
+
#### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* Add missing bucket condition in SignerV4#post_object
|
|
31
|
+
* Ensure bucket is not returned in PostObject fields
|
|
32
|
+
|
|
33
|
+
### 1.26.0 / 2020-04-06
|
|
34
|
+
|
|
35
|
+
#### Features
|
|
36
|
+
|
|
37
|
+
* Update V4 Signature support in Project#signed_url, Bucket#signed_url and File#signed_url
|
|
38
|
+
* Add scheme, virtual_hosted_style and bucket_bound_hostname to #signed_url methods
|
|
39
|
+
* Add support for V4 query param encoding and ordering
|
|
40
|
+
* Convert tabs in V4 to single whitespace character
|
|
41
|
+
* Set payload in V4 to X-Goog-Content-SHA256 if present
|
|
42
|
+
* Fix method param default value GET for #signed_url
|
|
43
|
+
* Add support for V4 Signature POST Policies
|
|
44
|
+
* Add Bucket#generate_signed_post_policy_v4
|
|
45
|
+
|
|
46
|
+
#### Bug Fixes
|
|
47
|
+
|
|
48
|
+
* Address keyword argument warnings in Ruby 2.7 and later
|
|
49
|
+
|
|
50
|
+
### 1.25.1 / 2020-01-06
|
|
51
|
+
|
|
52
|
+
#### Documentation
|
|
53
|
+
|
|
54
|
+
* Add ARCHIVE storage class
|
|
55
|
+
|
|
3
56
|
### 1.25.0 / 2019-12-12
|
|
4
57
|
|
|
5
58
|
#### 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
|
|
@@ -357,7 +357,7 @@ module Google
|
|
|
357
357
|
##
|
|
358
358
|
# The bucket's storage class. This defines how objects in the bucket are
|
|
359
359
|
# stored and determines the SLA and the cost of storage. Values include
|
|
360
|
-
# `STANDARD`, `NEARLINE`, and `
|
|
360
|
+
# `STANDARD`, `NEARLINE`, `COLDLINE`, and `ARCHIVE`. `REGIONAL`,`MULTI_REGIONAL`,
|
|
361
361
|
# and `DURABLE_REDUCED_AVAILABILITY` are supported as legacy storage
|
|
362
362
|
# classes.
|
|
363
363
|
#
|
|
@@ -370,11 +370,11 @@ module Google
|
|
|
370
370
|
##
|
|
371
371
|
# Updates the bucket's storage class. This defines how objects in the
|
|
372
372
|
# bucket are stored and determines the SLA and the cost of storage.
|
|
373
|
-
# Accepted values include `:standard`, `:nearline`,
|
|
374
|
-
# well as the equivalent strings returned by
|
|
375
|
-
# `:multi_regional`, `:regional`, and
|
|
376
|
-
# are accepted as legacy storage classes.
|
|
377
|
-
# [Storage
|
|
373
|
+
# Accepted values include `:standard`, `:nearline`, `:coldline`, and
|
|
374
|
+
# `:archive`, as well as the equivalent strings returned by
|
|
375
|
+
# {Bucket#storage_class}. `:multi_regional`, `:regional`, and
|
|
376
|
+
# `durable_reduced_availability` are accepted as legacy storage classes.
|
|
377
|
+
# For more information, see [Storage
|
|
378
378
|
# Classes](https://cloud.google.com/storage/docs/storage-classes).
|
|
379
379
|
#
|
|
380
380
|
# @param [Symbol, String] new_storage_class Storage class of the bucket.
|
|
@@ -1146,8 +1146,8 @@ module Google
|
|
|
1146
1146
|
# @param [Symbol, String] storage_class Storage class of the file.
|
|
1147
1147
|
# Determines how the file is stored and determines the SLA and the
|
|
1148
1148
|
# cost of storage. Accepted values include `:standard`, `:nearline`,
|
|
1149
|
-
# and `:
|
|
1150
|
-
# {#storage_class}. `:multi_regional`, `:regional`, and
|
|
1149
|
+
# `:coldline`, and `:archive`, as well as the equivalent strings
|
|
1150
|
+
# returned by {#storage_class}. `:multi_regional`, `:regional`, and
|
|
1151
1151
|
# `durable_reduced_availability` are accepted legacy storage classes.
|
|
1152
1152
|
# For more information, see [Storage
|
|
1153
1153
|
# Classes](https://cloud.google.com/storage/docs/storage-classes)
|
|
@@ -1254,22 +1254,27 @@ module Google
|
|
|
1254
1254
|
storage_class: nil, encryption_key: nil, kms_key: nil,
|
|
1255
1255
|
temporary_hold: nil, event_based_hold: nil
|
|
1256
1256
|
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
1257
|
ensure_io_or_file_exists! file
|
|
1268
1258
|
path ||= file.path if file.respond_to? :path
|
|
1269
1259
|
path ||= file if file.is_a? String
|
|
1270
1260
|
raise ArgumentError, "must provide path" if path.nil?
|
|
1271
1261
|
|
|
1272
|
-
|
|
1262
|
+
|
|
1263
|
+
gapi = service.insert_file name, file, path, acl: File::Acl.predefined_rule_for(acl),
|
|
1264
|
+
md5: md5,
|
|
1265
|
+
cache_control: cache_control,
|
|
1266
|
+
content_type: content_type,
|
|
1267
|
+
content_disposition: content_disposition,
|
|
1268
|
+
crc32c: crc32c,
|
|
1269
|
+
content_encoding: content_encoding,
|
|
1270
|
+
metadata: metadata,
|
|
1271
|
+
content_language: content_language,
|
|
1272
|
+
key: encryption_key,
|
|
1273
|
+
kms_key: kms_key,
|
|
1274
|
+
storage_class: storage_class_for(storage_class),
|
|
1275
|
+
temporary_hold: temporary_hold,
|
|
1276
|
+
event_based_hold: event_based_hold,
|
|
1277
|
+
user_project: user_project
|
|
1273
1278
|
File.from_gapi gapi, service, user_project: user_project
|
|
1274
1279
|
end
|
|
1275
1280
|
alias upload_file create_file
|
|
@@ -1368,9 +1373,6 @@ module Google
|
|
|
1368
1373
|
raise ArgumentError, "must provide at least two source files"
|
|
1369
1374
|
end
|
|
1370
1375
|
|
|
1371
|
-
options = { acl: File::Acl.predefined_rule_for(acl),
|
|
1372
|
-
key: encryption_key,
|
|
1373
|
-
user_project: user_project }
|
|
1374
1376
|
destination_gapi = nil
|
|
1375
1377
|
if block_given?
|
|
1376
1378
|
destination_gapi = API::Object.new
|
|
@@ -1378,8 +1380,11 @@ module Google
|
|
|
1378
1380
|
yield updater
|
|
1379
1381
|
updater.check_for_changed_metadata!
|
|
1380
1382
|
end
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
+
|
|
1384
|
+
acl_rule = File::Acl.predefined_rule_for acl
|
|
1385
|
+
gapi = service.compose_file name, sources, destination, destination_gapi, acl: acl_rule,
|
|
1386
|
+
key: encryption_key,
|
|
1387
|
+
user_project: user_project
|
|
1383
1388
|
File.from_gapi gapi, service, user_project: user_project
|
|
1384
1389
|
end
|
|
1385
1390
|
alias compose_file compose
|
|
@@ -1401,7 +1406,7 @@ module Google
|
|
|
1401
1406
|
# A {SignedUrlUnavailable} is raised if the service account credentials
|
|
1402
1407
|
# are missing. Service account credentials are acquired by following the
|
|
1403
1408
|
# steps in [Service Account Authentication](
|
|
1404
|
-
# https://cloud.google.com/
|
|
1409
|
+
# https://cloud.google.com/iam/docs/service-accounts).
|
|
1405
1410
|
#
|
|
1406
1411
|
# @see https://cloud.google.com/storage/docs/access-control/signed-urls
|
|
1407
1412
|
# Signed URLs guide
|
|
@@ -1428,10 +1433,22 @@ module Google
|
|
|
1428
1433
|
# use the signed URL.
|
|
1429
1434
|
# @param [String] issuer Service Account's Client Email.
|
|
1430
1435
|
# @param [String] client_email Service Account's Client Email.
|
|
1431
|
-
# @param [OpenSSL::PKey::RSA, String] signing_key Service Account's
|
|
1432
|
-
# Private Key
|
|
1433
|
-
#
|
|
1434
|
-
#
|
|
1436
|
+
# @param [OpenSSL::PKey::RSA, String, Proc] signing_key Service Account's
|
|
1437
|
+
# Private Key or a Proc that accepts a single String parameter and returns a
|
|
1438
|
+
# RSA SHA256 signature using a valid Google Service Account Private Key.
|
|
1439
|
+
# @param [OpenSSL::PKey::RSA, String, Proc] private_key Service Account's
|
|
1440
|
+
# Private Key or a Proc that accepts a single String parameter and returns a
|
|
1441
|
+
# RSA SHA256 signature using a valid Google Service Account Private Key.
|
|
1442
|
+
# @param [OpenSSL::PKey::RSA, String, Proc] signer 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
|
+
#
|
|
1446
|
+
# When using this method in environments such as GAE Flexible Environment,
|
|
1447
|
+
# GKE, or Cloud Functions where the private key is unavailable, it may be
|
|
1448
|
+
# necessary to provide a Proc (or lambda) via the signer parameter. This
|
|
1449
|
+
# Proc should return a signature created using a RPC call to the
|
|
1450
|
+
# [Service Account Credentials signBlob](https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signBlob)
|
|
1451
|
+
# method as shown in the example below.
|
|
1435
1452
|
# @param [Hash] query Query string parameters to include in the signed
|
|
1436
1453
|
# URL. The given parameters are not verified by the signature.
|
|
1437
1454
|
#
|
|
@@ -1440,11 +1457,29 @@ module Google
|
|
|
1440
1457
|
# using the URL, but only when the file resource is missing the
|
|
1441
1458
|
# corresponding values. (These values can be permanently set using
|
|
1442
1459
|
# {File#content_disposition=} and {File#content_type=}.)
|
|
1460
|
+
# @param [String] scheme The URL scheme. The default value is `HTTPS`.
|
|
1461
|
+
# @param [Boolean] virtual_hosted_style Whether to use a virtual hosted-style
|
|
1462
|
+
# hostname, which adds the bucket into the host portion of the URI rather
|
|
1463
|
+
# than the path, e.g. `https://mybucket.storage.googleapis.com/...`.
|
|
1464
|
+
# For V4 signing, this also sets the `host` header in the canonicalized
|
|
1465
|
+
# extension headers to the virtual hosted-style host, unless that header is
|
|
1466
|
+
# supplied via the `headers` param. The default value of `false` uses the
|
|
1467
|
+
# form of `https://storage.googleapis.com/mybucket`.
|
|
1468
|
+
# @param [String] bucket_bound_hostname Use a bucket-bound hostname, which
|
|
1469
|
+
# replaces the `storage.googleapis.com` host with the name of a `CNAME`
|
|
1470
|
+
# bucket, e.g. a bucket named `gcs-subdomain.my.domain.tld`, or a Google
|
|
1471
|
+
# Cloud Load Balancer which routes to a bucket you own, e.g.
|
|
1472
|
+
# `my-load-balancer-domain.tld`.
|
|
1443
1473
|
# @param [Symbol, String] version The version of the signed credential
|
|
1444
1474
|
# to create. Must be one of `:v2` or `:v4`. The default value is
|
|
1445
1475
|
# `:v2`.
|
|
1446
1476
|
#
|
|
1447
|
-
# @return [String]
|
|
1477
|
+
# @return [String] The signed URL.
|
|
1478
|
+
#
|
|
1479
|
+
# @raise [SignedUrlUnavailable] If the service account credentials
|
|
1480
|
+
# are missing. Service account credentials are acquired by following the
|
|
1481
|
+
# steps in [Service Account Authentication](
|
|
1482
|
+
# https://cloud.google.com/iam/docs/service-accounts).
|
|
1448
1483
|
#
|
|
1449
1484
|
# @example
|
|
1450
1485
|
# require "google/cloud/storage"
|
|
@@ -1475,6 +1510,40 @@ module Google
|
|
|
1475
1510
|
# issuer: "service-account@gcloud.com",
|
|
1476
1511
|
# signing_key: key
|
|
1477
1512
|
#
|
|
1513
|
+
# @example Using Cloud IAMCredentials signBlob to create the signature:
|
|
1514
|
+
# require "google/cloud/storage"
|
|
1515
|
+
# require "google/apis/iamcredentials_v1"
|
|
1516
|
+
# require "googleauth"
|
|
1517
|
+
#
|
|
1518
|
+
# # Issuer is the service account email that the Signed URL will be signed with
|
|
1519
|
+
# # and any permission granted in the Signed URL must be granted to the
|
|
1520
|
+
# # Google Service Account.
|
|
1521
|
+
# issuer = "service-account@project-id.iam.gserviceaccount.com"
|
|
1522
|
+
#
|
|
1523
|
+
# # Create a lambda that accepts the string_to_sign
|
|
1524
|
+
# signer = lambda do |string_to_sign|
|
|
1525
|
+
# IAMCredentials = Google::Apis::IamcredentialsV1
|
|
1526
|
+
# iam_client = IAMCredentials::IAMCredentialsService.new
|
|
1527
|
+
#
|
|
1528
|
+
# # Get the environment configured authorization
|
|
1529
|
+
# scopes = ["https://www.googleapis.com/auth/iam"]
|
|
1530
|
+
# iam_client.authorization = Google::Auth.get_application_default scopes
|
|
1531
|
+
#
|
|
1532
|
+
# request = {
|
|
1533
|
+
# "payload": string_to_sign,
|
|
1534
|
+
# }
|
|
1535
|
+
# resource = "projects/-/serviceAccounts/#{issuer}"
|
|
1536
|
+
# response = iam_client.sign_service_account_blob resource, request, {}
|
|
1537
|
+
# response.signed_blob
|
|
1538
|
+
# end
|
|
1539
|
+
#
|
|
1540
|
+
# storage = Google::Cloud::Storage.new
|
|
1541
|
+
#
|
|
1542
|
+
# bucket_name = "my-todo-app"
|
|
1543
|
+
# file_path = "avatars/heidi/400x400.png"
|
|
1544
|
+
# url = storage.signed_url bucket_name, file_path,
|
|
1545
|
+
# method: "GET", issuer: issuer,
|
|
1546
|
+
# signer: signer
|
|
1478
1547
|
# @example Using the `headers` option:
|
|
1479
1548
|
# require "google/cloud/storage"
|
|
1480
1549
|
#
|
|
@@ -1510,28 +1579,52 @@ module Google
|
|
|
1510
1579
|
# bucket = storage.bucket "my-todo-app"
|
|
1511
1580
|
# list_files_url = bucket.signed_url version: :v4
|
|
1512
1581
|
#
|
|
1513
|
-
def signed_url path = nil,
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1582
|
+
def signed_url path = nil,
|
|
1583
|
+
method: "GET",
|
|
1584
|
+
expires: nil,
|
|
1585
|
+
content_type: nil,
|
|
1586
|
+
content_md5: nil,
|
|
1587
|
+
headers: nil,
|
|
1588
|
+
issuer: nil,
|
|
1589
|
+
client_email: nil,
|
|
1590
|
+
signing_key: nil,
|
|
1591
|
+
private_key: nil,
|
|
1592
|
+
signer: nil,
|
|
1593
|
+
query: nil,
|
|
1594
|
+
scheme: "HTTPS",
|
|
1595
|
+
virtual_hosted_style: nil,
|
|
1596
|
+
bucket_bound_hostname: nil,
|
|
1597
|
+
version: nil
|
|
1517
1598
|
ensure_service!
|
|
1518
1599
|
version ||= :v2
|
|
1519
1600
|
case version.to_sym
|
|
1520
1601
|
when :v2
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1602
|
+
sign = File::SignerV2.from_bucket self, path
|
|
1603
|
+
sign.signed_url method: method,
|
|
1604
|
+
expires: expires,
|
|
1605
|
+
headers: headers,
|
|
1606
|
+
content_type: content_type,
|
|
1607
|
+
content_md5: content_md5,
|
|
1608
|
+
issuer: issuer,
|
|
1609
|
+
client_email: client_email,
|
|
1610
|
+
signing_key: signing_key,
|
|
1611
|
+
private_key: private_key,
|
|
1612
|
+
signer: signer,
|
|
1613
|
+
query: query
|
|
1528
1614
|
when :v4
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1615
|
+
sign = File::SignerV4.from_bucket self, path
|
|
1616
|
+
sign.signed_url method: method,
|
|
1617
|
+
expires: expires,
|
|
1618
|
+
headers: headers,
|
|
1619
|
+
issuer: issuer,
|
|
1620
|
+
client_email: client_email,
|
|
1621
|
+
signing_key: signing_key,
|
|
1622
|
+
private_key: private_key,
|
|
1623
|
+
signer: signer,
|
|
1624
|
+
query: query,
|
|
1625
|
+
scheme: scheme,
|
|
1626
|
+
virtual_hosted_style: virtual_hosted_style,
|
|
1627
|
+
bucket_bound_hostname: bucket_bound_hostname
|
|
1535
1628
|
else
|
|
1536
1629
|
raise ArgumentError, "version '#{version}' not supported"
|
|
1537
1630
|
end
|
|
@@ -1552,28 +1645,45 @@ module Google
|
|
|
1552
1645
|
# A {SignedUrlUnavailable} is raised if the service account credentials
|
|
1553
1646
|
# are missing. Service account credentials are acquired by following the
|
|
1554
1647
|
# steps in [Service Account Authentication](
|
|
1555
|
-
# https://cloud.google.com/
|
|
1648
|
+
# https://cloud.google.com/iam/docs/service-accounts).
|
|
1556
1649
|
#
|
|
1557
1650
|
# @see https://cloud.google.com/storage/docs/xml-api/post-object
|
|
1558
1651
|
#
|
|
1559
1652
|
# @param [String] path Path to the file in Google Cloud Storage.
|
|
1560
1653
|
# @param [Hash] policy The security policy that describes what
|
|
1561
|
-
# can and cannot be uploaded in the form. When provided,
|
|
1562
|
-
#
|
|
1563
|
-
#
|
|
1654
|
+
# can and cannot be uploaded in the form. When provided, the PostObject
|
|
1655
|
+
# fields will include a signature based on the JSON representation of
|
|
1656
|
+
# this hash and the same policy in Base64 format.
|
|
1657
|
+
#
|
|
1564
1658
|
# If you do not provide a security policy, requests are considered
|
|
1565
1659
|
# to be anonymous and will only work with buckets that have granted
|
|
1566
|
-
# WRITE or FULL_CONTROL permission to anonymous users.
|
|
1660
|
+
# `WRITE` or `FULL_CONTROL` permission to anonymous users.
|
|
1567
1661
|
# See [Policy Document](https://cloud.google.com/storage/docs/xml-api/post-object#policydocument)
|
|
1568
1662
|
# for more information.
|
|
1569
1663
|
# @param [String] issuer Service Account's Client Email.
|
|
1570
1664
|
# @param [String] client_email Service Account's Client Email.
|
|
1571
|
-
# @param [OpenSSL::PKey::RSA, String] signing_key Service Account's
|
|
1572
|
-
# Private Key
|
|
1573
|
-
#
|
|
1574
|
-
#
|
|
1575
|
-
#
|
|
1576
|
-
#
|
|
1665
|
+
# @param [OpenSSL::PKey::RSA, String, Proc] signing_key Service Account's
|
|
1666
|
+
# Private Key or a Proc that accepts a single String parameter and returns a
|
|
1667
|
+
# RSA SHA256 signature using a valid Google Service Account Private Key.
|
|
1668
|
+
# @param [OpenSSL::PKey::RSA, String, Proc] private_key Service Account's
|
|
1669
|
+
# Private Key or a Proc that accepts a single String parameter and returns a
|
|
1670
|
+
# RSA SHA256 signature using a valid Google Service Account Private Key.
|
|
1671
|
+
# @param [OpenSSL::PKey::RSA, String, Proc] signer 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
|
+
#
|
|
1675
|
+
# When using this method in environments such as GAE Flexible Environment,
|
|
1676
|
+
# GKE, or Cloud Functions where the private key is unavailable, it may be
|
|
1677
|
+
# necessary to provide a Proc (or lambda) via the signer parameter. This
|
|
1678
|
+
# Proc should return a signature created using a RPC call to the
|
|
1679
|
+
# [Service Account Credentials signBlob](https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signBlob)
|
|
1680
|
+
# method as shown in the example below.
|
|
1681
|
+
# @return [PostObject] An object containing the URL, fields, and values needed to upload files via html forms.
|
|
1682
|
+
#
|
|
1683
|
+
# @raise [SignedUrlUnavailable] If the service account credentials
|
|
1684
|
+
# are missing. Service account credentials are acquired by following the
|
|
1685
|
+
# steps in [Service Account Authentication](
|
|
1686
|
+
# https://cloud.google.com/iam/docs/service-accounts).
|
|
1577
1687
|
#
|
|
1578
1688
|
# @example
|
|
1579
1689
|
# require "google/cloud/storage"
|
|
@@ -1633,15 +1743,213 @@ module Google
|
|
|
1633
1743
|
# post.fields[:signature] #=> "ABC...XYZ="
|
|
1634
1744
|
# post.fields[:policy] #=> "ABC...XYZ="
|
|
1635
1745
|
#
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1746
|
+
# @example Using Cloud IAMCredentials signBlob to create the signature:
|
|
1747
|
+
# require "google/cloud/storage"
|
|
1748
|
+
# require "google/apis/iamcredentials_v1"
|
|
1749
|
+
# require "googleauth"
|
|
1750
|
+
#
|
|
1751
|
+
# # Issuer is the service account email that the Signed URL will be signed with
|
|
1752
|
+
# # and any permission granted in the Signed URL must be granted to the
|
|
1753
|
+
# # Google Service Account.
|
|
1754
|
+
# issuer = "service-account@project-id.iam.gserviceaccount.com"
|
|
1755
|
+
#
|
|
1756
|
+
# # Create a lambda that accepts the string_to_sign
|
|
1757
|
+
# signer = lambda do |string_to_sign|
|
|
1758
|
+
# IAMCredentials = Google::Apis::IamcredentialsV1
|
|
1759
|
+
# iam_client = IAMCredentials::IAMCredentialsService.new
|
|
1760
|
+
#
|
|
1761
|
+
# # Get the environment configured authorization
|
|
1762
|
+
# scopes = ["https://www.googleapis.com/auth/iam"]
|
|
1763
|
+
# iam_client.authorization = Google::Auth.get_application_default scopes
|
|
1764
|
+
#
|
|
1765
|
+
# request = {
|
|
1766
|
+
# "payload": string_to_sign,
|
|
1767
|
+
# }
|
|
1768
|
+
# resource = "projects/-/serviceAccounts/#{issuer}"
|
|
1769
|
+
# response = iam_client.sign_service_account_blob resource, request, {}
|
|
1770
|
+
# response.signed_blob
|
|
1771
|
+
# end
|
|
1772
|
+
#
|
|
1773
|
+
# storage = Google::Cloud::Storage.new
|
|
1774
|
+
#
|
|
1775
|
+
# bucket = storage.bucket "my-todo-app"
|
|
1776
|
+
# post = bucket.post_object "avatars/heidi/400x400.png",
|
|
1777
|
+
# issuer: issuer,
|
|
1778
|
+
# signer: signer
|
|
1779
|
+
#
|
|
1780
|
+
# post.url #=> "https://storage.googleapis.com"
|
|
1781
|
+
# post.fields[:key] #=> "my-todo-app/avatars/heidi/400x400.png"
|
|
1782
|
+
# post.fields[:GoogleAccessId] #=> "0123456789@gserviceaccount.com"
|
|
1783
|
+
# post.fields[:signature] #=> "ABC...XYZ="
|
|
1784
|
+
# post.fields[:policy] #=> "ABC...XYZ="
|
|
1785
|
+
#
|
|
1786
|
+
def post_object path,
|
|
1787
|
+
policy: nil,
|
|
1788
|
+
issuer: nil,
|
|
1789
|
+
client_email: nil,
|
|
1790
|
+
signing_key: nil,
|
|
1791
|
+
private_key: nil,
|
|
1792
|
+
signer: nil
|
|
1639
1793
|
ensure_service!
|
|
1794
|
+
sign = File::SignerV2.from_bucket self, path
|
|
1795
|
+
sign.post_object issuer: issuer,
|
|
1796
|
+
client_email: client_email,
|
|
1797
|
+
signing_key: signing_key,
|
|
1798
|
+
private_key: private_key,
|
|
1799
|
+
signer: signer,
|
|
1800
|
+
policy: policy
|
|
1801
|
+
end
|
|
1640
1802
|
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1803
|
+
##
|
|
1804
|
+
# Generate a PostObject that includes the fields and url to
|
|
1805
|
+
# upload objects via html forms.
|
|
1806
|
+
#
|
|
1807
|
+
# Generating a PostObject requires service account credentials,
|
|
1808
|
+
# either by connecting with a service account when calling
|
|
1809
|
+
# {Google::Cloud.storage}, or by passing in the service account
|
|
1810
|
+
# `issuer` and `signing_key` values. Although the private key can
|
|
1811
|
+
# be passed as a string for convenience, creating and storing
|
|
1812
|
+
# an instance of `OpenSSL::PKey::RSA` is more efficient
|
|
1813
|
+
# when making multiple calls to `generate_signed_post_policy_v4`.
|
|
1814
|
+
#
|
|
1815
|
+
# A {SignedUrlUnavailable} is raised if the service account credentials
|
|
1816
|
+
# are missing. Service account credentials are acquired by following the
|
|
1817
|
+
# steps in [Service Account Authentication](
|
|
1818
|
+
# https://cloud.google.com/iam/docs/service-accounts).
|
|
1819
|
+
#
|
|
1820
|
+
# @see https://cloud.google.com/storage/docs/xml-api/post-object
|
|
1821
|
+
#
|
|
1822
|
+
# @param [String] path Path to the file in Google Cloud Storage.
|
|
1823
|
+
# @param [String] issuer Service Account's Client Email.
|
|
1824
|
+
# @param [String] client_email Service Account's Client Email.
|
|
1825
|
+
# @param [OpenSSL::PKey::RSA, String, Proc] signing_key Service Account's
|
|
1826
|
+
# Private Key or a Proc that accepts a single String parameter and returns a
|
|
1827
|
+
# RSA SHA256 signature using a valid Google Service Account Private Key.
|
|
1828
|
+
# @param [OpenSSL::PKey::RSA, String, Proc] private_key Service Account's
|
|
1829
|
+
# Private Key or a Proc that accepts a single String parameter and returns a
|
|
1830
|
+
# RSA SHA256 signature using a valid Google Service Account Private Key.
|
|
1831
|
+
# @param [OpenSSL::PKey::RSA, String, Proc] signer 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
|
+
#
|
|
1835
|
+
# When using this method in environments such as GAE Flexible Environment,
|
|
1836
|
+
# GKE, or Cloud Functions where the private key is unavailable, it may be
|
|
1837
|
+
# necessary to provide a Proc (or lambda) via the signer parameter. This
|
|
1838
|
+
# Proc should return a signature created using a RPC call to the
|
|
1839
|
+
# [Service Account Credentials signBlob](https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signBlob)
|
|
1840
|
+
# method as shown in the example below.
|
|
1841
|
+
# @param [Integer] expires The number of seconds until the URL expires.
|
|
1842
|
+
# The default is 604800 (7 days).
|
|
1843
|
+
# @param [Hash] fields User-supplied form fields such as `acl`,
|
|
1844
|
+
# `cache-control`, `success_action_status`, and `success_action_redirect`.
|
|
1845
|
+
# @param [Array<Hash|Array>] conditions User-supplied policy conditions.
|
|
1846
|
+
# @param [String] scheme The URL scheme. The default value is `HTTPS`.
|
|
1847
|
+
# @param [Boolean] virtual_hosted_style Whether to use a virtual hosted-style
|
|
1848
|
+
# hostname, which adds the bucket into the host portion of the URI rather
|
|
1849
|
+
# than the path, e.g. `https://mybucket.storage.googleapis.com/...`.
|
|
1850
|
+
# The default value of `false` uses the
|
|
1851
|
+
# form of `https://storage.googleapis.com/mybucket`.
|
|
1852
|
+
# @param [String] bucket_bound_hostname Use a bucket-bound hostname, which
|
|
1853
|
+
# replaces the `storage.googleapis.com` host with the name of a `CNAME`
|
|
1854
|
+
# bucket, e.g. a bucket named `gcs-subdomain.my.domain.tld`, or a Google
|
|
1855
|
+
# Cloud Load Balancer which routes to a bucket you own, e.g.
|
|
1856
|
+
# `my-load-balancer-domain.tld`.
|
|
1857
|
+
#
|
|
1858
|
+
# @return [PostObject] An object containing the URL, fields, and values needed to upload files via html forms.
|
|
1859
|
+
#
|
|
1860
|
+
# @raise [SignedUrlUnavailable] If the service account credentials
|
|
1861
|
+
# are missing. Service account credentials are acquired by following the
|
|
1862
|
+
# steps in [Service Account Authentication](
|
|
1863
|
+
# https://cloud.google.com/iam/docs/service-accounts).
|
|
1864
|
+
#
|
|
1865
|
+
# @example
|
|
1866
|
+
# require "google/cloud/storage"
|
|
1867
|
+
#
|
|
1868
|
+
# storage = Google::Cloud::Storage.new
|
|
1869
|
+
#
|
|
1870
|
+
# bucket = storage.bucket "my-todo-app"
|
|
1871
|
+
#
|
|
1872
|
+
# conditions = [["starts-with", "$acl","public"]]
|
|
1873
|
+
# post = bucket.generate_signed_post_policy_v4 "avatars/heidi/400x400.png", expires: 10,
|
|
1874
|
+
# conditions: conditions
|
|
1875
|
+
#
|
|
1876
|
+
# post.url #=> "https://storage.googleapis.com/my-todo-app/"
|
|
1877
|
+
# post.fields["key"] #=> "my-todo-app/avatars/heidi/400x400.png"
|
|
1878
|
+
# post.fields["policy"] #=> "ABC...XYZ"
|
|
1879
|
+
# post.fields["x-goog-algorithm"] #=> "GOOG4-RSA-SHA256"
|
|
1880
|
+
# post.fields["x-goog-credential"] #=> "cred@pid.iam.gserviceaccount.com/20200123/auto/storage/goog4_request"
|
|
1881
|
+
# post.fields["x-goog-date"] #=> "20200128T000000Z"
|
|
1882
|
+
# post.fields["x-goog-signature"] #=> "4893a0e...cd82"
|
|
1883
|
+
#
|
|
1884
|
+
# @example Using Cloud IAMCredentials signBlob to create the signature:
|
|
1885
|
+
# require "google/cloud/storage"
|
|
1886
|
+
# require "google/apis/iamcredentials_v1"
|
|
1887
|
+
# require "googleauth"
|
|
1888
|
+
#
|
|
1889
|
+
# # Issuer is the service account email that the Signed URL will be signed with
|
|
1890
|
+
# # and any permission granted in the Signed URL must be granted to the
|
|
1891
|
+
# # Google Service Account.
|
|
1892
|
+
# issuer = "service-account@project-id.iam.gserviceaccount.com"
|
|
1893
|
+
#
|
|
1894
|
+
# # Create a lambda that accepts the string_to_sign
|
|
1895
|
+
# signer = lambda do |string_to_sign|
|
|
1896
|
+
# IAMCredentials = Google::Apis::IamcredentialsV1
|
|
1897
|
+
# iam_client = IAMCredentials::IAMCredentialsService.new
|
|
1898
|
+
#
|
|
1899
|
+
# # Get the environment configured authorization
|
|
1900
|
+
# scopes = ["https://www.googleapis.com/auth/iam"]
|
|
1901
|
+
# iam_client.authorization = Google::Auth.get_application_default scopes
|
|
1902
|
+
#
|
|
1903
|
+
# request = {
|
|
1904
|
+
# "payload": string_to_sign,
|
|
1905
|
+
# }
|
|
1906
|
+
# resource = "projects/-/serviceAccounts/#{issuer}"
|
|
1907
|
+
# response = iam_client.sign_service_account_blob resource, request, {}
|
|
1908
|
+
# response.signed_blob
|
|
1909
|
+
# end
|
|
1910
|
+
#
|
|
1911
|
+
# storage = Google::Cloud::Storage.new
|
|
1912
|
+
#
|
|
1913
|
+
# bucket = storage.bucket "my-todo-app"
|
|
1914
|
+
# conditions = [["starts-with", "$acl","public"]]
|
|
1915
|
+
# post = bucket.generate_signed_post_policy_v4(
|
|
1916
|
+
# "avatars/heidi/400x400.png", expires: 10,
|
|
1917
|
+
# conditions: conditions, issuer: issuer, signer: signer
|
|
1918
|
+
# )
|
|
1919
|
+
#
|
|
1920
|
+
# post.url #=> "https://storage.googleapis.com/my-todo-app/"
|
|
1921
|
+
# post.fields["key"] #=> "my-todo-app/avatars/heidi/400x400.png"
|
|
1922
|
+
# post.fields["policy"] #=> "ABC...XYZ"
|
|
1923
|
+
# post.fields["x-goog-algorithm"] #=> "GOOG4-RSA-SHA256"
|
|
1924
|
+
# post.fields["x-goog-credential"] #=> "cred@pid.iam.gserviceaccount.com/20200123/auto/storage/goog4_request"
|
|
1925
|
+
# post.fields["x-goog-date"] #=> "20200128T000000Z"
|
|
1926
|
+
# post.fields["x-goog-signature"] #=> "4893a0e...cd82"
|
|
1927
|
+
#
|
|
1928
|
+
def generate_signed_post_policy_v4 path,
|
|
1929
|
+
issuer: nil,
|
|
1930
|
+
client_email: nil,
|
|
1931
|
+
signing_key: nil,
|
|
1932
|
+
private_key: nil,
|
|
1933
|
+
signer: nil,
|
|
1934
|
+
expires: nil,
|
|
1935
|
+
fields: nil,
|
|
1936
|
+
conditions: nil,
|
|
1937
|
+
scheme: "https",
|
|
1938
|
+
virtual_hosted_style: nil,
|
|
1939
|
+
bucket_bound_hostname: nil
|
|
1940
|
+
ensure_service!
|
|
1941
|
+
sign = File::SignerV4.from_bucket self, path
|
|
1942
|
+
sign.post_object issuer: issuer,
|
|
1943
|
+
client_email: client_email,
|
|
1944
|
+
signing_key: signing_key,
|
|
1945
|
+
private_key: private_key,
|
|
1946
|
+
signer: signer,
|
|
1947
|
+
expires: expires,
|
|
1948
|
+
fields: fields,
|
|
1949
|
+
conditions: conditions,
|
|
1950
|
+
scheme: scheme,
|
|
1951
|
+
virtual_hosted_style: virtual_hosted_style,
|
|
1952
|
+
bucket_bound_hostname: bucket_bound_hostname
|
|
1645
1953
|
end
|
|
1646
1954
|
|
|
1647
1955
|
##
|
|
@@ -2125,11 +2433,12 @@ module Google
|
|
|
2125
2433
|
def create_notification topic, custom_attrs: nil, event_types: nil,
|
|
2126
2434
|
prefix: nil, payload: nil
|
|
2127
2435
|
ensure_service!
|
|
2128
|
-
options = { custom_attrs: custom_attrs, event_types: event_types,
|
|
2129
|
-
prefix: prefix, payload: payload,
|
|
2130
|
-
user_project: user_project }
|
|
2131
2436
|
|
|
2132
|
-
gapi = service.insert_notification name, topic,
|
|
2437
|
+
gapi = service.insert_notification name, topic, custom_attrs: custom_attrs,
|
|
2438
|
+
event_types: event_types,
|
|
2439
|
+
prefix: prefix,
|
|
2440
|
+
payload: payload,
|
|
2441
|
+
user_project: user_project
|
|
2133
2442
|
Notification.from_gapi name, gapi, service, user_project: user_project
|
|
2134
2443
|
end
|
|
2135
2444
|
alias new_notification create_notification
|
|
@@ -2215,7 +2524,7 @@ module Google
|
|
|
2215
2524
|
patch_args = Hash[attributes.map do |attr|
|
|
2216
2525
|
[attr, @gapi.send(attr)]
|
|
2217
2526
|
end]
|
|
2218
|
-
patch_gapi = API::Bucket.new
|
|
2527
|
+
patch_gapi = API::Bucket.new(**patch_args)
|
|
2219
2528
|
@gapi = service.patch_bucket name, patch_gapi,
|
|
2220
2529
|
user_project: user_project
|
|
2221
2530
|
@lazy = nil
|