Module: CloudFoundry::Client::Users

Included in:
CloudFoundry::Client
Defined in:
lib/cloudfoundry/client/users.rb

Overview

CloudFoundry API Users methods.

Instance Method Summary collapse

Instance Method Details

#create_user(email, password) ⇒ Boolean

Creates a new user on the target cloud.

Parameters:

  • email (String)

    The user's email.

  • password (String)

    The user's password.

Returns:

  • (Boolean)

    Returns true if user is created.

Raises:



81
82
83
84
85
86
# File 'lib/cloudfoundry/client/users.rb', line 81

def create_user(email, password)
  raise CloudFoundry::Client::Exception::BadParams, "Email cannot be blank" if email.nil? || email.empty?
  raise CloudFoundry::Client::Exception::BadParams, "Password cannot be blank" if password.nil? || password.empty?
  post(CloudFoundry::Client::USERS_PATH, {:email => email, :password => password})
  true
end

#delete_user(email) ⇒ Boolean

Deletes a user on the target cloud.

Parameters:

  • email (String)

    The user's email.

Returns:

  • (Boolean)

    Returns true if user is deleted.

Raises:

Requires an admin user logged in:

  • True



113
114
115
116
117
118
# File 'lib/cloudfoundry/client/users.rb', line 113

def delete_user(email)
  
  raise CloudFoundry::Client::Exception::BadParams, "Email cannot be blank" if email.nil? || email.empty?
  delete("#{CloudFoundry::Client::USERS_PATH}/#{email}", :raw => true)
  true
end

#list_usersHash

Returns the list of users on the target cloud.

Returns:

  • (Hash)

    List of users on the target cloud.

Requires an admin user logged in:

  • True



56
57
58
59
# File 'lib/cloudfoundry/client/users.rb', line 56

def list_users()
  
  get(CloudFoundry::Client::USERS_PATH)
end

#logged_in?Boolean

Checks if the user is logged in at the cloud target.

Returns:

  • (Boolean)

    Returns true if user is logged in, false otherwise.



26
27
28
29
30
31
32
# File 'lib/cloudfoundry/client/users.rb', line 26

def logged_in?
  return false unless cloud_info = cloud_info()
  return false unless cloud_info[:user]
  return false unless cloud_info[:usage]
  @user = cloud_info[:user]
  true
end

#login(email, password) ⇒ String

Logs the user in and returns the auth_token provided by the target cloud.

Parameters:

  • email (String)

    The user's email.

  • password (String)

    The user's password.

Returns:

  • (String)

    CloudFoundry API Authorization Token.

Raises:



13
14
15
16
17
18
19
20
21
# File 'lib/cloudfoundry/client/users.rb', line 13

def (email, password)
  raise CloudFoundry::Client::Exception::BadParams, "Email cannot be blank" if email.nil? || email.empty?
  raise CloudFoundry::Client::Exception::BadParams, "Password cannot be blank" if password.nil? || password.empty?
  response_info = post("#{CloudFoundry::Client::USERS_PATH}/#{email}/tokens", {:password => password})
  raise CloudFoundry::Client::Exception::Forbidden, "Login failed" unless response_info &&  response_info[:token]
  @user = email
  @proxy_user = nil
  @auth_token = response_info[:token]
end

#set_proxy_user(email) ⇒ String

Sets a user proxied access

Parameters:

  • email (String)

    The user's email to be proxied.

Returns:

  • (String)

    Proxied user.

Raises:

Requires an admin user logged in:

  • True



40
41
42
43
# File 'lib/cloudfoundry/client/users.rb', line 40

def set_proxy_user(email)
  raise CloudFoundry::Client::Exception::BadParams, "Email cannot be blank" if email.nil? || email.empty?
  @proxy_user = email
end

#unset_proxy_usernil

Unsets a user proxied access

Returns:

  • (nil)


48
49
50
# File 'lib/cloudfoundry/client/users.rb', line 48

def unset_proxy_user()
  @proxy_user = nil
end

#update_user(email, password) ⇒ Boolean

Updates the user's password on the target cloud.

Parameters:

  • email (String)

    The user's email.

  • password (String)

    The user's password.

Returns:

  • (Boolean)

    Returns true if user is updated.

Raises:

Requires a user logged in:

  • True

Requires an admin user logged in:

  • Only when updating password for others users.



97
98
99
100
101
102
103
104
105
# File 'lib/cloudfoundry/client/users.rb', line 97

def update_user(email, password)
  
  raise CloudFoundry::Client::Exception::BadParams, "Email cannot be blank" if email.nil? || email.empty?
  raise CloudFoundry::Client::Exception::BadParams, "Password cannot be blank" if password.nil? || password.empty?
   = (email)
  [:password] = password
  put("#{CloudFoundry::Client::USERS_PATH}/#{email}", )
  true
end

#user_info(email) ⇒ Hash

Returns information about a user on the target cloud.

Parameters:

  • email (String)

    The user's email.

Returns:

  • (Hash)

    User information on the target cloud.

Raises:

Requires a user logged in:

  • True

Requires an admin user logged in:

  • Only when retrieving information about others users.



68
69
70
71
72
# File 'lib/cloudfoundry/client/users.rb', line 68

def (email)
  
  raise CloudFoundry::Client::Exception::BadParams, "Email cannot be blank" if email.nil? || email.empty?
  get("#{CloudFoundry::Client::USERS_PATH}/#{email}")
end