Module: CloudFoundry::Client::Users
- Included in:
- CloudFoundry::Client
- Defined in:
- lib/cloudfoundry/client/users.rb
Overview
CloudFoundry API Users methods.
Instance Method Summary collapse
-
#create_user(email, password) ⇒ Boolean
Creates a new user on the target cloud.
-
#delete_user(email) ⇒ Boolean
Deletes a user on the target cloud.
-
#list_users ⇒ Hash
Returns the list of users on the target cloud.
-
#logged_in? ⇒ Boolean
Checks if the user is logged in at the cloud target.
-
#login(email, password) ⇒ String
Logs the user in and returns the auth_token provided by the target cloud.
-
#set_proxy_user(email) ⇒ String
Sets a user proxied access.
-
#unset_proxy_user ⇒ nil
Unsets a user proxied access.
-
#update_user(email, password) ⇒ Boolean
Updates the user's password on the target cloud.
-
#user_info(email) ⇒ Hash
Returns information about a user on the target cloud.
Instance Method Details
#create_user(email, password) ⇒ Boolean
Creates a new user on the target cloud.
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.
113 114 115 116 117 118 |
# File 'lib/cloudfoundry/client/users.rb', line 113 def delete_user(email) require_login 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_users ⇒ Hash
Returns the list of users on the target cloud.
56 57 58 59 |
# File 'lib/cloudfoundry/client/users.rb', line 56 def list_users() require_login get(CloudFoundry::Client::USERS_PATH) end |
#logged_in? ⇒ Boolean
Checks if the user is logged in at the cloud target.
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.
13 14 15 16 17 18 19 20 21 |
# File 'lib/cloudfoundry/client/users.rb', line 13 def login(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
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_user ⇒ nil
Unsets a user proxied access
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.
97 98 99 100 101 102 103 104 105 |
# File 'lib/cloudfoundry/client/users.rb', line 97 def update_user(email, password) require_login 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? user_info = user_info(email) user_info[:password] = password put("#{CloudFoundry::Client::USERS_PATH}/#{email}", user_info) true end |
#user_info(email) ⇒ Hash
Returns information about a user on the target cloud.
68 69 70 71 72 |
# File 'lib/cloudfoundry/client/users.rb', line 68 def user_info(email) require_login raise CloudFoundry::Client::Exception::BadParams, "Email cannot be blank" if email.nil? || email.empty? get("#{CloudFoundry::Client::USERS_PATH}/#{email}") end |