Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to support 'Requester Pays' buckets #56

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions lib/shrine/storage/google_cloud_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ 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
@host = host
@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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion shrine-google_cloud_storage.gemspec
Original file line number Diff line number Diff line change
@@ -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"

Expand Down