class Occi::Api::Client::Http::AuthnPlugins::KeystoneV3
Public Class Methods
new(base_url, env_ref, options = {})
click to toggle source
# File lib/occi/api/client/http/authn_plugins/keystone.rb, line 189 def initialize(base_url, env_ref, options = {}) @base_url = base_url @env_ref = env_ref @options = options end
Public Instance Methods
get_first_working_project()
click to toggle source
# File lib/occi/api/client/http/authn_plugins/keystone.rb, line 237 def get_first_working_project response = @env_ref.class.get( "#{@base_url}/auth/projects", :headers => get_req_headers ) Occi::Api::Log.debug response.inspect raise ::Occi::Api::Client::Errors::AuthnError, "Keystone didn't return any projects, fallback failed!" if response['projects'].blank? response['projects'].each do |project| begin Occi::Api::Log.debug "Authenticating for project #{project['name'].inspect}" set_scoped_token(project['id']) # found a working project, stop looking break rescue ::Occi::Api::Client::Errors::AuthnError # ignoring and trying the next tenant end end end
get_req_headers()
click to toggle source
# File lib/occi/api/client/http/authn_plugins/keystone.rb, line 288 def get_req_headers headers = @env_ref.class.headers.clone headers['Content-Type'] = "application/json" headers['Accept'] = headers['Content-Type'] headers end
passwd_authenticate(tenant = nil)
click to toggle source
# File lib/occi/api/client/http/authn_plugins/keystone.rb, line 207 def passwd_authenticate(tenant = nil) raise ::Occi::Api::Client::Errors::AuthnError, "Needs to be implemented, check http://developer.openstack.org/api-ref-identity-v3.html#authenticatePasswordUnscoped" end
set_auth_token(tenant = nil)
click to toggle source
# File lib/occi/api/client/http/authn_plugins/keystone.rb, line 195 def set_auth_token(tenant = nil) if @options[:original_type] == "x509" voms_authenticate(tenant) elsif @options[:username] && @options[:password] passwd_authenticate(tenant) else raise ::Occi::Api::Client::Errors::AuthnError, "Unable to request a token from Keystone! Chosen " "AuthN is not supported, fallback failed!" end end
set_scoped_token(project)
click to toggle source
# File lib/occi/api/client/http/authn_plugins/keystone.rb, line 260 def set_scoped_token(project) body = { "auth" => { "identity" => { "methods" => ["token"], "token" => {"id" => @env_ref.class.headers['X-Auth-Token'] } }, "scope" => { "project" => {"id" => project} } } } response = @env_ref.class.post( "#{@base_url}/auth/tokens", :body => body.to_json, :headers => get_req_headers ) Occi::Api::Log.debug response.inspect if response.success? @env_ref.class.headers['X-Auth-Token'] = response.headers['x-subject-token'] else raise ::Occi::Api::Client::Errors::AuthnError, "Unable to get a token from Keystone, fallback failed!" end end
set_voms_unscoped_token()
click to toggle source
# File lib/occi/api/client/http/authn_plugins/keystone.rb, line 222 def set_voms_unscoped_token response = @env_ref.class.post( # egi.eu and mapped below should be configurable "#{@base_url}/OS-FEDERATION/identity_providers/egi.eu/protocols/mapped/auth", ) Occi::Api::Log.debug response.inspect if response.success? @env_ref.class.headers['X-Auth-Token'] = response.headers['x-subject-token'] else raise ::Occi::Api::Client::Errors::AuthnError, "Unable to get a token from Keystone, fallback failed!" end end
voms_authenticate(tenant = nil)
click to toggle source
# File lib/occi/api/client/http/authn_plugins/keystone.rb, line 212 def voms_authenticate(tenant = nil) set_voms_unscoped_token if !tenant.blank? set_scoped_token(tenant) else get_first_working_project end end