Skip to content

Commit

Permalink
Add support for specifying credentials (#35)
Browse files Browse the repository at this point in the history
* Add support for specifying credentials
  • Loading branch information
ianks authored Apr 2, 2020
1 parent 0477b07 commit 5254d17
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 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: {})
def initialize(project: nil, bucket:, prefix: nil, host: nil, default_acl: nil, object_options: {}, credentials: nil)
@project = project
@bucket = bucket
@prefix = prefix
@host = host
@default_acl = default_acl
@object_options = object_options
@storage = nil
@credentials = credentials
end

# If the file is an UploadFile from GCS, issues a copy command, otherwise it uploads a file.
Expand Down Expand Up @@ -150,11 +151,13 @@ def get_bucket(bucket_name = @bucket)

# @see http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-storage/v1.6.0/guides/authentication
def storage
@storage ||= if @project.nil?
Google::Cloud::Storage.new
else
Google::Cloud::Storage.new(project: @project)
end
return @storage if @storage

opts = {}
opts[:project] = @project if @project
opts[:credentials] = @credentials if @credentials

@storage = Google::Cloud::Storage.new(opts)
end

def copyable?(io)
Expand Down

0 comments on commit 5254d17

Please sign in to comment.