Class: Fog::OpenStack::Auth::Token::V3

Inherits:
Object
  • Object
show all
Includes:
Fog::OpenStack::Auth::Token
Defined in:
lib/fog/openstack/auth/token/v3.rb

Constant Summary collapse

DOMAIN_ID =

Default Domain ID

'default'.freeze

Instance Attribute Summary collapse

Attributes included from Fog::OpenStack::Auth::Token

#catalog, #data, #expires, #tenant, #token, #user

Instance Method Summary collapse

Methods included from Fog::OpenStack::Auth::Token

build, #get, #initialize

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



10
11
12
# File 'lib/fog/openstack/auth/token/v3.rb', line 10

def domain
  @domain
end

#projectObject (readonly)

Returns the value of attribute project.



10
11
12
# File 'lib/fog/openstack/auth/token/v3.rb', line 10

def project
  @project
end

Instance Method Details

#build_credentials(auth) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/fog/openstack/auth/token/v3.rb', line 75

def build_credentials(auth)
  if auth[:openstack_project_id] || auth[:openstack_project_name]
    # project scoped
    @project = Fog::OpenStack::Auth::ProjectScope.new(
      auth[:openstack_project_id],
      auth[:openstack_project_name]
    )
    @project.domain = if auth[:openstack_project_domain_id] || auth[:openstack_project_domain_name]
                        Fog::OpenStack::Auth::Name.new(
                          auth[:openstack_project_domain_id],
                          auth[:openstack_project_domain_name]
                        )
                      elsif auth[:openstack_domain_id] || auth[:openstack_domain_name]
                        Fog::OpenStack::Auth::Name.new(
                          auth[:openstack_domain_id],
                          auth[:openstack_domain_name]
                        )
                      else
                        Fog::OpenStack::Auth::Name.new(DOMAIN_ID, nil)
                      end
  elsif auth[:openstack_domain_id] || auth[:openstack_domain_name]
    # domain scoped
    @domain = Fog::OpenStack::Auth::DomainScope.new(
      auth[:openstack_domain_id],
      auth[:openstack_domain_name]
    )
  end

  if auth[:openstack_auth_token]
    @token = auth[:openstack_auth_token]
  elsif auth[:openstack_application_credential_id] and auth[:openstack_application_credential_secret]
    @application_credential = {
      :id => auth[:openstack_application_credential_id],
      :secret => auth[:openstack_application_credential_secret],
    }
  else
    @user = Fog::OpenStack::Auth::User.new(auth[:openstack_userid], auth[:openstack_username])
    @user.password = auth[:openstack_api_key]

    @user.domain = if auth[:openstack_user_domain_id] || auth[:openstack_user_domain_name]
                     Fog::OpenStack::Auth::Name.new(
                       auth[:openstack_user_domain_id],
                       auth[:openstack_user_domain_name]
                     )
                   elsif auth[:openstack_domain_id] || auth[:openstack_domain_name]
                     Fog::OpenStack::Auth::Name.new(
                       auth[:openstack_domain_id],
                       auth[:openstack_domain_name]
                     )
                   else
                     Fog::OpenStack::Auth::Name.new(DOMAIN_ID, nil)
                   end
  end

  credentials
end

#credentialsObject



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
42
43
# File 'lib/fog/openstack/auth/token/v3.rb', line 15

def credentials
  identity = if @token
               {
                 'methods' => ['token'],
                 'token'   => {'id' => @token}
               }
             elsif @application_credential
               {
                 'methods' => ['application_credential'],
                 'application_credential' => @application_credential
               }
             else
               {
                 'methods'  => ['password'],
                 'password' => @user.identity
               }
             end

  if scope
    {
      'auth' => {
        'identity' => identity,
        'scope'    => scope
      }
    }
  else
    {'auth' => {'identity' => identity}}
  end
end

#pathObject



53
54
55
# File 'lib/fog/openstack/auth/token/v3.rb', line 53

def path
  '/auth/tokens'
end

#prefix_path(uri) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/fog/openstack/auth/token/v3.rb', line 45

def prefix_path(uri)
  if uri.path =~ /\/v3(\/)*.*$/
    ''
  else
    '/v3'
  end
end

#scopeObject



57
58
59
60
61
# File 'lib/fog/openstack/auth/token/v3.rb', line 57

def scope
  return nil if @application_credential
  return @project.identity if @project
  return @domain.identity if @domain
end

#set(response) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/fog/openstack/auth/token/v3.rb', line 63

def set(response)
  @data = Fog::JSON.decode(response.body)
  @token = response.headers['x-subject-token']
  @expires = @data['token']['expires_at']
  @tenant = @data['token']['project']
  @user = @data['token']['user']
  catalog = @data['token']['catalog']
  if catalog
    @catalog = Fog::OpenStack::Auth::Catalog::V3.new(catalog)
  end
end