Merge pull request #21 from joneslee85/minor-refactoring

Minor refactoring
This commit is contained in:
Tim Emiola 2015-04-14 08:58:47 -07:00
commit 2924980b52
2 changed files with 11 additions and 8 deletions

View File

@ -62,9 +62,14 @@ END
json_key = MultiJson.load(json_key_io.read) json_key = MultiJson.load(json_key_io.read)
fail "the json is missing the #{key} field" unless json_key.key?('type') fail "the json is missing the #{key} field" unless json_key.key?('type')
type = json_key['type'] type = json_key['type']
return json_key, ServiceAccountCredentials if type == 'service_account' case type
return [json_key, UserRefreshCredentials] if type == 'authorized_user' when 'service_account'
fail "credentials type '#{type}' is not supported" [json_key, ServiceAccountCredentials]
when 'authorized_user'
[json_key, UserRefreshCredentials]
else
fail "credentials type '#{type}' is not supported"
end
end end
end end
@ -82,9 +87,8 @@ END
# @param scope [string|array|nil] the scope(s) to access # @param scope [string|array|nil] the scope(s) to access
# @param options [hash] allows override of the connection being used # @param options [hash] allows override of the connection being used
def get_application_default(scope = nil, options = {}) def get_application_default(scope = nil, options = {})
creds = DefaultCredentials.from_env(scope) creds = DefaultCredentials.from_env(scope) ||
return creds unless creds.nil? DefaultCredentials.from_well_known_path(scope)
creds = DefaultCredentials.from_well_known_path(scope)
return creds unless creds.nil? return creds unless creds.nil?
fail NOT_FOUND_ERROR unless GCECredentials.on_gce?(options) fail NOT_FOUND_ERROR unless GCECredentials.on_gce?(options)
GCECredentials.new GCECredentials.new

View File

@ -45,8 +45,7 @@ describe Signet::OAuth2::Client do
scope: 'https://www.googleapis.com/auth/userinfo.profile', scope: 'https://www.googleapis.com/auth/userinfo.profile',
issuer: 'app@example.com', issuer: 'app@example.com',
audience: 'https://accounts.google.com/o/oauth2/token', audience: 'https://accounts.google.com/o/oauth2/token',
signing_key: @key signing_key: @key)
)
end end
def make_auth_stubs(opts) def make_auth_stubs(opts)