1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Add OpenStack EC2 credentials requests.

This wraps API discovered from python-keystoneclient that allows CRUD
for EC2 credentials for an OpenStack service.  Unfortunately I haven't
been able to find documentation for this API.
This commit is contained in:
Eric Hodel 2012-10-29 14:47:14 -07:00
parent bcfb5fe1df
commit 8c76badfba
6 changed files with 180 additions and 10 deletions

View file

@ -53,6 +53,10 @@ module Fog
request :set_tenant
request :create_ec2_credential
request :delete_ec2_credential
request :get_ec2_credential
request :list_ec2_credentials
class Mock
attr_reader :auth_token
@ -63,24 +67,27 @@ module Fog
attr_reader :unscoped_token
def self.data
@users ||= {}
@roles ||= {}
@tenants ||= {}
@users ||= {}
@roles ||= {}
@tenants ||= {}
@ec2_credentials ||= Hash.new { |hash, key| hash[key] = {} }
@data ||= Hash.new do |hash, key|
hash[key] = {
:users => @users,
:roles => @roles,
:tenants => @tenants
:users => @users,
:roles => @roles,
:tenants => @tenants,
:ec2_credentials => @ec2_credentials,
}
end
end
def self.reset!
@data = nil
@users = nil
@roles = nil
@tenants = nil
@data = nil
@users = nil
@roles = nil
@tenants = nil
@ec2_credentials = nil
end
def initialize(options={})

View file

@ -0,0 +1,38 @@
module Fog
module Identity
class OpenStack
class Real
def create_ec2_credential(user_id, tenant_id)
data = { 'tenant_id' => tenant_id }
request(
:body => MultiJson.encode(data),
:expects => [200, 202],
:method => 'POST',
:path => "/users/#{user_id}/credentials/OS-EC2",
)
end
end
class Mock
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
end
end
end
end

View file

@ -0,0 +1,30 @@
module Fog
module Identity
class OpenStack
class Real
def delete_ec2_credential(user_id, access)
request(
:expects => [200, 204],
:method => 'DELETE',
:path => "/users/#{user_id}/credentials/OS-EC2/#{access}",
)
end
end
class Mock
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
end
end
end
end

View file

@ -0,0 +1,28 @@
module Fog
module Identity
class OpenStack
class Real
def get_ec2_credential(user_id, access)
request(
:expects => [200, 202],
:method => 'GET',
:path => "/users/#{user_id}/credentials/OS-EC2/#{access}",
)
end
end
class Mock
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
end
end
end
end

View file

@ -0,0 +1,26 @@
module Fog
module Identity
class OpenStack
class Real
def list_ec2_credentials(user_id)
request(
:expects => [200, 202],
:method => 'GET',
:path => "/users/#{user_id}/credentials/OS-EC2",
)
end
end
class Mock
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
end
end
end
end

View file

@ -0,0 +1,41 @@
Shindo.tests('Fog::Identity[:openstack] | EC2 credential requests', ['openstack']) do
@credential_format = {
'access' => String,
'tenant_id' => String,
'secret' => String,
'user_id' => String,
}
tests('success') do
tests('#create_ec2_credential').
formats({'credential' => @credential_format}) do
response =
Fog::Identity[:openstack].
create_ec2_credential('user_id', 'tenant_id')
@ec2_credential = response.body['credential']
response.body
end
tests('#get_ec2_credential').
formats({'credential' => @credential_format}) do
Fog::Identity[:openstack].
get_ec2_credential('user_id', @ec2_credential['access']).body
end
tests('#list_ec2_credentials').
formats({'credentials' => [@credential_format]}) do
Fog::Identity[:openstack].
list_ec2_credentials('user_id').body
end
tests('#delete_ec2_credential').succeeds do
Fog::Identity[:openstack].
delete_ec2_credential('user_id', @ec2_credential['access'])
end
end
end