lib/google/cloud/storage.rb in google-cloud-storage-1.15.0 vs lib/google/cloud/storage.rb in google-cloud-storage-1.16.0
- old
+ new
@@ -73,20 +73,24 @@
# bucket = storage.bucket "my-bucket"
# file = bucket.file "path/to/my-file.ext"
#
def self.new project_id: nil, credentials: nil, scope: nil, retries: nil,
timeout: nil, project: nil, keyfile: nil
- project_id ||= (project || default_project_id)
- project_id = project_id.to_s # Always cast to a string
- raise ArgumentError, "project_id is missing" if project_id.empty?
-
- scope ||= configure.scope
- retries ||= configure.retries
- timeout ||= configure.timeout
+ project_id ||= (project || default_project_id)
+ scope ||= configure.scope
+ retries ||= configure.retries
+ timeout ||= configure.timeout
credentials ||= (keyfile || default_credentials(scope: scope))
+
unless credentials.is_a? Google::Auth::Credentials
credentials = Storage::Credentials.new credentials, scope: scope
end
+
+ if credentials.respond_to? :project_id
+ project_id ||= credentials.project_id
+ end
+ project_id = project_id.to_s # Always cast to a string
+ raise ArgumentError, "project_id is missing" if project_id.empty?
Storage::Project.new(
Storage::Service.new(
project_id, credentials, retries: retries, timeout: timeout
)