google-cloud-storage 1.18.1 → 1.44.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 +17 -30
- data/CHANGELOG.md +312 -0
- data/CONTRIBUTING.md +4 -5
- data/LOGGING.md +1 -1
- data/OVERVIEW.md +37 -5
- data/TROUBLESHOOTING.md +2 -8
- data/lib/google/cloud/storage/bucket/acl.rb +40 -40
- data/lib/google/cloud/storage/bucket/cors.rb +4 -1
- data/lib/google/cloud/storage/bucket/lifecycle.rb +259 -44
- data/lib/google/cloud/storage/bucket/list.rb +3 -3
- data/lib/google/cloud/storage/bucket.rb +1096 -172
- data/lib/google/cloud/storage/convert.rb +4 -3
- data/lib/google/cloud/storage/credentials.rb +16 -14
- data/lib/google/cloud/storage/errors.rb +7 -2
- data/lib/google/cloud/storage/file/acl.rb +181 -20
- data/lib/google/cloud/storage/file/list.rb +10 -8
- data/lib/google/cloud/storage/file/signer_v2.rb +36 -18
- data/lib/google/cloud/storage/file/signer_v4.rb +249 -61
- data/lib/google/cloud/storage/file/verifier.rb +2 -2
- data/lib/google/cloud/storage/file.rb +450 -84
- data/lib/google/cloud/storage/hmac_key/list.rb +182 -0
- data/lib/google/cloud/storage/hmac_key.rb +316 -0
- data/lib/google/cloud/storage/policy/binding.rb +246 -0
- data/lib/google/cloud/storage/policy/bindings.rb +196 -0
- data/lib/google/cloud/storage/policy/condition.rb +138 -0
- data/lib/google/cloud/storage/policy.rb +277 -24
- data/lib/google/cloud/storage/post_object.rb +20 -2
- data/lib/google/cloud/storage/project.rb +249 -50
- data/lib/google/cloud/storage/service.rb +479 -288
- data/lib/google/cloud/storage/version.rb +1 -1
- data/lib/google/cloud/storage.rb +86 -16
- data/lib/google-cloud-storage.rb +54 -7
- metadata +74 -27
@@ -21,6 +21,7 @@ require "google/cloud/storage/bucket"
|
|
21
21
|
require "google/cloud/storage/bucket/cors"
|
22
22
|
require "google/cloud/storage/bucket/lifecycle"
|
23
23
|
require "google/cloud/storage/file"
|
24
|
+
require "google/cloud/storage/hmac_key"
|
24
25
|
|
25
26
|
module Google
|
26
27
|
module Cloud
|
@@ -164,6 +165,11 @@ module Google
|
|
164
165
|
# without verifying the bucket resource exists on the Storage service.
|
165
166
|
# Calls made on this object will raise errors if the bucket resource
|
166
167
|
# does not exist. Default is `false`.
|
168
|
+
# @param [Integer] if_metageneration_match Makes the operation conditional
|
169
|
+
# on whether the bucket's current metageneration matches the given value.
|
170
|
+
# @param [Integer] if_metageneration_not_match Makes the operation
|
171
|
+
# conditional on whether the bucket's current metageneration does not
|
172
|
+
# match the given value.
|
167
173
|
# @param [Boolean, String] user_project If this parameter is set to
|
168
174
|
# `true`, transit costs for operations on the requested bucket or a
|
169
175
|
# file it contains will be billed to the current project for this
|
@@ -207,12 +213,19 @@ module Google
|
|
207
213
|
# user_project: "my-other-project"
|
208
214
|
# files = bucket.files # Billed to "my-other-project"
|
209
215
|
#
|
210
|
-
def bucket bucket_name,
|
216
|
+
def bucket bucket_name,
|
217
|
+
skip_lookup: false,
|
218
|
+
if_metageneration_match: nil,
|
219
|
+
if_metageneration_not_match: nil,
|
220
|
+
user_project: nil
|
211
221
|
if skip_lookup
|
212
222
|
return Bucket.new_lazy bucket_name, service,
|
213
223
|
user_project: user_project
|
214
224
|
end
|
215
|
-
gapi = service.get_bucket bucket_name,
|
225
|
+
gapi = service.get_bucket bucket_name,
|
226
|
+
if_metageneration_match: if_metageneration_match,
|
227
|
+
if_metageneration_not_match: if_metageneration_not_match,
|
228
|
+
user_project: user_project
|
216
229
|
Bucket.from_gapi gapi, service, user_project: user_project
|
217
230
|
rescue Google::Cloud::NotFoundError
|
218
231
|
nil
|
@@ -232,11 +245,9 @@ module Google
|
|
232
245
|
# for the bucket, including a block that defines CORS rule. See
|
233
246
|
# {Bucket::Cors} for details.
|
234
247
|
#
|
235
|
-
# Before enabling
|
236
|
-
# review [
|
237
|
-
#
|
238
|
-
# as well as [Should you use Bucket Policy
|
239
|
-
# Only?](https://cloud.google.com/storage/docs/bucket-policy-only#should-you-use).
|
248
|
+
# Before enabling uniform bucket-level access (see
|
249
|
+
# {Bucket#uniform_bucket_level_access=}) please review [uniform bucket-level
|
250
|
+
# access](https://cloud.google.com/storage/docs/uniform-bucket-level-access).
|
240
251
|
#
|
241
252
|
# @see https://cloud.google.com/storage/docs/cross-origin Cross-Origin
|
242
253
|
# Resource Sharing (CORS)
|
@@ -277,12 +288,11 @@ module Google
|
|
277
288
|
# roles.
|
278
289
|
# * `public`, `public_read`, `publicRead` - File owner gets OWNER
|
279
290
|
# access, and allUsers get READER access.
|
280
|
-
# @param [String] location The location of the bucket.
|
281
|
-
#
|
282
|
-
#
|
283
|
-
#
|
284
|
-
#
|
285
|
-
# the authoritative list. The default value is `US`.
|
291
|
+
# @param [String] location The location of the bucket. Optional.
|
292
|
+
# If not passed, the default location, 'US', will be used.
|
293
|
+
# If specifying a dual-region location, the `customPlacementConfig`
|
294
|
+
# property should be set in conjunction. See:
|
295
|
+
# [Storage Locations](https://cloud.google.com/storage/docs/locations).
|
286
296
|
# @param [String] logging_bucket The destination bucket for the bucket's
|
287
297
|
# logs. For more information, see [Access
|
288
298
|
# Logs](https://cloud.google.com/storage/docs/access-logs).
|
@@ -295,13 +305,11 @@ module Google
|
|
295
305
|
# Logs](https://cloud.google.com/storage/docs/access-logs).
|
296
306
|
# @param [Symbol, String] storage_class Defines how objects in the
|
297
307
|
# bucket are stored and determines the SLA and the cost of storage.
|
298
|
-
# Accepted values include `:
|
299
|
-
#
|
308
|
+
# Accepted values include `:standard`, `:nearline`, `:coldline`, and
|
309
|
+
# `:archive`, as well as the equivalent strings returned by
|
300
310
|
# {Bucket#storage_class}. For more information, see [Storage
|
301
311
|
# Classes](https://cloud.google.com/storage/docs/storage-classes). The
|
302
|
-
# default value is the
|
303
|
-
# `:multi_regional` or `:regional` depending on the bucket's location
|
304
|
-
# settings.
|
312
|
+
# default value is the `:standard` storage class.
|
305
313
|
# @param [Boolean] versioning Whether [Object
|
306
314
|
# Versioning](https://cloud.google.com/storage/docs/object-versioning)
|
307
315
|
# is to be enabled for the bucket. The default value is `false`.
|
@@ -319,6 +327,11 @@ module Google
|
|
319
327
|
# other than the current project, and that project is authorized for
|
320
328
|
# the currently authenticated service account, transit costs will be
|
321
329
|
# billed to the given project. The default is `nil`.
|
330
|
+
# @param [Boolean] autoclass_enabled The bucket's autoclass configuration.
|
331
|
+
# Buckets can have either StorageClass OLM rules or Autoclass, but
|
332
|
+
# not both. When Autoclass is enabled on a bucket, adding StorageClass
|
333
|
+
# OLM rules will result in failure. For more information, see
|
334
|
+
# [Autoclass](https://cloud.google.com/storage/docs/autoclass).
|
322
335
|
#
|
323
336
|
# The value provided will be applied to all operations on the returned
|
324
337
|
# bucket instance and its files.
|
@@ -355,19 +368,31 @@ module Google
|
|
355
368
|
# b.lifecycle.add_set_storage_class_rule "COLDLINE", age: 10
|
356
369
|
# end
|
357
370
|
#
|
358
|
-
def create_bucket bucket_name,
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
371
|
+
def create_bucket bucket_name,
|
372
|
+
acl: nil,
|
373
|
+
default_acl: nil,
|
374
|
+
location: nil,
|
375
|
+
custom_placement_config: nil,
|
376
|
+
storage_class: nil,
|
377
|
+
logging_bucket: nil,
|
378
|
+
logging_prefix: nil,
|
379
|
+
website_main: nil,
|
380
|
+
website_404: nil,
|
381
|
+
versioning: nil,
|
382
|
+
requester_pays: nil,
|
383
|
+
user_project: nil,
|
384
|
+
autoclass_enabled: false
|
385
|
+
params = {
|
364
386
|
name: bucket_name,
|
365
|
-
location: location
|
366
|
-
|
387
|
+
location: location,
|
388
|
+
custom_placement_config: custom_placement_config
|
389
|
+
}.delete_if { |_, v| v.nil? }
|
390
|
+
new_bucket = Google::Apis::StorageV1::Bucket.new(**params)
|
367
391
|
storage_class = storage_class_for storage_class
|
368
392
|
updater = Bucket::Updater.new(new_bucket).tap do |b|
|
369
393
|
b.logging_bucket = logging_bucket unless logging_bucket.nil?
|
370
394
|
b.logging_prefix = logging_prefix unless logging_prefix.nil?
|
395
|
+
b.autoclass_enabled = autoclass_enabled
|
371
396
|
b.storage_class = storage_class unless storage_class.nil?
|
372
397
|
b.website_main = website_main unless website_main.nil?
|
373
398
|
b.website_404 = website_404 unless website_404.nil?
|
@@ -384,6 +409,91 @@ module Google
|
|
384
409
|
Bucket.from_gapi gapi, service, user_project: user_project
|
385
410
|
end
|
386
411
|
|
412
|
+
##
|
413
|
+
# Creates a new HMAC key.
|
414
|
+
#
|
415
|
+
# @param [String] service_account_email The email address of the service
|
416
|
+
# account. Used to create the HMAC key.
|
417
|
+
# @param [String] project_id The project ID associated with
|
418
|
+
# `service_account_email`, if `service_account_email` belongs to a
|
419
|
+
# project other than the currently authenticated project. Optional. If
|
420
|
+
# not provided, the project ID for the current project will be used.
|
421
|
+
# @param [String] user_project If this parameter is set to a project ID
|
422
|
+
# other than the current project, and that project is authorized for
|
423
|
+
# the currently authenticated service account, transit costs will be
|
424
|
+
# billed to the given project. The default is `nil`.
|
425
|
+
#
|
426
|
+
# @return [Google::Cloud::Storage::HmacKey]
|
427
|
+
#
|
428
|
+
def create_hmac_key service_account_email, project_id: nil,
|
429
|
+
user_project: nil
|
430
|
+
gapi = service.create_hmac_key service_account_email,
|
431
|
+
project_id: project_id,
|
432
|
+
user_project: user_project
|
433
|
+
HmacKey.from_gapi gapi, service, user_project: user_project
|
434
|
+
end
|
435
|
+
|
436
|
+
##
|
437
|
+
# Retrieves an HMAC key's metadata; the key's secret is not included in
|
438
|
+
# the representation.
|
439
|
+
#
|
440
|
+
# @param [String] project_id The project ID associated with the
|
441
|
+
# `service_account_email` used to create the HMAC key, if the
|
442
|
+
# service account email belongs to a project other than the
|
443
|
+
# currently authenticated project. Optional. If not provided, the
|
444
|
+
# project ID for current project will be used.
|
445
|
+
# @param [String] user_project If this parameter is set to a project ID
|
446
|
+
# other than the current project, and that project is authorized for
|
447
|
+
# the currently authenticated service account, transit costs will be
|
448
|
+
# billed to the given project. The default is `nil`.
|
449
|
+
#
|
450
|
+
# @return [Google::Cloud::Storage::HmacKey]
|
451
|
+
#
|
452
|
+
def hmac_key access_id, project_id: nil, user_project: nil
|
453
|
+
gapi = service.get_hmac_key \
|
454
|
+
access_id, project_id: project_id, user_project: user_project
|
455
|
+
HmacKey.from_gapi_metadata gapi, service, user_project: user_project
|
456
|
+
end
|
457
|
+
|
458
|
+
##
|
459
|
+
# Retrieves a list of HMAC key metadata matching the criteria; the keys'
|
460
|
+
# secrets are not included.
|
461
|
+
#
|
462
|
+
# @param [String] service_account_email
|
463
|
+
# If present, only keys for the given service account are returned.
|
464
|
+
# @param [String] project_id The project ID associated with the
|
465
|
+
# `service_account_email` used to create the HMAC keys, if the
|
466
|
+
# service account email belongs to a project other than the
|
467
|
+
# currently authenticated project. Optional. If not provided, the
|
468
|
+
# project ID for current project will be used.
|
469
|
+
# @param [Boolean] show_deleted_keys
|
470
|
+
# Whether to include keys in the `DELETED` state. The default value is
|
471
|
+
# false.
|
472
|
+
# @param [String] token A previously-returned page token representing
|
473
|
+
# part of the larger set of results to view.
|
474
|
+
# @param [Integer] max Maximum number of keys to return.
|
475
|
+
# @param [String] user_project If this parameter is set to a project ID
|
476
|
+
# other than the current project, and that project is authorized for
|
477
|
+
# the currently authenticated service account, transit costs will be
|
478
|
+
# billed to the given project. The default is `nil`.
|
479
|
+
#
|
480
|
+
# @return [Google::Cloud::Storage::HmacKey]
|
481
|
+
#
|
482
|
+
def hmac_keys service_account_email: nil, project_id: nil,
|
483
|
+
show_deleted_keys: nil, token: nil, max: nil,
|
484
|
+
user_project: nil
|
485
|
+
gapi = service.list_hmac_keys \
|
486
|
+
max: max, token: token,
|
487
|
+
service_account_email: service_account_email,
|
488
|
+
project_id: project_id, show_deleted_keys: show_deleted_keys,
|
489
|
+
user_project: user_project
|
490
|
+
|
491
|
+
HmacKey::List.from_gapi \
|
492
|
+
gapi, service,
|
493
|
+
service_account_email: nil, show_deleted_keys: nil,
|
494
|
+
max: max, user_project: user_project
|
495
|
+
end
|
496
|
+
|
387
497
|
##
|
388
498
|
# Generates a signed URL. See [Signed
|
389
499
|
# URLs](https://cloud.google.com/storage/docs/access-control/signed-urls)
|
@@ -400,7 +510,7 @@ module Google
|
|
400
510
|
# A {SignedUrlUnavailable} is raised if the service account credentials
|
401
511
|
# are missing. Service account credentials are acquired by following the
|
402
512
|
# steps in [Service Account Authentication](
|
403
|
-
# https://cloud.google.com/
|
513
|
+
# https://cloud.google.com/iam/docs/service-accounts).
|
404
514
|
#
|
405
515
|
# @see https://cloud.google.com/storage/docs/access-control/signed-urls
|
406
516
|
# Signed URLs guide
|
@@ -428,10 +538,22 @@ module Google
|
|
428
538
|
# use the signed URL.
|
429
539
|
# @param [String] issuer Service Account's Client Email.
|
430
540
|
# @param [String] client_email Service Account's Client Email.
|
431
|
-
# @param [OpenSSL::PKey::RSA, String] signing_key Service Account's
|
432
|
-
# Private Key
|
433
|
-
#
|
434
|
-
#
|
541
|
+
# @param [OpenSSL::PKey::RSA, String, Proc] signing_key Service Account's
|
542
|
+
# Private Key or a Proc that accepts a single String parameter and returns a
|
543
|
+
# RSA SHA256 signature using a valid Google Service Account Private Key.
|
544
|
+
# @param [OpenSSL::PKey::RSA, String, Proc] private_key Service Account's
|
545
|
+
# Private Key or a Proc that accepts a single String parameter and returns a
|
546
|
+
# RSA SHA256 signature using a valid Google Service Account Private Key.
|
547
|
+
# @param [OpenSSL::PKey::RSA, String, Proc] signer Service Account's
|
548
|
+
# Private Key or a Proc that accepts a single String parameter and returns a
|
549
|
+
# RSA SHA256 signature using a valid Google Service Account Private Key.
|
550
|
+
#
|
551
|
+
# When using this method in environments such as GAE Flexible Environment,
|
552
|
+
# GKE, or Cloud Functions where the private key is unavailable, it may be
|
553
|
+
# necessary to provide a Proc (or lambda) via the signer parameter. This
|
554
|
+
# Proc should return a signature created using a RPC call to the
|
555
|
+
# [Service Account Credentials signBlob](https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signBlob)
|
556
|
+
# method as shown in the example below.
|
435
557
|
# @param [Hash] query Query string parameters to include in the signed
|
436
558
|
# URL. The given parameters are not verified by the signature.
|
437
559
|
#
|
@@ -440,11 +562,29 @@ module Google
|
|
440
562
|
# using the URL, but only when the file resource is missing the
|
441
563
|
# corresponding values. (These values can be permanently set using
|
442
564
|
# {File#content_disposition=} and {File#content_type=}.)
|
565
|
+
# @param [String] scheme The URL scheme. The default value is `HTTPS`.
|
566
|
+
# @param [Boolean] virtual_hosted_style Whether to use a virtual hosted-style
|
567
|
+
# hostname, which adds the bucket into the host portion of the URI rather
|
568
|
+
# than the path, e.g. `https://mybucket.storage.googleapis.com/...`.
|
569
|
+
# For V4 signing, this also sets the `host` header in the canonicalized
|
570
|
+
# extension headers to the virtual hosted-style host, unless that header is
|
571
|
+
# supplied via the `headers` param. The default value of `false` uses the
|
572
|
+
# form of `https://storage.googleapis.com/mybucket`.
|
573
|
+
# @param [String] bucket_bound_hostname Use a bucket-bound hostname, which
|
574
|
+
# replaces the `storage.googleapis.com` host with the name of a `CNAME`
|
575
|
+
# bucket, e.g. a bucket named `gcs-subdomain.my.domain.tld`, or a Google
|
576
|
+
# Cloud Load Balancer which routes to a bucket you own, e.g.
|
577
|
+
# `my-load-balancer-domain.tld`.
|
443
578
|
# @param [Symbol, String] version The version of the signed credential
|
444
579
|
# to create. Must be one of `:v2` or `:v4`. The default value is
|
445
580
|
# `:v2`.
|
446
581
|
#
|
447
|
-
# @return [String]
|
582
|
+
# @return [String] The signed URL.
|
583
|
+
#
|
584
|
+
# @raise [SignedUrlUnavailable] If the service account credentials
|
585
|
+
# are missing. Service account credentials are acquired by following the
|
586
|
+
# steps in [Service Account Authentication](
|
587
|
+
# https://cloud.google.com/iam/docs/service-accounts).
|
448
588
|
#
|
449
589
|
# @example
|
450
590
|
# require "google/cloud/storage"
|
@@ -479,6 +619,41 @@ module Google
|
|
479
619
|
# issuer: issuer_email,
|
480
620
|
# signing_key: key
|
481
621
|
#
|
622
|
+
# @example Using Cloud IAMCredentials signBlob to create the signature:
|
623
|
+
# require "google/cloud/storage"
|
624
|
+
# require "google/apis/iamcredentials_v1"
|
625
|
+
# require "googleauth"
|
626
|
+
#
|
627
|
+
# # Issuer is the service account email that the Signed URL will be signed with
|
628
|
+
# # and any permission granted in the Signed URL must be granted to the
|
629
|
+
# # Google Service Account.
|
630
|
+
# issuer = "service-account@project-id.iam.gserviceaccount.com"
|
631
|
+
#
|
632
|
+
# # Create a lambda that accepts the string_to_sign
|
633
|
+
# signer = lambda do |string_to_sign|
|
634
|
+
# IAMCredentials = Google::Apis::IamcredentialsV1
|
635
|
+
# iam_client = IAMCredentials::IAMCredentialsService.new
|
636
|
+
#
|
637
|
+
# # Get the environment configured authorization
|
638
|
+
# scopes = ["https://www.googleapis.com/auth/iam"]
|
639
|
+
# iam_client.authorization = Google::Auth.get_application_default scopes
|
640
|
+
#
|
641
|
+
# request = Google::Apis::IamcredentialsV1::SignBlobRequest.new(
|
642
|
+
# payload: string_to_sign
|
643
|
+
# )
|
644
|
+
# resource = "projects/-/serviceAccounts/#{issuer}"
|
645
|
+
# response = iam_client.sign_service_account_blob resource, request
|
646
|
+
# response.signed_blob
|
647
|
+
# end
|
648
|
+
#
|
649
|
+
# storage = Google::Cloud::Storage.new
|
650
|
+
#
|
651
|
+
# bucket_name = "my-todo-app"
|
652
|
+
# file_path = "avatars/heidi/400x400.png"
|
653
|
+
# url = storage.signed_url bucket_name, file_path,
|
654
|
+
# method: "GET", issuer: issuer,
|
655
|
+
# signer: signer
|
656
|
+
#
|
482
657
|
# @example Using the `headers` option:
|
483
658
|
# require "google/cloud/storage"
|
484
659
|
#
|
@@ -509,28 +684,52 @@ module Google
|
|
509
684
|
# # Send the `x-goog-resumable:start` header and the content type
|
510
685
|
# # with the resumable upload POST request.
|
511
686
|
#
|
512
|
-
def signed_url bucket,
|
513
|
-
|
514
|
-
|
515
|
-
|
687
|
+
def signed_url bucket,
|
688
|
+
path,
|
689
|
+
method: "GET",
|
690
|
+
expires: nil,
|
691
|
+
content_type: nil,
|
692
|
+
content_md5: nil,
|
693
|
+
headers: nil,
|
694
|
+
issuer: nil,
|
695
|
+
client_email: nil,
|
696
|
+
signing_key: nil,
|
697
|
+
private_key: nil,
|
698
|
+
signer: nil,
|
699
|
+
query: nil,
|
700
|
+
scheme: "HTTPS",
|
701
|
+
virtual_hosted_style: nil,
|
702
|
+
bucket_bound_hostname: nil,
|
703
|
+
version: nil
|
516
704
|
version ||= :v2
|
517
705
|
case version.to_sym
|
518
706
|
when :v2
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
707
|
+
sign = File::SignerV2.new bucket, path, service
|
708
|
+
sign.signed_url method: method,
|
709
|
+
expires: expires,
|
710
|
+
headers: headers,
|
711
|
+
content_type: content_type,
|
712
|
+
content_md5: content_md5,
|
713
|
+
issuer: issuer,
|
714
|
+
client_email: client_email,
|
715
|
+
signing_key: signing_key,
|
716
|
+
private_key: private_key,
|
717
|
+
signer: signer,
|
718
|
+
query: query
|
527
719
|
when :v4
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
720
|
+
sign = File::SignerV4.new bucket, path, service
|
721
|
+
sign.signed_url method: method,
|
722
|
+
expires: expires,
|
723
|
+
headers: headers,
|
724
|
+
issuer: issuer,
|
725
|
+
client_email: client_email,
|
726
|
+
signing_key: signing_key,
|
727
|
+
private_key: private_key,
|
728
|
+
signer: signer,
|
729
|
+
query: query,
|
730
|
+
scheme: scheme,
|
731
|
+
virtual_hosted_style: virtual_hosted_style,
|
732
|
+
bucket_bound_hostname: bucket_bound_hostname
|
534
733
|
else
|
535
734
|
raise ArgumentError, "version '#{version}' not supported"
|
536
735
|
end
|