From 0d2becbdcd986204489b8a93507ced148e387082 Mon Sep 17 00:00:00 2001 From: Graham Paye Date: Fri, 26 Oct 2018 12:17:12 -0700 Subject: [PATCH] make load_gcloud_project_id module function (#170) --- CHANGELOG.md | 6 +++++- lib/googleauth/credentials_loader.rb | 1 + lib/googleauth/service_account.rb | 4 ++-- lib/googleauth/user_refresh.rb | 2 +- lib/googleauth/version.rb | 2 +- spec/googleauth/user_refresh_spec.rb | 2 +- 6 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e69b7e..14400c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ -## 0.7.0 (2018/10/23) +## 0.7.1 (2018/10/25) + +* Make load_gcloud_project_id module function. + +## 0.7.0 (2018/10/24) * Add project_id instance variable to UserRefreshCredentials, ServiceAccountCredentials, and Credentials. diff --git a/lib/googleauth/credentials_loader.rb b/lib/googleauth/credentials_loader.rb index 9d4aab8..f5f8908 100644 --- a/lib/googleauth/credentials_loader.rb +++ b/lib/googleauth/credentials_loader.rb @@ -147,6 +147,7 @@ module Google rescue warn 'Unable to determine project id.' end + module_function :load_gcloud_project_id private diff --git a/lib/googleauth/service_account.rb b/lib/googleauth/service_account.rb index 3e799ce..cc23f72 100644 --- a/lib/googleauth/service_account.rb +++ b/lib/googleauth/service_account.rb @@ -65,7 +65,7 @@ module Google client_email = ENV[CredentialsLoader::CLIENT_EMAIL_VAR] project_id = ENV[CredentialsLoader::PROJECT_ID_VAR] end - project_id ||= self.class.load_gcloud_project_id + project_id ||= CredentialsLoader.load_gcloud_project_id new(token_credential_uri: TOKEN_CRED_URI, audience: TOKEN_CRED_URI, @@ -157,7 +157,7 @@ module Google @issuer = ENV[CredentialsLoader::CLIENT_EMAIL_VAR] @project_id = ENV[CredentialsLoader::PROJECT_ID_VAR] end - @project_id ||= self.class.load_gcloud_project_id + @project_id ||= CredentialsLoader.load_gcloud_project_id @signing_key = OpenSSL::PKey::RSA.new(@private_key) end diff --git a/lib/googleauth/user_refresh.rb b/lib/googleauth/user_refresh.rb index aeb1a4d..211cb31 100644 --- a/lib/googleauth/user_refresh.rb +++ b/lib/googleauth/user_refresh.rb @@ -90,7 +90,7 @@ module Google options[:token_credential_uri] ||= TOKEN_CRED_URI options[:authorization_uri] ||= AUTHORIZATION_URI @project_id = options[:project_id] - @project_id ||= self.class.load_gcloud_project_id + @project_id ||= CredentialsLoader.load_gcloud_project_id super(options) end diff --git a/lib/googleauth/version.rb b/lib/googleauth/version.rb index b348104..364411c 100644 --- a/lib/googleauth/version.rb +++ b/lib/googleauth/version.rb @@ -31,6 +31,6 @@ module Google # Module Auth provides classes that provide Google-specific authorization # used to access Google APIs. module Auth - VERSION = '0.7.0'.freeze + VERSION = '0.7.1'.freeze end end diff --git a/spec/googleauth/user_refresh_spec.rb b/spec/googleauth/user_refresh_spec.rb index fbb4443..d38ca53 100644 --- a/spec/googleauth/user_refresh_spec.rb +++ b/spec/googleauth/user_refresh_spec.rb @@ -221,7 +221,7 @@ describe Google::Auth::UserRefreshCredentials do ENV['HOME'] = dir ENV['APPDATA'] = dir ENV[PROJECT_ID_VAR] = nil - expect(@clz).to receive(:load_gcloud_project_id).with(no_args) + expect(Google::Auth::CredentialsLoader).to receive(:load_gcloud_project_id).with(no_args) @clz.from_well_known_path(@scope) end end