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, #query_option, #query_read_delete, #value_create_modify

Constructor Details

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

Returns a new instance of BasicAuthPlugin.



19
20
21
22
# File 'lib/aspera/cli/basic_auth_plugin.rb', line 19

def initialize(basic_options: true, **env)
  super(**env)
  BasicAuthPlugin.declare_options(options) if basic_options
end

Class Method Details

.declare_options(options) ⇒ Object



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

def declare_options(options)
  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



37
38
39
# File 'lib/aspera/cli/basic_auth_plugin.rb', line 37

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



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/aspera/cli/basic_auth_plugin.rb', line 25

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