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:
parent
bcfb5fe1df
commit
8c76badfba
6 changed files with 180 additions and 10 deletions
|
@ -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={})
|
||||
|
|
38
lib/fog/openstack/requests/identity/create_ec2_credential.rb
Normal file
38
lib/fog/openstack/requests/identity/create_ec2_credential.rb
Normal 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
|
30
lib/fog/openstack/requests/identity/delete_ec2_credential.rb
Normal file
30
lib/fog/openstack/requests/identity/delete_ec2_credential.rb
Normal 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
|
||||
|
28
lib/fog/openstack/requests/identity/get_ec2_credential.rb
Normal file
28
lib/fog/openstack/requests/identity/get_ec2_credential.rb
Normal 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
|
26
lib/fog/openstack/requests/identity/list_ec2_credentials.rb
Normal file
26
lib/fog/openstack/requests/identity/list_ec2_credentials.rb
Normal 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
|
41
tests/openstack/requests/identity/ec2_credentials_tests.rb
Normal file
41
tests/openstack/requests/identity/ec2_credentials_tests.rb
Normal 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
|
Loading…
Reference in a new issue