Class: Misty::Auth::Token::V2
- Inherits:
-
Object
- Object
- Misty::Auth::Token::V2
- Includes:
- Misty::Auth::Token
- Defined in:
- lib/misty/auth/token/v2.rb
Constant Summary
Constants included from Misty::Auth::Token
Instance Attribute Summary
Attributes included from Misty::Auth::Token
Instance Method Summary collapse
- #credentials ⇒ Object
- #path ⇒ Object
- #set(response) ⇒ Object
- #set_credentials(auth) ⇒ Object
- #user_credentials ⇒ Object
Methods included from Misty::Auth::Token
Methods included from HTTP::NetHTTP
Instance Method Details
#credentials ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/misty/auth/token/v2.rb', line 10 def credentials if @token identity = { 'token': { 'id': @token } } else raise CredentialsError, "#{self.class}: User name is required" if @user.name.nil? raise CredentialsError, "#{self.class}: User password is required" if @user.password.nil? identity = { 'passwordCredentials': user_credentials } end if @tenant.id identity.merge!('tenantId': @tenant.id) elsif @tenant.name identity.merge!('tenantName': @tenant.name) else raise CredentialsError, "#{self.class}: No tenant available" end { 'auth': identity } end |
#path ⇒ Object
30 31 32 |
# File 'lib/misty/auth/token/v2.rb', line 30 def path '/v2.0/tokens' end |
#set(response) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/misty/auth/token/v2.rb', line 41 def set(response) payload = JSON.load(response.body) @token = payload['access']['token']['id'] @expires = payload['access']['token']['expires'] catalog = payload['access']['serviceCatalog'] @catalog = Misty::Auth::Catalog::V2.new(catalog) end |
#set_credentials(auth) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/misty/auth/token/v2.rb', line 49 def set_credentials(auth) if auth[:token] @token = auth[:token] else @user = Misty::Auth::User.new(auth[:user_id], auth[:user]) @user.password = auth[:password] end @tenant = Misty::Auth::Name.new(auth[:tenant_id], auth[:tenant]) credentials end |
#user_credentials ⇒ Object
34 35 36 37 38 39 |
# File 'lib/misty/auth/token/v2.rb', line 34 def user_credentials { 'username': @user.name, 'password': @user.password } end |