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::INSTANCE_OPS, Plugin::MAX_ITEMS, Plugin::MAX_PAGES, Plugin::REGEX_LOOKUP_ID_BY_FIELD, Plugin::VAL_ALL

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Plugin

#do_bulk_operation, #entity_action, #entity_command, #instance_identifier, #old_query_read_delete, #query_read_delete, #value_create_modify, #value_or_query

Constructor Details

#initialize(env) ⇒ BasicAuthPlugin

Returns a new instance of BasicAuthPlugin.



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

def initialize(env)
  super(env)
  self.class.register_options(env) unless env[:skip_basic_auth_options]
end

Class Method Details

.register_options(env) ⇒ Object



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

def register_options(env)
  env[:options].declare(:url, 'URL of application, e.g. https://org.asperafiles.com')
  env[:options].declare(:username, 'Username to log in')
  env[:options].declare(:password, "User's password")
  env[: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