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



61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
# File 'lib/fog/openstack/auth/token/v3.rb', line 61

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

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

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

#pathObject



40
41
42
# File 'lib/fog/openstack/auth/token/v3.rb', line 40

def path
  '/v3/auth/tokens'
end

#scopeObject



44
45
46
47
# File 'lib/fog/openstack/auth/token/v3.rb', line 44

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

#set(response) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fog/openstack/auth/token/v3.rb', line 49

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