module Fog::OpenStack::Auth::Token

Attributes

catalog[R]
data[R]
expires[R]
tenant[R]
token[R]
user[R]

Public Class Methods

build(auth, options) click to toggle source
# File lib/fog/openstack/auth/token.rb, line 16
def self.build(auth, options)
  if auth[:openstack_identity_api_version] =~ /(v)*2(\.0)*/i ||
     auth[:openstack_tenant_id] || auth[:openstack_tenant]
    Fog::OpenStack::Auth::Token::V2.new(auth, options)
  else
    Fog::OpenStack::Auth::Token::V3.new(auth, options)
  end
end
new(auth, options) click to toggle source
# File lib/fog/openstack/auth/token.rb, line 25
def initialize(auth, options)
  raise URLError, 'No URL provided' if auth[:openstack_auth_url].nil? || auth[:openstack_auth_url].empty?
  @creds = {
    :data => build_credentials(auth),
    :uri  => URI.parse(auth[:openstack_auth_url])
  }
  response = authenticate(@creds, options)
  set(response)
end

Public Instance Methods

get() click to toggle source
# File lib/fog/openstack/auth/token.rb, line 35
def get
  set(authenticate(@creds, {})) if expired?
  @token
end

Private Instance Methods

authenticate(creds, options) click to toggle source
# File lib/fog/openstack/auth/token.rb, line 42
def authenticate(creds, options)
  connection = Fog::Core::Connection.new(creds[:uri].to_s, false, options)

  headers = {
    'Accept'       => 'application/json',
    'Content-Type' => 'application/json'
  }
  request_options = {
    :expects => [200, 201],
    :headers => headers,
    :body    => Fog::JSON.encode(creds[:data]),
    :method  => 'POST',
    :path    => creds[:uri].path + prefix_path(creds[:uri]) + path
  }

  connection.request(request_options)
end
expired?() click to toggle source
# File lib/fog/openstack/auth/token.rb, line 60
def expired?
  if @expires.nil? || @expires.empty?
    raise ExpiryError, 'Missing token expiration data'
  end
  Time.parse(@expires) < Time.now.utc
end
refresh() click to toggle source
# File lib/fog/openstack/auth/token.rb, line 67
def refresh
  raise StandardError, "__method__ not implemented yet!"
end