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

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

Constant Summary collapse

DOMAIN_ID =

Default Domain ID

'default'

Instance Attribute Summary collapse

Attributes included from Misty::Auth::Token

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

Instance Method Summary collapse

Methods included from Misty::Auth::Token

build, #get, #initialize

Methods included from HTTP::NetHTTP

http_request

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



9
10
11
# File 'lib/misty/auth/token/v3.rb', line 9

def domain
  @domain
end

#projectObject (readonly)

Returns the value of attribute project.



9
10
11
# File 'lib/misty/auth/token/v3.rb', line 9

def project
  @project
end

Instance Method Details

#credentialsObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/misty/auth/token/v3.rb', line 14

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



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

def path
  '/v3/auth/tokens'
end

#scopeObject

Raises:

  • (DomainScopeError)


38
39
40
41
42
# File 'lib/misty/auth/token/v3.rb', line 38

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

#set(response) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/misty/auth/token/v3.rb', line 44

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

#set_credentials(auth) ⇒ Object



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
90
91
92
93
# File 'lib/misty/auth/token/v3.rb', line 52

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