Class: OpenStack::Keystone::Public::Auth

Inherits:
Base show all
Defined in:
lib/open_stack/keystone/public/auth.rb

Overview

End user authentication

Defined Under Namespace

Classes: Token

Instance Method Summary collapse

Methods inherited from Base

headers

Methods inherited from ActiveResource::Base

#load

Constructor Details

#initialize(attributes = {}, persisted = false) ⇒ Auth

:notnew:



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/open_stack/keystone/public/auth.rb', line 35

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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/open_stack/keystone/public/auth.rb', line 49

def encode(options={}) #: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}", options)
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)



120
121
122
# File 'lib/open_stack/keystone/public/auth.rb', line 120

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)



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/open_stack/keystone/public/auth.rb', line 98

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

#saveObject

:nodoc: Catch some exceptions to perform “remote validation” of this resource



71
72
73
74
75
76
# File 'lib/open_stack/keystone/public/auth.rb', line 71

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_catalogObject

Returns the service catalog for current authentication



79
80
81
# File 'lib/open_stack/keystone/public/auth.rb', line 79

def service_catalog
  @attributes[:serviceCatalog].is_a?(Array) ? @attributes[:serviceCatalog] : []
end

#tokenObject

Returns the OpenStack::Keystone::Public::Auth::Token instance for current authentication



84
85
86
# File 'lib/open_stack/keystone/public/auth.rb', line 84

def token
  @attributes[:token]
end

#token_idObject

Returns the token_id (string) for current authentication



89
90
91
# File 'lib/open_stack/keystone/public/auth.rb', line 89

def token_id
  token.id if token.present?
end