diff --git a/googleauth.gemspec b/googleauth.gemspec index cb84e39..55a8a84 100755 --- a/googleauth.gemspec +++ b/googleauth.gemspec @@ -5,7 +5,7 @@ require 'googleauth/version' Gem::Specification.new do |s| s.name = 'googleauth' - s.version = GoogleAuth::VERSION + s.version = Google::Auth::VERSION s.authors = ['Tim Emiola'] s.email = 'temiola@google.com' s.homepage = 'https://github.com/google/google-auth-library-ruby' @@ -13,7 +13,7 @@ Gem::Specification.new do |s| s.description = <<-eos Allows simple authorization for accessing Google APIs. Provide support Application Default Credentials, as described at - https://developers.google.com/accounts/docs/application-default-credentials + https://developers.google.com/accounts/xdocs/application-default-credentials eos s.files = `git ls-files`.split("\n") @@ -27,6 +27,7 @@ Gem::Specification.new do |s| s.add_dependency 'faraday', '~> 0.9' s.add_dependency 'logging', '~> 1.8' s.add_dependency 'jwt', '~> 1.2.1' + s.add_dependency 'memoist', '~> 0.11.0' s.add_dependency 'multi_json', '1.10.1' s.add_dependency 'signet', '~> 0.6.0' diff --git a/lib/googleauth/compute_engine.rb b/lib/googleauth/compute_engine.rb index 5dab27c..5e1d503 100644 --- a/lib/googleauth/compute_engine.rb +++ b/lib/googleauth/compute_engine.rb @@ -29,6 +29,7 @@ require 'faraday' require 'googleauth/signet' +require 'memoist' module Google # Module Auth provides classes that provide Google-specific authorization @@ -43,16 +44,20 @@ module Google 'instance/service-accounts/default/token' COMPUTE_CHECK_URI = 'http://169.254.169.254' - # Detect if this appear to be a GCE instance, by checking if metadata - # is available - def self.on_gce?(options = {}) - c = options[:connection] || Faraday.default_connection - resp = c.get(COMPUTE_CHECK_URI) - return false unless resp.status == 200 - return false unless resp.headers.key?('Metadata-Flavor') - return resp.headers['Metadata-Flavor'] == 'Google' - rescue Faraday::ConnectionFailed - return false + class << self + extend Memoist + # Detect if this appear to be a GCE instance, by checking if metadata + # is available + def on_gce?(options = {}) + c = options[:connection] || Faraday.default_connection + resp = c.get(COMPUTE_CHECK_URI) + return false unless resp.status == 200 + return false unless resp.headers.key?('Metadata-Flavor') + return resp.headers['Metadata-Flavor'] == 'Google' + rescue Faraday::ConnectionFailed + return false + end + memoize :on_gce? end # Overrides the super class method to change how access tokens are