Memoizes on_gce?

- also fixes an error in the gemspec.
This commit is contained in:
Tim Emiola 2015-02-11 20:52:47 -08:00
parent eea40d1d1e
commit e01b14cba8
2 changed files with 18 additions and 12 deletions

View File

@ -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'

View File

@ -29,6 +29,7 @@
require 'faraday'
require 'googleauth/signet'
require 'memoist'
module Google
# Module Auth provides classes that provide Google-specific authorization
@ -43,9 +44,11 @@ module Google
'instance/service-accounts/default/token'
COMPUTE_CHECK_URI = 'http://169.254.169.254'
class << self
extend Memoist
# Detect if this appear to be a GCE instance, by checking if metadata
# is available
def self.on_gce?(options = {})
def on_gce?(options = {})
c = options[:connection] || Faraday.default_connection
resp = c.get(COMPUTE_CHECK_URI)
return false unless resp.status == 200
@ -54,6 +57,8 @@ module Google
rescue Faraday::ConnectionFailed
return false
end
memoize :on_gce?
end
# Overrides the super class method to change how access tokens are
# fetched.