Class: Openstack::Client::Authenticator
- Inherits:
-
Object
- Object
- Openstack::Client::Authenticator
- Includes:
- ActiveModel::Model, Helpers::CacheReaderable
- Defined in:
- lib/openstack/client/authenticator.rb,
lib/openstack/client/authenticator/request.rb
Overview
:reek:IrresponsibleModule
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #authenticate ⇒ Object
- #authenticate_request ⇒ Object
-
#initialize(username:, password:, uri: Rails.application.config.x.openstack.fetch(:authentication_url), cache: Rails.cache) ⇒ Authenticator
constructor
A new instance of Authenticator.
- #token ⇒ Object
Methods included from Helpers::CacheReaderable
#cache_key, #null_cache_placeholder, #read_from_cache
Constructor Details
#initialize(username:, password:, uri: Rails.application.config.x.openstack.fetch(:authentication_url), cache: Rails.cache) ⇒ Authenticator
Returns a new instance of Authenticator.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/openstack/client/authenticator.rb', line 19 def initialize( username:, password:, uri: Rails.application.config.x.openstack.fetch(:authentication_url), cache: Rails.cache ) @username = username @password = password @uri = URI(uri) @cache = cache end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
10 11 12 |
# File 'lib/openstack/client/authenticator.rb', line 10 def cache @cache end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
10 11 12 |
# File 'lib/openstack/client/authenticator.rb', line 10 def password @password end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
10 11 12 |
# File 'lib/openstack/client/authenticator.rb', line 10 def uri @uri end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
10 11 12 |
# File 'lib/openstack/client/authenticator.rb', line 10 def username @username end |
Instance Method Details
#authenticate ⇒ Object
31 32 33 34 |
# File 'lib/openstack/client/authenticator.rb', line 31 def authenticate cache_response if token_expired? authentication_succeed? end |
#authenticate_request ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/openstack/client/authenticator.rb', line 36 def authenticate_request return unless block_given? authenticate yield.tap do |request| request.add_field('x-auth-token', token) end end |
#token ⇒ Object
45 46 47 |
# File 'lib/openstack/client/authenticator.rb', line 45 def token read_from_cache.fetch('token') end |