mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
commit
41b3f8b156
7 changed files with 87 additions and 2 deletions
|
@ -51,6 +51,8 @@ module Fog
|
|||
request :list_users
|
||||
request :create_user
|
||||
request :delete_user
|
||||
request :grant_user_access
|
||||
request :revoke_user_access
|
||||
|
||||
class Mock < Fog::Rackspace::Service
|
||||
def request(params)
|
||||
|
|
|
@ -21,6 +21,17 @@ module Fog
|
|||
true
|
||||
end
|
||||
|
||||
def grant_access_for(user)
|
||||
requires :identity, :instance
|
||||
service.grant_user_access(instance.identity, user, name)
|
||||
end
|
||||
|
||||
def revoke_access_for(user)
|
||||
requires :identity, :instance
|
||||
service.revoke_user_access(instance.identity, user, name)
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def instance
|
||||
|
|
|
@ -8,10 +8,11 @@ module Fog
|
|||
|
||||
attribute :password
|
||||
attribute :databases
|
||||
attribute :host
|
||||
|
||||
def save
|
||||
requires :identity, :instance, :password
|
||||
service.create_user(instance.identity, identity, password, :databases => databases)
|
||||
service.create_user(instance.identity, identity, password, :databases => databases, :host => host)
|
||||
true
|
||||
end
|
||||
|
||||
|
|
|
@ -7,7 +7,8 @@ module Fog
|
|||
'users' => [{
|
||||
'name' => name,
|
||||
'password' => password,
|
||||
'databases' => options[:databases] || []
|
||||
'databases' => options[:databases] || [],
|
||||
'host' => options[:host] || '%'
|
||||
}]
|
||||
}
|
||||
|
||||
|
|
32
lib/fog/rackspace/requests/databases/grant_user_access.rb
Normal file
32
lib/fog/rackspace/requests/databases/grant_user_access.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class Databases
|
||||
class Real
|
||||
def grant_user_access(instance_id, user, *databases)
|
||||
user =
|
||||
if user.respond_to?(:name) && user.respond_to?(:host)
|
||||
host_str =
|
||||
if user.host && user.host != '' && user.host != '%'
|
||||
"@#{user.host}"
|
||||
end.to_s
|
||||
user.name + host_str
|
||||
else
|
||||
user
|
||||
end
|
||||
|
||||
data = { :databases => [] }
|
||||
databases.each do |db_name|
|
||||
data[:databases] << { :name => db_name }
|
||||
end
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:expects => 202,
|
||||
:method => 'PUT',
|
||||
:path => "instances/#{instance_id}/users/#{user}/databases"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
26
lib/fog/rackspace/requests/databases/revoke_user_access.rb
Normal file
26
lib/fog/rackspace/requests/databases/revoke_user_access.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class Databases
|
||||
class Real
|
||||
def revoke_user_access(instance_id, user, database)
|
||||
user =
|
||||
if user.respond_to?(:name) && user.respond_to?(:host)
|
||||
host_str =
|
||||
if user.host && user.host != '' && user.host != '%'
|
||||
"@#{user.host}"
|
||||
end.to_s
|
||||
user.name + host_str
|
||||
else
|
||||
user
|
||||
end
|
||||
|
||||
request(
|
||||
:expects => 202,
|
||||
:method => 'DELETE',
|
||||
:path => "instances/#{instance_id}/users/#{user}/databases/#{database}"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -13,5 +13,17 @@ Shindo.tests('Fog::Rackspace::Databases | database', ['rackspace']) do
|
|||
|
||||
model_tests(instance.databases, { :name => "db_#{Time.now.to_i.to_s}" }, false)
|
||||
|
||||
user_no_host = instance.users.create(:name => "foo", :password => "foo")
|
||||
user_with_host = instance.users.create(:name => "bar", :host => "10.20.30.40", :password => "bar")
|
||||
|
||||
db = instance.databases.create(:name => "Test_#{Time.now.to_i}")
|
||||
|
||||
db.grant_access_for(user_no_host)
|
||||
db.grant_access_for(user_with_host)
|
||||
|
||||
db.revoke_access_for(user_no_host)
|
||||
db.revoke_access_for(user_with_host)
|
||||
|
||||
|
||||
instance.destroy
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue