From 291ee76afc4d43f46c4372123b5146fb093b36f6 Mon Sep 17 00:00:00 2001 From: Tom Naessens Date: Mon, 15 Jan 2024 13:03:06 +0100 Subject: [PATCH] Add option to support 'Requester Pays' buckets --- CHANGELOG.md | 4 ++++ lib/shrine/storage/google_cloud_storage.rb | 7 ++++--- shrine-google_cloud_storage.gemspec | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd3cbec..ecff3b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Added + +- `user_project` option on storage, which enables the `userProject` option on the underlying `google-cloud-storage` client, allowing to specify a project to bill for the request for requester-pays buckets (https://cloud.google.com/storage/docs/using-requester-pays) + ## 3.3.0 - 2022-08-14 ### Added diff --git a/lib/shrine/storage/google_cloud_storage.rb b/lib/shrine/storage/google_cloud_storage.rb index e687ca9..9497430 100644 --- a/lib/shrine/storage/google_cloud_storage.rb +++ b/lib/shrine/storage/google_cloud_storage.rb @@ -10,7 +10,7 @@ class GoogleCloudStorage # Initialize a Shrine::Storage for GCS allowing for auto-discovery of the Google::Cloud::Storage client. # @param [String] project Provide if not using auto discovery # @see http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-storage/v1.6.0/guides/authentication#environmentvariables for information on discovery - def initialize(project: nil, bucket:, prefix: nil, host: nil, default_acl: nil, object_options: {}, credentials: nil, public: false) + def initialize(project: nil, bucket:, prefix: nil, host: nil, default_acl: nil, object_options: {}, credentials: nil, public: false, user_project: nil) @project = project @bucket = bucket @prefix = prefix @@ -18,6 +18,7 @@ def initialize(project: nil, bucket:, prefix: nil, host: nil, default_acl: nil, @object_options = object_options @storage = nil @credentials = credentials + @user_project = user_project @default_acl = if public && default_acl && default_acl != "publicRead" raise Shrine::Error, "You can not set both public and default_acl" @@ -154,8 +155,8 @@ def get_file(id) get_bucket.file(object_name(id)) end - def get_bucket(bucket_name = @bucket) - storage.bucket(bucket_name, skip_lookup: true) + def get_bucket(bucket_name = @bucket, user_project = @user_project) + storage.bucket(bucket_name, skip_lookup: true, user_project: user_project) end # @see http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-storage/v1.6.0/guides/authentication diff --git a/shrine-google_cloud_storage.gemspec b/shrine-google_cloud_storage.gemspec index b318132..cad3eb0 100644 --- a/shrine-google_cloud_storage.gemspec +++ b/shrine-google_cloud_storage.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |gem| gem.name = "shrine-google_cloud_storage" - gem.version = "3.3.0" + gem.version = "3.4.0" gem.required_ruby_version = ">= 2.6"