Class: Nephophobia::Resource::Role

Inherits:
Object
  • Object
show all
Defined in:
lib/nephophobia/resource/role.rb

Constant Summary collapse

DEFAULT =
"sysadmin"

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Role

Returns a new instance of Role.



9
10
11
# File 'lib/nephophobia/resource/role.rb', line 9

def initialize client
  @client = client
end

Instance Method Details

#all(user_name = nil, project_name = nil) ⇒ Object

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.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/nephophobia/resource/role.rb', line 19

def all user_name=nil, project_name = nil
  params = {}
  params.merge!("User" => user_name) if user_name
  params.merge!("Project" => project_name) if project_name
  action = ( user_name ? "DescribeUserRoles" : "DescribeRoles" )

  response = @client.action action, params

  roles = response.body["#{action}Response"]['roles']
  roles && Nephophobia::Util.coerce(roles['item']).collect do |data|
    Response::Role.new data
  end
end

#create(user_name, project_name = nil, role_name = nil) ⇒ Object

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. role_name: An Optional String representing a nova role name.



42
43
44
# File 'lib/nephophobia/resource/role.rb', line 42

def create user_name, project_name = nil, role_name = nil
  modify_role user_name, "add", project_name, role_name
end

#destroy(user_name, project_name = nil, role_name = nil) ⇒ Object

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. role_name: An Optional String representing a nova role name.



54
55
56
# File 'lib/nephophobia/resource/role.rb', line 54

def destroy user_name, project_name = nil, role_name = nil
  modify_role user_name, "remove", project_name
end

#modify_role(user_name, operation, project_name = nil, role_name = nil) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/nephophobia/resource/role.rb', line 58

def modify_role user_name, operation, project_name = nil, role_name = nil
  params = {
    "User"      => user_name,
    "Role"      => role_name || DEFAULT,
    "Operation" => operation
  }
  params.merge!("Project" => project_name) if project_name

  response = @client.action "ModifyUserRole", params

  Response::Return.new response.body['ModifyUserRoleResponse']
end