# File lib/fog/openstack/identity.rb, line 71 def self.data @users ||= {} @roles ||= {} @tenants ||= {} @ec2_credentials ||= Hash.new { |hash, key| hash[key] = {} } @user_tenant_membership ||= {} @data ||= Hash.new do |hash, key| hash[key] = { :users => @users, :roles => @roles, :tenants => @tenants, :ec2_credentials => @ec2_credentials, :user_tenant_membership => @user_tenant_membership } end end
# File lib/fog/openstack/identity.rb, line 97 def initialize(options={}) @openstack_username = options[:openstack_username] || 'admin' @openstack_tenant = options[:openstack_tenant] || 'admin' @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) @openstack_management_url = @openstack_auth_uri.to_s @auth_token = Fog::Mock.random_base64(64) @auth_token_expiration = (Time.now.utc + 86400).iso8601 @admin_tenant = self.data[:tenants].values.find do |u| u['name'] == 'admin' end if @openstack_tenant @current_tenant = self.data[:tenants].values.find do |u| u['name'] == @openstack_tenant end unless @current_tenant @current_tenant_id = Fog::Mock.random_hex(32) @current_tenant = self.data[:tenants][@current_tenant_id] = { 'id' => @current_tenant_id, 'name' => @openstack_tenant } else @current_tenant_id = @current_tenant['id'] end else @current_tenant = @admin_tenant end @current_user = self.data[:users].values.find do |u| u['name'] == @openstack_username end @current_tenant_id = Fog::Mock.random_hex(32) unless @current_user @current_user_id = Fog::Mock.random_hex(32) @current_user = self.data[:users][@current_user_id] = { 'id' => @current_user_id, 'name' => @openstack_username, 'email' => "#{@openstack_username}@mock.com", 'tenantId' => Fog::Mock.random_numbers(6).to_s, 'enabled' => true } else @current_user_id = @current_user['id'] end end
# File lib/fog/openstack/requests/identity/add_user_to_tenant.rb, line 15 def add_user_to_tenant(tenant_id, user_id, role_id) role = self.data[:roles][role_id] self.data[:user_tenant_membership][tenant_id] ||= {} self.data[:user_tenant_membership][tenant_id][user_id] ||= [] self.data[:user_tenant_membership][tenant_id][user_id].push(role['id']).uniq! response = Excon::Response.new response.status = 200 response.body = { 'role' => { 'id' => role['id'], 'name' => role['name'] } } response end
# File lib/fog/openstack/requests/identity/create_ec2_credential.rb, line 38 def create_ec2_credential(user_id, tenant_id) response = Excon::Response.new response.status = 200 data = { 'access' => Fog::Mock.random_hex(32), 'secret' => Fog::Mock.random_hex(32), 'tenant_id' => tenant_id, 'user_id' => user_id, } self.data[:ec2_credentials][user_id][data['access']] = data response.body = { 'credential' => data } response end
# File lib/fog/openstack/requests/identity/create_role.rb, line 22 def create_role(name) data = { 'id' => Fog::Mock.random_hex(32), 'name' => name } self.data[:roles][data['id']] = data Excon::Response.new( :body => { 'role' => data }, :status => 202 ) end
# File lib/fog/openstack/requests/identity/create_tenant.rb, line 16 def create_tenant(attributes) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { 'tenant' => { 'id' => "df9a815161eba9b76cc748fd5c5af73e", 'description' => attributes['description'] || 'normal tenant', 'enabled' => true, 'name' => attributes['name'] || 'default' } } response end
# File lib/fog/openstack/requests/identity/create_user.rb, line 29 def create_user(name, password, email, tenantId=nil, enabled=true) response = Excon::Response.new response.status = 200 data = { 'id' => Fog::Mock.random_hex(32), 'name' => name, 'email' => email, 'tenantId' => tenantId, 'enabled' => enabled } self.data[:users][data['id']] = data response.body = { 'user' => data } response end
# File lib/fog/openstack/requests/identity/create_user_role.rb, line 17 def create_user_role(tenant_id, user_id, role_id) Excon::Response.new( :body => { 'role' => self.data[:roles][role_id] }, :status => 200 ) end
# File lib/fog/openstack/identity.rb, line 155 def credentials { :provider => 'openstack', :openstack_auth_url => @openstack_auth_uri.to_s, :openstack_auth_token => @auth_token, :openstack_management_url => @openstack_management_url, :openstack_current_user_id => @openstack_current_user_id, :current_user => @current_user, :current_tenant => @current_tenant} end
# File lib/fog/openstack/identity.rb, line 147 def data self.class.data[@openstack_username] end
# File lib/fog/openstack/requests/identity/delete_ec2_credential.rb, line 29 def delete_ec2_credential(user_id, access) raise Fog::Identity::OpenStack::NotFound unless self.data[:ec2_credentials][user_id][access] self.data[:ec2_credentials][user_id].delete access response = Excon::Response.new response.status = 204 response rescue end
# File lib/fog/openstack/requests/identity/delete_role.rb, line 18 def delete_role(role_id) response = Excon::Response.new if self.data[:roles][role_id] self.data[:roles].delete(role_id) response.status = 204 response else raise Fog::Identity::OpenStack::NotFound end end
# File lib/fog/openstack/requests/identity/delete_tenant.rb, line 15 def delete_tenant(attributes) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { 'tenant' => { 'id' => '1', 'description' => 'Has access to everything', 'enabled' => true, 'name' => 'admin' } } response end
# File lib/fog/openstack/requests/identity/delete_user.rb, line 18 def delete_user(user_id) self.data[:users].delete( list_users.body['users'].find {|x| x['id'] == user_id }['id']) response = Excon::Response.new response.status = 204 response rescue raise Fog::Identity::OpenStack::NotFound end
# File lib/fog/openstack/requests/identity/delete_user_role.rb, line 17 def delete_user_role(tenant_id, user_id, role_id) response = Excon::Response.new response.status = 204 response end
# File lib/fog/openstack/requests/identity/get_ec2_credential.rb, line 36 def get_ec2_credential(user_id, access) ec2_credential = self.data[:ec2_credentials][user_id][access] raise Fog::OpenStack::Identity::NotFound unless ec2_credential response = Excon::Response.new response.status = 200 response.body = { 'credential' => ec2_credential } response end
# File lib/fog/openstack/requests/identity/get_role.rb, line 15 def get_role(id) response = Excon::Response.new if data = self.data[:roles][id] response.status = 200 response.body = { 'role' => data } response else raise Fog::Identity::OpenStack::NotFound end end
# File lib/fog/openstack/requests/identity/get_tenant.rb, line 15 def get_tenant(id) response = Excon::Response.new response.status = [200, 204][rand(1)] response.body = { 'tenant' => { 'id' => id, 'description' => 'Has access to everything', 'enabled' => true, 'name' => 'admin' } } response end
# File lib/fog/openstack/requests/identity/get_user_by_id.rb, line 17 def get_user_by_id(user_id) response = Excon::Response.new response.status = 200 existing_user = self.data[:users].find do |u| u[0] == user_id || u[1]['name'] == 'mock' end existing_user = existing_user[1] if existing_user response.body = { 'user' => existing_user || create_user('mock', 'mock', 'mock@email.com').body['user'] } response end
# File lib/fog/openstack/requests/identity/get_user_by_name.rb, line 18 def get_user_by_name(name) response = Excon::Response.new response.status = 200 user = self.data[:users].values.select {|user| user['name'] == name}[0] response.body = { 'user' => user } response end
# File lib/fog/openstack/requests/identity/list_ec2_credentials.rb, line 33 def list_ec2_credentials(user_id) ec2_credentials = self.data[:ec2_credentials][user_id].values response = Excon::Response.new response.status = 200 response.body = { 'credentials' => ec2_credentials } response end
# File lib/fog/openstack/requests/identity/list_roles.rb, line 18 def list_roles if self.data[:roles].empty? ['admin', 'Member'].each do |name| id = Fog::Mock.random_hex(32) self.data[:roles][id] = {'id' => id, 'name' => name} end end Excon::Response.new( :body => { 'roles' => self.data[:roles].values }, :status => 200 ) end
# File lib/fog/openstack/requests/identity/list_roles_for_user_on_tenant.rb, line 15 def list_roles_for_user_on_tenant(tenant_id, user_id) self.data[:user_tenant_membership][tenant_id] ||= {} self.data[:user_tenant_membership][tenant_id][user_id] ||= [] roles = self.data[:user_tenant_membership][tenant_id][user_id].map do |role_id| self.data[:roles][role_id] end Excon::Response.new( :body => { 'roles' => roles }, :status => 200 ) end
# File lib/fog/openstack/requests/identity/list_tenants.rb, line 20 def list_tenants Excon::Response.new( :body => { 'tenants_links' => [], 'tenants' => [ {'id' => '1', 'description' => 'Has access to everything', 'enabled' => true, 'name' => 'admin'}, {'id' => '2', 'description' => 'Normal tenant', 'enabled' => true, 'name' => 'default'}, {'id' => '3', 'description' => 'Disabled tenant', 'enabled' => false, 'name' => 'disabled'} ] }, :status => [200, 204][rand(1)] ) end
# File lib/fog/openstack/requests/identity/list_users.rb, line 16 def list_users(tenant_id = nil) users = self.data[:users].values if tenant_id users = users.select { |user| user['tenantId'] == tenant_id } end Excon::Response.new( :body => { 'users' => users }, :status => 200 ) end
# File lib/fog/openstack/requests/identity/remove_user_from_tenant.rb, line 15 def remove_user_from_tenant(tenant_id, user_id, role_id) end
# File lib/fog/openstack/identity.rb, line 151 def reset_data self.class.data.delete(@openstack_username) end
# File lib/fog/openstack/requests/identity/set_tenant.rb, line 14 def set_tenant(tenant) true end
# File lib/fog/openstack/requests/identity/update_tenant.rb, line 16 def update_tenant(id, attributes) response = Excon::Response.new response.status = [200, 204][rand(1)] attributes = {'enabled' => true, 'id' => '1'}.merge(attributes) response.body = { 'tenant' => attributes } response end
# File lib/fog/openstack/requests/identity/update_user.rb, line 20 def update_user(user_id, options) response = Excon::Response.new if user = self.data[:users][user_id] if options['name'] user['name'] = options['name'] end response.status = 200 response else raise Fog::Identity::OpenStack::NotFound end end
Generated with the Darkfish Rdoc Generator 2.