class Openstack::Client

Defines OpenStack client behaviours.

:reek: IrresponsibleModule

:reek: IrresponsibleModule

:reek: IrresponsibleModule

:reek: IrresponsibleModule

:reek: IrresponsibleModule

:reek: IrresponsibleModule

:reek: IrresponsibleModule

:reek: IrresponsibleModule

:reek: IrresponsibleModule

:reek: IrresponsibleModule

:reek: IrresponsibleModule

Attributes

cache[R]
password[R]
username[R]

Public Class Methods

new(username:, password:, cache: Rails.cache) click to toggle source
# File lib/openstack/client.rb, line 16
def initialize(username:, password:, cache: Rails.cache)
  @username = username
  @password = password
  @cache = cache
end

Public Instance Methods

absolute_uri(key) click to toggle source
# File lib/openstack/client/storage.rb, line 121
def absolute_uri(key)
  URI("#{uri}/#{key}")
end
authenticator() click to toggle source
# File lib/openstack/client.rb, line 22
def authenticator
  @authenticator ||= Authenticator.new(
    username: username,
    password: password,
    cache: cache
  )
end
storage(container:, region:) click to toggle source
# File lib/openstack/client.rb, line 30
def storage(container:, region:)
  @storage ||= Storage.new(
    authenticator: authenticator,
    container: container,
    region: region
  )
end
token() click to toggle source
# File lib/openstack/client/authenticator.rb, line 45
def token
  read_from_cache.fetch('token')
end

Private Instance Methods

authentication_succeed?() click to toggle source
# File lib/openstack/client/authenticator.rb, line 61
def authentication_succeed?
  case read_from_cache.fetch('code')
  when 201
    true
  else
    false
  end
end
cache_response() click to toggle source
# File lib/openstack/client/authenticator.rb, line 51
def cache_response
  cache.write(cache_key, request.body_to_cache)
end
credentials() click to toggle source
# File lib/openstack/client/authenticator.rb, line 77
def credentials
  OpenStruct.new(username: username, password: password)
end
request() click to toggle source
# File lib/openstack/client/authenticator.rb, line 70
def request
  @request ||= Request.new(
    credentials: credentials,
    uri: uri
  ).call.extend(Helpers::CacheableBody)
end
token_expired?() click to toggle source
# File lib/openstack/client/authenticator.rb, line 55
def token_expired?
  read_from_cache.fetch('expires_at') < Time.now
rescue TypeError, NoMethodError
  true
end