Skip to content

Commit

Permalink
Merge pull request #1 from silverfin/tom-add-user-project-to-bucket-call
Browse files Browse the repository at this point in the history
Add  option to support 'Requester Pays' buckets
  • Loading branch information
liseki authored Jan 16, 2024
2 parents 04a7b0a + 291ee76 commit 7eb7e85
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
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

0 comments on commit 7eb7e85

Please sign in to comment.