Class: Garage::Strategy::AuthServer::AccessTokenFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/garage/strategy/auth_server.rb

Overview

Returns an AccessToken from request object or returns nil if failed.

Constant Summary collapse

READ_TIMEOUT =
1
OPEN_TIMEOUT =
1
USER_AGENT =
"Garage #{Garage::VERSION}"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ AccessTokenFetcher

Returns a new instance of AccessTokenFetcher.



53
54
55
# File 'lib/garage/strategy/auth_server.rb', line 53

def initialize(request)
  @request = request
end

Class Method Details

.fetch(*args) ⇒ Object



49
50
51
# File 'lib/garage/strategy/auth_server.rb', line 49

def self.fetch(*args)
  new(*args).fetch
end

Instance Method Details

#fetchObject



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/garage/strategy/auth_server.rb', line 57

def fetch
  if has_any_valid_credentials?
    if has_cacheable_credentials?
      fetch_with_cache
    else
      fetch_without_cache
    end
  else
    nil
  end
rescue Timeout::Error
  raise AuthBackendTimeout.new(OPEN_TIMEOUT, read_timeout)
end