Module: Aspera::Cli::Plugins::BasicAuth

Overview

Module for plugins of applications supporting basic authentication: include Cli::Plugins::BasicAuth in a plugin class. Its included hook gives the options of the module to the plugin class (use_options); Oauth includes this module and adds the options itself.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Option::Declarator

declare_options, option, option_specs, register_option_spec

Class Method Details

.included(base) ⇒ Object

Parameters:

  • base (Class) —

    Plugin class that includes the module



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

def included(base)
  super
  base.use_options(self) if base.is_a?(Class)
end

Instance Method Details

#basic_auth_api(subpath = nil) ⇒ Object



43
44
45
# File 'lib/aspera/cli/plugins/basic_auth.rb', line 43

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

#basic_auth_params(subpath = nil) ⇒ Object

returns a Rest::Client object with basic auth



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/aspera/cli/plugins/basic_auth.rb', line 30

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