Class: Morpheus::AuthInterface
- Defined in:
- lib/morpheus/api/auth_interface.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
Instance Method Summary collapse
-
#initialize(base_url, access_token = nil) ⇒ AuthInterface
constructor
A new instance of AuthInterface.
- #login(username, password) ⇒ Object
- #logout ⇒ Object
Methods inherited from APIClient
#accounts, #app_templates, #apps, #auth, #clouds, #custom_instance_types, #dashboard, #deploy, #deployments, #dry, #dry_run, #execute, #groups, #instance_types, #instances, #key_pairs, #license, #load_balancers, #logs, #options, #provision_types, #roles, #security_group_rules, #security_groups, #servers, #setup, #task_sets, #tasks, #users, #virtual_images, #whoami
Constructor Details
#initialize(base_url, access_token = nil) ⇒ AuthInterface
Returns a new instance of AuthInterface.
7 8 9 10 |
# File 'lib/morpheus/api/auth_interface.rb', line 7 def initialize(base_url, access_token=nil) @base_url = base_url @access_token = access_token end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
5 6 7 |
# File 'lib/morpheus/api/auth_interface.rb', line 5 def access_token @access_token end |
Instance Method Details
#login(username, password) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/morpheus/api/auth_interface.rb', line 12 def login(username, password) @access_token = nil url = "#{@base_url}/oauth/token" params = {grant_type: 'password', scope:'write', client_id: 'morph-cli', username: username} payload = {password: password} opts = {method: :post, url: url, headers:{ params: params}, payload: payload, timeout: 10} response = execute(opts) return response if @dry_run @access_token = response['access_token'] return response end |
#logout ⇒ Object
24 25 26 27 28 29 |
# File 'lib/morpheus/api/auth_interface.rb', line 24 def logout() if @access_token # todo: expire the token end raise "#{self}.logout() is not yet implemented" end |