Class: OpenStack::Keystone::Public::Auth
- Inherits:
-
Base
- Object
- ActiveResource::Base
- Base
- OpenStack::Keystone::Public::Auth
- Defined in:
- lib/open_stack/keystone/public/auth.rb
Overview
End user authentication
Defined Under Namespace
Classes: Token
Instance Method Summary collapse
-
#encode(options = {}) ⇒ Object
Overloads ActiveRecord::encode method.
-
#endpoint_for(endpoint_type, region = nil) ⇒ Object
Returns the first endpoint for current authentication and for a given endpoint_type and region.
-
#endpoints_for(endpoint_type, region = nil) ⇒ Object
Returns the list of endpoint for current authentication and for a given endpoint_type and region.
-
#initialize(attributes = {}, persisted = false) ⇒ Auth
constructor
:notnew:.
-
#save ⇒ Object
:nodoc: Catch some exceptions to perform “remote validation” of this resource.
-
#service_catalog ⇒ Object
Returns the service catalog for current authentication.
-
#token ⇒ Object
Returns the OpenStack::Keystone::Public::Auth::Token instance for current authentication.
-
#token_id ⇒ Object
Returns the token_id (string) for current authentication.
Methods inherited from Base
Methods inherited from ActiveResource::Base
Constructor Details
#initialize(attributes = {}, persisted = false) ⇒ Auth
:notnew:
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/open_stack/keystone/public/auth.rb', line 39 def initialize(attributes = {}, persisted = false) # :notnew: attributes[:username] ||= "" attributes[:password] ||= "" if attributes[:tenant].present? attributes[:tenant_id] = attributes[:tenant].id elsif attributes[:tenant_id].present? attributes[:tenant_id] = attributes[:tenant_id] end super(attributes, persisted) end |
Instance Method Details
#encode(options = {}) ⇒ Object
Overloads ActiveRecord::encode method
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/open_stack/keystone/public/auth.rb', line 53 def encode(={}) # :nodoc: Custom encoding to deal with openstack API to_encode = {} if token.present? to_encode[:auth] = { :token => { :id => token_id } } else to_encode[:auth] = { :passwordCredentials => { :username => username, :password => password } } end to_encode[:auth][:tenantId] = tenant_id if @attributes[:tenant_id].present? to_encode.send("to_#{self.class.format.extension}", ) end |
#endpoint_for(endpoint_type, region = nil) ⇒ Object
Returns the first endpoint for current authentication and for a given endpoint_type and region
Attributes
-
endpoint_type
- The type of endpoint. Currently valid values are: “Compute”, “Volume” -
region
- Restrict the search to given a region (can be omitted)
124 125 126 |
# File 'lib/open_stack/keystone/public/auth.rb', line 124 def endpoint_for(endpoint_type, region=nil) endpoints_for(endpoint_type, region)[0] end |
#endpoints_for(endpoint_type, region = nil) ⇒ Object
Returns the list of endpoint for current authentication and for a given endpoint_type and region
Attributes
-
endpoint_type
- The type of endpoint. Currently valid values are: “Compute”, “Volume” -
region
- Restrict the search to given a region (can be omitted)
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/open_stack/keystone/public/auth.rb', line 102 def endpoints_for(endpoint_type, region=nil) return [] unless service_catalog.present? endpoints = [] service_catalog.each { |c| next if c.attributes[:type] != endpoint_type c.endpoints.each { |e| if region.nil? or e.region == region endpoints << e end } } endpoints end |
#save ⇒ Object
:nodoc: Catch some exceptions to perform “remote validation” of this resource
75 76 77 78 79 80 |
# File 'lib/open_stack/keystone/public/auth.rb', line 75 def save # :nodoc: Catch some exceptions to perform "remote validation" of this resource super rescue ActiveResource::UnauthorizedAccess errors.add :password, I18n.t(:is_invalid) return false end |
#service_catalog ⇒ Object
Returns the service catalog for current authentication
83 84 85 |
# File 'lib/open_stack/keystone/public/auth.rb', line 83 def service_catalog @attributes[:serviceCatalog].is_a?(Array) ? @attributes[:serviceCatalog] : [] end |
#token ⇒ Object
Returns the OpenStack::Keystone::Public::Auth::Token instance for current authentication
88 89 90 |
# File 'lib/open_stack/keystone/public/auth.rb', line 88 def token @attributes[:token] end |
#token_id ⇒ Object
Returns the token_id (string) for current authentication
93 94 95 |
# File 'lib/open_stack/keystone/public/auth.rb', line 93 def token_id token.id if token.present? end |