lib/nephophobia/role.rb in nephophobia-0.0.6 vs lib/nephophobia/role.rb in nephophobia-0.0.7
- old
+ new
@@ -13,17 +13,37 @@
def initialize client
@client = client
end
##
+ # Returns global roles for the given 'user_name', or for the given 'project_name'.
+ #
+ # +user_name+: A String representing a nova user_name.
+ # +project_name+: An Optional String representing a nova project_name name.
+
+ def all user_name, project_name = nil
+ params = {
+ "User" => user_name,
+ }
+ params.merge!("Project" => project_name) if project_name
+
+ response = @client.action "DescribeUserRoles", params
+
+ roles = response.body['DescribeUserRolesResponse']['roles']
+ roles && Nephophobia.coerce(roles['item']).collect do |data|
+ RoleData.new data
+ end
+ end
+
+ ##
# Adds the given 'user_name' to the global 'Role::DEFAULT', unless a
# 'role_name' is provided.
# Returns a response to the state change.
#
# +user_name+: A String representing a nova user_name.
# +project_name+: An Optional String representing a nova project_name name.
- # +project_name+: An Optional String representing a nova role name.
+ # +role_name+: An Optional String representing a nova role name.
def create user_name, project_name = nil, role_name = nil
modify_role user_name, "add", project_name, role_name
end
@@ -31,33 +51,13 @@
# Removes the given 'user_name' from the global 'Role::DEFAULT', unless a
# 'role_name' is provided.
#
# +user_name+: A String representing a nova user_name.
# +project_name+: An Optional String representing a nova project_name name.
- # +project_name+: An Optional String representing a nova role name.
+ # +role_name+: An Optional String representing a nova role name.
def destroy user_name, project_name = nil, role_name = nil
modify_role user_name, "remove", project_name
- end
-
- ##
- # Returns roles for the given 'user_name' and 'project_name'.
- #
- # +user_name+: A String representing a nova user_name.
- # +project_name+: An Optional String representing a nova project_name name.
-
- def all user_name, project_name
- params = {
- "User" => user_name,
- "Project" => project_name
- }
-
- response = @client.action "DescribeUserRoles", params
-
- response.body['DescribeUserRolesResponse']['roles'] &&
- Nephophobia.coerce(response.body['DescribeUserRolesResponse']['roles']['item']).collect do |data|
- RoleData.new data
- end
end
private
def modify_role user_name, operation, project_name = nil, role_name = nil
params = {