Class: Misty::Auth::Token::V3

Inherits:
Object
  • Object
show all
Includes:
Misty::Auth::Token
Defined in:
lib/misty/auth/token/v3.rb

Constant Summary

Constants included from Misty::Auth::Token

DOMAIN_ID

Instance Attribute Summary

Attributes included from Misty::Auth::Token

#catalog, #token

Instance Method Summary collapse

Methods included from Misty::Auth::Token

build, #get, #initialize

Methods included from HTTP::NetHTTP

http_request

Instance Method Details

#credentialsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/misty/auth/token/v3.rb', line 10

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

#pathObject



30
31
32
# File 'lib/misty/auth/token/v3.rb', line 30

def path
  '/v3/auth/tokens'
end

#scopeObject

Raises:

  • (DomainScopeError)


34
35
36
37
38
# File 'lib/misty/auth/token/v3.rb', line 34

def scope
  return @project.identity if @project
  return @domain.identity if @domain
  raise DomainScopeError, "#{self.class}: No scope available"
end

#set(response) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/misty/auth/token/v3.rb', line 40

def set(response)
  payload = JSON.load(response.body)
  @token = response['x-subject-token']
  @expires = payload['token']['expires_at']
  catalog = payload['token']['catalog']
  @catalog = Misty::Auth::Catalog::V3.new(catalog)
end

#set_credentials(auth) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
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
# File 'lib/misty/auth/token/v3.rb', line 48

def set_credentials(auth)
  if auth[:project_id] || auth[:project]
    @project = Misty::Auth::ProjectScope.new(auth[:project_id], auth[:project])

    if auth[:project_domain_id] || auth[:project_domain]
      @project.domain = Misty::Auth::Name.new(auth[:project_domain_id], auth[:project_domain])
    else
      if auth[:domain_id] || auth[:domain]
        @project.domain = Misty::Auth::Name.new(auth[:domain_id], auth[:domain])
      else
        @project.domain = Misty::Auth::Name.new(DOMAIN_ID, nil)
      end
    end
  else
    # scope: domain
    if auth[:domain_id] || auth[:domain]
      @domain = Misty::Auth::DomainScope.new(auth[:domain_id], auth[:domain])
    else
      # Use default Domain
      @domain = Misty::Auth::DomainScope.new(DOMAIN_ID, nil)
    end
  end

  if auth[:token]
    @token = auth[:token]
  else
    @user = Misty::Auth::User.new(auth[:user_id], auth[:user])
    @user.password = auth[:password]

    if auth[:user_domain_id] || auth[:user_domain]
      @user.domain = Misty::Auth::Name.new(auth[:user_domain_id], auth[:user_domain])
    else
      if auth[:domain_id] || auth[:domain]
        @user.domain = Misty::Auth::Name.new(auth[:domain_id], auth[:domain])
      else
        @user.domain = Misty::Auth::Name.new(DOMAIN_ID, nil)
      end
    end
  end

  credentials
end