Class: Misty::AuthV3

Inherits:
Object
  • Object
show all
Includes:
Auth
Defined in:
lib/misty/auth/auth_v3.rb

Instance Attribute Summary

Attributes included from Auth

#catalog, #token

Instance Method Summary collapse

Methods included from Auth

#authenticate, #expired?, factory, #find_url, #get_service, #get_token, #get_url, #initialize

Methods included from HTTP::NetHTTP

http_request

Instance Method Details

#credentialsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/misty/auth/auth_v3.rb', line 7

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

#endpoint_url(endpoint, region_id, interface) ⇒ Object



27
28
29
# File 'lib/misty/auth/auth_v3.rb', line 27

def endpoint_url(endpoint, region_id, interface)
  return endpoint['url'] if endpoint['region_id'] == region_id && endpoint['interface'] == interface
end

#pathObject



31
32
33
# File 'lib/misty/auth/auth_v3.rb', line 31

def path
  '/v3/auth/tokens'
end

#scopeObject

Raises:



35
36
37
38
39
# File 'lib/misty/auth/auth_v3.rb', line 35

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

#set(response) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/misty/auth/auth_v3.rb', line 41

def set(response)
  payload = JSON.load(response.body)
  token = response['x-subject-token']
  catalog = payload['token']['catalog']
  expires = payload['token']['expires_at']
  [token, catalog, expires]
end

#set_credentials(auth) ⇒ Object



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
# File 'lib/misty/auth/auth_v3.rb', line 49

def set_credentials(auth)
  if auth[:project_id] || auth[:project]
    # scope: project
    project_domain_id = auth[:project_domain_id]
    if project_domain_id.nil? && auth[:project_domain].nil?
      project_domain_id = Misty::DOMAIN_ID
    end

    @project = Misty::Auth::ProjectScope.new(auth[:project_id], auth[:project])
    @project.domain = Misty::Auth::Name.new(project_domain_id, auth[:project_domain])
  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(Misty::DOMAIN_ID, nil)
    end
  end

  if auth[:token]
    @token = auth[:token]
  else
    user_domain_id = auth[:user_domain_id] ? auth[:user_domain_id] : Misty::DOMAIN_ID
    @user = Misty::Auth::User.new(auth[:user_id], auth[:user])
    @user.password = auth[:password]
    @user.domain = Misty::Auth::Name.new(user_domain_id, auth[:user_domain])
  end

  credentials
end