Class: Aspera::Cli::Plugins::Oauth

Inherits:
BasicAuth show all
Defined in:
lib/aspera/cli/plugins/oauth.rb

Overview

base class for applications supporting OAuth 2.0 authentication

Direct Known Subclasses

Aoc, Faspex5

Constant Summary collapse

AUTH_TYPES =

OAuth methods supported (web, jwt)

i[web jwt boot].freeze
AUTH_OPTIONS =

Options used for authentication (url, auth, client_id, etc…)

i[url auth client_id client_secret redirect_uri private_key passphrase username password].freeze

Constants inherited from Base

Base::ALL_OPS, Base::GLOBAL_OPS, Base::INSTANCE_OPS, Base::MAX_ITEMS, Base::MAX_PAGES

Instance Attribute Summary

Attributes inherited from Base

#context

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BasicAuth

#basic_auth_api, #basic_auth_params, declare_options

Methods inherited from Base

#add_manual_header, #config, declare_options, #do_bulk_operation, #entity_execute, #formatter, #instance_identifier, #list_entities_limit_offset_total_count, #lookup_entity_by_field, #lookup_entity_generic, #options, percent_selector, #persistency, #query_read_delete, #transfer, #value_create_modify

Constructor Details

#initialize(**_) ⇒ Oauth

Returns a new instance of Oauth.



38
39
40
41
42
43
44
45
46
# File 'lib/aspera/cli/plugins/oauth.rb', line 38

def initialize(**_)
  super
  options.declare(:auth, 'OAuth type of authentication', allowed: AUTH_TYPES, default: :jwt)
  options.declare(:client_id, 'OAuth client identifier')
  options.declare(:client_secret, 'OAuth client secret')
  options.declare(:redirect_uri, 'OAuth (Web) redirect URI for web authentication')
  options.declare(:private_key, 'OAuth (JWT) RSA private key PEM value (prefix file path with @file:)')
  options.declare(:passphrase, 'OAuth (JWT) RSA private key passphrase')
end

Class Method Details

.args_from_options(options, defaults: nil, **kwargs) ⇒ Object

Get command line options specified by AUTH_OPTIONS and defaults.keys (value is default). Adds those not nil to the kwargs. Instantiate the provided klass with those kwargs. defaults can specify a default value (not nil)

Parameters:

  • options (Cli::Manager)

    Object to get command line options.

  • kwargs (Hash)

    Object creation arguments

  • defaults (Hash) (defaults to: nil)

    Additional options, key=symbol, value=default value or nil

Returns:

  • (Object)

    instance of klass

Raises:

  • (Cli::Error)

    if a required option is missing



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/aspera/cli/plugins/oauth.rb', line 20

def args_from_options(options, defaults: nil, **kwargs)
  defaults ||= {}
  (AUTH_OPTIONS + defaults.keys).each_with_object(kwargs) do |i, m|
    v = options.get_option(i)
    m[i] = v unless v.nil?
    m[i] = defaults[i] if m[i].nil? && !defaults[i].nil?
  end
rescue ::ArgumentError => e
  if (m = e.message.match(/missing keyword: :(.*)$/))
    raise Cli::Error, "Missing option: #{m[1]}"
  end
  raise
end