Class: Nephophobia::Resource::User

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ User

Returns a new instance of User.



7
8
9
# File 'lib/nephophobia/resource/user.rb', line 7

def initialize client
  @client = client
end

Instance Method Details

#create(user_name) ⇒ Object

Creates the given ‘user_name’. Returns a response to the state change.

user_name: A String representing a nova user_name.



17
18
19
20
21
# File 'lib/nephophobia/resource/user.rb', line 17

def create user_name
  response = @client.action "RegisterUser", "Name" => user_name

  Response::User.new response.body['RegisterUserResponse']
end

#credentials(user_name, project_name) ⇒ Object

Returns the credentials for a given ‘user_name’ for the specified ‘project_name’.

user_name: A String containing a nova user_name. project_name: A String containing a nova project_name name.



29
30
31
32
33
34
35
36
37
38
# File 'lib/nephophobia/resource/user.rb', line 29

def credentials user_name, project_name
  params = {
    "Name"    => user_name,
    "Project" => project_name
  }

  response = @client.action "GenerateX509ForUser", params

  Base64.decode64 response.body['GenerateX509ForUserResponse']['file']
end

#destroy(user_name) ⇒ Object

Removes the given ‘user_name’. Returns a response to the state change.

user_name: A String representing a nova user_name.



46
47
48
49
50
# File 'lib/nephophobia/resource/user.rb', line 46

def destroy user_name
  response = @client.action "DeregisterUser", "Name" => user_name

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

#find(user_name) ⇒ Object

Returns information about the given ‘user_name’.

user_name: A String representing the user_name.



57
58
59
60
61
62
# File 'lib/nephophobia/resource/user.rb', line 57

def find user_name
  response = @client.action "DescribeUser", "Name" => user_name

  Response::User.new response.body['DescribeUserResponse']
rescue Hugs::Errors::BadRequest
end

#register(user_name, project_name) ⇒ Object

Apply a set of global and per-project permissions to the given ‘user_name’. Do the following if the ‘user_name’ is not a member of the ‘project_name’.

- Add the 'user_name' with the default role (sysadmin) globally.
- Add the 'user_name' to the 'project_name', with the default role (sysadmin).
- Add the 'user_name' as a member to the 'project_name'

user_name: A String representing a nova user_name. project_name: A String representing a nova project_name name.



74
75
76
77
78
79
80
# File 'lib/nephophobia/resource/user.rb', line 74

def register user_name, project_name
  unless @client.project.member? user_name, project_name
    @client.role.create user_name
    @client.role.create user_name, project_name
    @client.project.add_member user_name, project_name
  end
end