Class: Aspera::Cli::BasicAuthPlugin

Inherits:
Plugin
  • Object
show all
Defined in:
lib/aspera/cli/basic_auth_plugin.rb

Overview

base class for applications supporting basic authentication

Constant Summary

Constants inherited from Plugin

Plugin::ALL_OPS, Plugin::GLOBAL_OPS, Plugin::INIT_PARAMS, Plugin::INSTANCE_OPS, Plugin::MAX_ITEMS, Plugin::MAX_PAGES, Plugin::REGEX_LOOKUP_ID_BY_FIELD

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Plugin

declare_generic_options, #do_bulk_operation, #entity_action, #entity_command, #init_params, #instance_identifier, #old_query_read_delete, #query_option, #query_read_delete, #value_create_modify

Constructor Details

#initialize(basic_options: true, **env) ⇒ BasicAuthPlugin

Returns a new instance of BasicAuthPlugin.



22
23
24
25
26
# File 'lib/aspera/cli/basic_auth_plugin.rb', line 22

def initialize(basic_options: true, **env)
  super(**env)
  # , force: env[:all_manuals]
  BasicAuthPlugin.declare_options(options) if basic_options
end

Class Method Details

.declare_options(options) ⇒ Object

@@basic_options_declared = false # rubocop:disable Style/ClassVars



12
13
14
15
16
17
18
19
# File 'lib/aspera/cli/basic_auth_plugin.rb', line 12

def declare_options(options) # , force: false
  #return if @@basic_options_declared && !force
  #@@basic_options_declared = true # rubocop:disable Style/ClassVars
  options.declare(:url, 'URL of application, e.g. https://faspex.example.com/aspera/faspex')
  options.declare(:username, "User's name to log in")
  options.declare(:password, "User's password")
  options.parse_options!
end

Instance Method Details

#basic_auth_api(subpath = nil) ⇒ Object



41
42
43
# File 'lib/aspera/cli/basic_auth_plugin.rb', line 41

def basic_auth_api(subpath=nil)
  return Rest.new(**basic_auth_params(subpath))
end

#basic_auth_params(subpath = nil) ⇒ Object

returns a Rest object with basic auth



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/aspera/cli/basic_auth_plugin.rb', line 29

def basic_auth_params(subpath=nil)
  api_url = options.get_option(:url, mandatory: true)
  api_url = api_url + '/' + subpath unless subpath.nil?
  return {
    base_url: api_url,
    auth:     {
      type:     :basic,
      username: options.get_option(:username, mandatory: true),
      password: options.get_option(:password, mandatory: true)
    }}
end