Module: Fog::OpenStack::Common

Instance Attribute Summary collapse

Attributes included from Core

#auth_token, #auth_token_expiration, #current_tenant, #current_user, #current_user_id, #openstack_cache_ttl, #openstack_domain_id, #openstack_domain_name, #openstack_identity_prefix, #openstack_project_domain, #openstack_project_domain_id, #openstack_project_id, #openstack_user_domain, #openstack_user_domain_id

Instance Method Summary collapse

Methods included from Core

#credentials, #initialize_identity, #reload

Instance Attribute Details

#unscoped_tokenObject (readonly)

Returns the value of attribute unscoped_token.



4
5
6
# File 'lib/fog/openstack/common.rb', line 4

def unscoped_token
  @unscoped_token
end

Instance Method Details

#request(params) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fog/openstack/common.rb', line 8

def request(params)
  retried = false
  begin
    std_headers   = {
        'Content-Type' => 'application/json',
        'Accept'       => 'application/json',
        'X-Auth-Token' => @auth_token
    }
    param_headers = params.fetch(:headers, {})

    response = @connection.request(params.merge({
                                                    :headers => std_headers.merge(param_headers),
                                                    :path    => "#{@path}/#{params[:path]}"
                                                }))
  rescue Excon::Errors::Unauthorized => error
    raise if retried
    retried = true

    @openstack_must_reauthenticate = true
    authenticate
    retry
  rescue Excon::Errors::HTTPStatusError => error
    raise case error
            when Excon::Errors::NotFound
              self.class.not_found_class.slurp(error)
            else
              error
          end
  end
  unless response.body.empty?
    response.body = Fog::JSON.decode(response.body) unless params[:raw_body]
  end
  response
end