module Ropenstack::Identity::Version2

Public Instance Methods

add_endpoint(region, service_id, publicurl, adminurl, internalurl) click to toggle source

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_to_services(name, type, description) click to toggle source

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
address(endpoint) click to toggle source
Calls superclass method
# File lib/ropenstack/identity/v2.rb, line 170
def address(endpoint)
  super("/v2.0/" + endpoint)
end
admin() click to toggle source

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(username, password, tenant = nil) click to toggle source

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_endpoints(token = nil) click to toggle source

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_services() click to toggle source

Get list of services

# File lib/ropenstack/identity/v2.rb, line 139
def get_services()
        return get_request(address("/OS-KSADM/services"), token())
end
raw() click to toggle source

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(para1, para2 = nil, para3 = nil) click to toggle source

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
services() click to toggle source

Get the service catalog returned by Identity on authentication.

# File lib/ropenstack/identity/v2.rb, line 101
def services()
        return @data["access"]["serviceCatalog"]
end
tenant_id() click to toggle source

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
tenant_list() click to toggle source

Separate Identity Calls

# File lib/ropenstack/identity/v2.rb, line 118
def tenant_list()
        return get_request(address('/tenants'), token()) 
end
tenant_name() click to toggle source
# File lib/ropenstack/identity/v2.rb, line 112
def tenant_name()
        return @data["access"]["token"]["tenant"]["name"] 
end
token(token = nil) click to toggle source

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
token?(token) click to toggle source

TODO Add head version of tokens call

# File lib/ropenstack/identity/v2.rb, line 67
def token?(token)
        return false
end
token_metadata() click to toggle source

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
user() click to toggle source

Return the user hash from the authentication data

# File lib/ropenstack/identity/v2.rb, line 82
def user()
        return @data["access"]["user"]
end
version() click to toggle source
# File lib/ropenstack/identity/v2.rb, line 174
def version
  "V2"
end