module Ropenstack::Identity::Version2
-
Name: IdentityVersion2
-
Description: An implementation of the V2.0
Identity
API Client in Ruby -
Author: Sam ‘Tehsmash’ Betts, John Davidge
-
Date: 30/06/2014
Public Instance Methods
Add an endpoint list
# File lib/ropenstack/identity/v2.rb, line 146 def add_endpoint(region, service_id, publicurl, adminurl, internalurl) data = { 'endpoint' => { 'region' => region, 'service_id' => service_id, 'publicurl' => publicurl, 'adminurl' => adminurl, 'internalurl' => internalurl } } return post_request(address("/endpoints"), data, token()) end
Add a service to the keystone services directory
# File lib/ropenstack/identity/v2.rb, line 125 def add_to_services(name, type, description) data = { 'OS-KSADM:service' => { 'name' => name, 'type' => type, 'description' => description } } return post_request(address("/OS-KSADM/services"), data, token()) end
# File lib/ropenstack/identity/v2.rb, line 170 def address(endpoint) super("/v2.0/" + endpoint) end
Returns true if a user is admin.
# File lib/ropenstack/identity/v2.rb, line 89 def admin() @data["access"]["user"]["roles"].each do |role| if role["name"].eql?("admin") return true end end return false end
Authenticate via keystone, unless a token and tenant are defined then a unscoped token is returned with all associated data and stored in the @data variable. Does not return anything, but all data is accessible through accessor methods.
# File lib/ropenstack/identity/v2.rb, line 14 def authenticate(username, password, tenant = nil) data = { "auth" => { "passwordCredentials" => { "username" => username, "password" => password } } } unless tenant.nil? data["auth"]["tenantName"] = tenant end @data = post_request(address("/tokens"), data, @token) end
Get the endpoint list
# File lib/ropenstack/identity/v2.rb, line 162 def get_endpoints(token = nil) if token.nil? return get_request(address("/endpoints"), token()) else return get_request(address("/tokens/#{token}/endpoints"), token()) end end
Get list of services
# File lib/ropenstack/identity/v2.rb, line 139 def get_services() return get_request(address("/OS-KSADM/services"), token()) end
Return the raw @data hash with all the data from authentication.
# File lib/ropenstack/identity/v2.rb, line 49 def raw() return @data end
Scope token provides two ways to call it:
scope_token(tenantName) => Just using the current token and a tenantName it scopes in the token. Token stays the same. scope_token(username, password, tenantName) => This uses the username and password to reauthenticate with a tenant. The token changes.
# File lib/ropenstack/identity/v2.rb, line 37 def scope_token(para1, para2 = nil, para3 = nil) if ( para2.nil? ) data = { "auth" => { "tenantName" => para1, "token" => { "id" => token() } } } @data = post_request(address("/tokens"), data, token()) else authenticate(para1, para2, token(), para3) end end
Get the service catalog returned by Identity
on authentication.
# File lib/ropenstack/identity/v2.rb, line 101 def services() return @data["access"]["serviceCatalog"] end
Get the tenant id from the @data
# File lib/ropenstack/identity/v2.rb, line 108 def tenant_id() return @data["access"]["token"]["tenant"]["id"] end
Separate Identity
Calls
# File lib/ropenstack/identity/v2.rb, line 118 def tenant_list() return get_request(address('/tenants'), token()) end
# File lib/ropenstack/identity/v2.rb, line 112 def tenant_name() return @data["access"]["token"]["tenant"]["name"] end
Gets the authentication token from the hash and returns it as a string.
# File lib/ropenstack/identity/v2.rb, line 56 def token(token = nil) if token.nil? return @data["access"]["token"]["id"] else get_request(address("/tokens/#{token}"), token()) end end
TODO Add head version of tokens call
# File lib/ropenstack/identity/v2.rb, line 67 def token?(token) return false end
This returns the token and all metadata associated with the token, including the tenant information.
# File lib/ropenstack/identity/v2.rb, line 75 def token_metadata() return @data["access"]["token"] end
Return the user hash from the authentication data
# File lib/ropenstack/identity/v2.rb, line 82 def user() return @data["access"]["user"] end
# File lib/ropenstack/identity/v2.rb, line 174 def version "V2" end