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
-
#use_refresh_token(refresh_token) ⇒ Object
this regenerates the access_token and refresh_token.
Methods inherited from APIClient
#account_groups, #accounts, #apps, #archive_buckets, #archive_files, #auth, #blueprints, #cloud_datastores, #cloud_folders, #cloud_policies, #cloud_resource_pools, #clouds, #containers, #custom_instance_types, #cypher, #dashboard, #default_content_type, #deploy, #deployments, #dry, #dry_run, #environments, #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, #network_types, #networks, #old_cypher, #option_type_lists, #option_types, #options, #packages, #policies, #power_schedules, #processes, #provision_types, #reports, #roles, #security_group_rules, #security_groups, #server_types, #servers, #set_ssl_verification_enabled, #setopts, #setup, #ssl_verification_enabled?, #storage_providers, #task_sets, #tasks, #user_groups, #user_settings, #user_sources, #users, #virtual_images, #whoami, #wiki, #withopts
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: 5} response = execute(opts) return response if @dry_run @access_token = response['access_token'] return response end |
#logout ⇒ Object
37 38 39 40 41 42 |
# File 'lib/morpheus/api/auth_interface.rb', line 37 def logout() if @access_token # todo: expire the token end raise "#{self}.logout() is not yet implemented" end |
#use_refresh_token(refresh_token) ⇒ Object
this regenerates the access_token and refresh_token
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/morpheus/api/auth_interface.rb', line 25 def use_refresh_token(refresh_token) @access_token = nil url = "#{@base_url}/oauth/token" params = {grant_type: 'refresh_token', scope:'write', client_id: 'morph-cli'} payload = {refresh_token: refresh_token} opts = {method: :post, url: url, headers:{ params: params}, payload: payload} response = execute(opts) return response if @dry_run @access_token = response['access_token'] return response end |