Class: Morpheus::AuthInterface

Inherits:
APIClient show all
Defined in:
lib/morpheus/api/auth_interface.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from APIClient

#account_groups, #accounts, #app_templates, #apps, #archive_buckets, #archive_files, #auth, #blueprints, #cloud_datastores, #cloud_policies, #clouds, #containers, #custom_instance_types, #cypher, #dashboard, #deploy, #deployments, #dry, #dry_run, #execute, #execute_schedules, #execution_request, #file_copy_request, #group_policies, #groups, #image_builder, #instance_types, #instances, #key_pairs, #library_container_scripts, #library_container_templates, #library_container_types, #library_container_upgrades, #library_instance_types, #library_layouts, #license, #load_balancers, #logs, #monitoring, #network_domains, #network_groups, #network_pool_servers, #network_pools, #network_proxies, #network_services, #networks, #option_type_lists, #option_types, #options, #packages, #policies, #power_schedules, #processes, #provision_types, #roles, #security_group_rules, #security_groups, #servers, #set_ssl_verification_enabled, #setup, #ssl_verification_enabled?, #storage_providers, #task_sets, #tasks, #user_groups, #user_settings, #user_sources, #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_tokenObject (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 (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

#logoutObject



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