mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #1632 from rubiojr/multiple-accounts-support
[openstack|storage] Added support to impersonate other accounts
This commit is contained in:
commit
0c1ddd97c7
2 changed files with 76 additions and 0 deletions
|
@ -48,6 +48,7 @@ module Fog
|
|||
require 'mime/types'
|
||||
@openstack_api_key = options[:openstack_api_key]
|
||||
@openstack_username = options[:openstack_username]
|
||||
@path = '/v1/AUTH_1234'
|
||||
end
|
||||
|
||||
def data
|
||||
|
@ -57,6 +58,16 @@ module Fog
|
|||
def reset_data
|
||||
self.class.data.delete(@openstack_username)
|
||||
end
|
||||
|
||||
def change_account(account)
|
||||
@original_path ||= @path
|
||||
version_string = @original_path.split('/')[1]
|
||||
@path = "/#{version_string}/#{account}"
|
||||
end
|
||||
|
||||
def reset_account_name
|
||||
@path = @original_path
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -84,6 +95,52 @@ module Fog
|
|||
@connection.reset
|
||||
end
|
||||
|
||||
# Change the current account while re-using the auth token.
|
||||
#
|
||||
# This is usefull when you have an admin role and you're able
|
||||
# to HEAD other user accounts, set quotas, list files, etc.
|
||||
#
|
||||
# For example:
|
||||
#
|
||||
# # List current user account details
|
||||
# service = Fog::Storage[:openstack]
|
||||
# service.request :method => 'HEAD'
|
||||
#
|
||||
# Would return something like:
|
||||
#
|
||||
# Account: AUTH_1234
|
||||
# Date: Tue, 05 Mar 2013 16:50:52 GMT
|
||||
# X-Account-Bytes-Used: 0 (0.00 Bytes)
|
||||
# X-Account-Container-Count: 0
|
||||
# X-Account-Object-Count: 0
|
||||
#
|
||||
# Now let's change the account
|
||||
#
|
||||
# service.change_account('AUTH_3333')
|
||||
# service.request :method => 'HEAD'
|
||||
#
|
||||
# Would return something like:
|
||||
#
|
||||
# Account: AUTH_3333
|
||||
# Date: Tue, 05 Mar 2013 16:51:53 GMT
|
||||
# X-Account-Bytes-Used: 23423433
|
||||
# X-Account-Container-Count: 2
|
||||
# X-Account-Object-Count: 10
|
||||
#
|
||||
# If we wan't to go back to our original admin account:
|
||||
#
|
||||
# service.reset_account_name
|
||||
#
|
||||
def change_account(account)
|
||||
@original_path ||= @path
|
||||
version_string = @path.split('/')[1]
|
||||
@path = "/#{version_string}/#{account}"
|
||||
end
|
||||
|
||||
def reset_account_name
|
||||
@path = @original_path
|
||||
end
|
||||
|
||||
def request(params, parse_json = true, &block)
|
||||
begin
|
||||
response = @connection.request(params.merge({
|
||||
|
|
19
tests/openstack/storage_tests.rb
Normal file
19
tests/openstack/storage_tests.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
Shindo.tests('Fog::Storage[:openstack]', ['openstack', 'storage']) do
|
||||
|
||||
storage = Fog::Storage[:openstack]
|
||||
original_path = storage.instance_variable_get :@path
|
||||
|
||||
tests("account changes") do
|
||||
test("#change_account") do
|
||||
new_account = 'AUTH_1234567890'
|
||||
storage.change_account new_account
|
||||
storage.instance_variable_get(:@path) != original_path
|
||||
end
|
||||
test("#reset_account_name") do
|
||||
storage.reset_account_name
|
||||
storage.instance_variable_get(:@path) == original_path
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Add table
Reference in a new issue