lib/nephophobia/role.rb in nephophobia-0.0.4 vs lib/nephophobia/role.rb in nephophobia-0.0.5
- old
+ new
@@ -6,40 +6,46 @@
@name = hash['role']
end
end
class Role
- ### TODO: Add a default attr.
DEFAULT = "sysadmin"
def initialize client
@client = client
end
##
- # Adds the given 'user_name' to the specified "project_name's" 'Role::DEFAULT'.
+ # 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+: A String representing a nova project_name name.
+ # +project_name+: An Optional String representing a nova project_name name.
+ # +project_name+: An Optional String representing a nova role name.
- def create user_name, project_name
+ def create user_name, project_name = nil, role_name = nil
modify_role user_name, "add", project_name
end
##
- # Removes the given 'user_name' from the specified "project_name's" 'Role::DEFAULT'.
+ # 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+: A String representing a nova project_name name.
+ # +project_name+: An Optional String representing a nova project_name name.
+ # +project_name+: An Optional String representing a nova role name.
- def destroy user_name, project_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
@@ -52,15 +58,16 @@
RoleData.new data
end
end
private
- def modify_role user_name, operation, project_name
+ def modify_role user_name, operation, project_name = nil, role_name = nil
params = {
"User" => user_name,
- "Role" => DEFAULT,
+ "Role" => role_name || DEFAULT,
"Operation" => operation
}
+ params.merge!("Project" => project_name) if project_name
response = @client.action "ModifyUserRole", params
ResponseData.new response.body['ModifyUserRoleResponse']
end