From 13bb435cf827f2508a7c8f8f4aff4e36396f8a2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trung=20L=C3=AA?= Date: Wed, 8 Apr 2015 10:53:22 +1000 Subject: [PATCH 1/3] Refactor Google::Auth.determine_creds_class to use case statements --- lib/googleauth.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/googleauth.rb b/lib/googleauth.rb index c7cfe45..03f8308 100644 --- a/lib/googleauth.rb +++ b/lib/googleauth.rb @@ -62,9 +62,14 @@ END json_key = MultiJson.load(json_key_io.read) fail "the json is missing the #{key} field" unless json_key.key?('type') type = json_key['type'] - return json_key, ServiceAccountCredentials if type == 'service_account' - return [json_key, UserRefreshCredentials] if type == 'authorized_user' - fail "credentials type '#{type}' is not supported" + case type + when 'service_account' + [json_key, ServiceAccountCredentials] + when 'authorized_user' + [json_key, UserRefreshCredentials] + else + fail "credentials type '#{type}' is not supported" + end end end From 377c679586f2363686cd96499ad40c2c5ebda5c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trung=20L=C3=AA?= Date: Wed, 8 Apr 2015 11:05:42 +1000 Subject: [PATCH 2/3] Refactor Google::Auth#get_application_default --- lib/googleauth.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/googleauth.rb b/lib/googleauth.rb index 03f8308..4834faa 100644 --- a/lib/googleauth.rb +++ b/lib/googleauth.rb @@ -87,9 +87,7 @@ END # @param scope [string|array|nil] the scope(s) to access # @param options [hash] allows override of the connection being used def get_application_default(scope = nil, options = {}) - creds = DefaultCredentials.from_env(scope) - return creds unless creds.nil? - creds = DefaultCredentials.from_well_known_path(scope) + creds = DefaultCredentials.from_env(scope) || DefaultCredentials.from_well_known_path(scope) return creds unless creds.nil? fail NOT_FOUND_ERROR unless GCECredentials.on_gce?(options) GCECredentials.new From 66ae035cce46acef4f96e62f175a4cf074df7a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trung=20L=C3=AA?= Date: Wed, 8 Apr 2015 11:10:25 +1000 Subject: [PATCH 3/3] More refactoring to please rubocop --- lib/googleauth.rb | 3 ++- spec/googleauth/signet_spec.rb | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/googleauth.rb b/lib/googleauth.rb index 4834faa..ca9b750 100644 --- a/lib/googleauth.rb +++ b/lib/googleauth.rb @@ -87,7 +87,8 @@ END # @param scope [string|array|nil] the scope(s) to access # @param options [hash] allows override of the connection being used def get_application_default(scope = nil, options = {}) - creds = DefaultCredentials.from_env(scope) || DefaultCredentials.from_well_known_path(scope) + creds = DefaultCredentials.from_env(scope) || + DefaultCredentials.from_well_known_path(scope) return creds unless creds.nil? fail NOT_FOUND_ERROR unless GCECredentials.on_gce?(options) GCECredentials.new diff --git a/spec/googleauth/signet_spec.rb b/spec/googleauth/signet_spec.rb index 60da4fd..884e2fe 100644 --- a/spec/googleauth/signet_spec.rb +++ b/spec/googleauth/signet_spec.rb @@ -45,8 +45,7 @@ describe Signet::OAuth2::Client do scope: 'https://www.googleapis.com/auth/userinfo.profile', issuer: 'app@example.com', audience: 'https://accounts.google.com/o/oauth2/token', - signing_key: @key - ) + signing_key: @key) end def make_auth_stubs(opts)