Class: Aspera::Cli::Plugins::Faspio

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

Constant Summary

Constants inherited from Base

Base::FILTER_ARGS

Instance Attribute Summary

Attributes inherited from Base

#context, #help_path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BasicAuth

#basic_auth_api, #basic_auth_params

Methods inherited from Base

#action_for, #add_manual_header, application_name, #bulk_result, command, command_registry, commands_under, #config, crud_commands, declare_options, define_action_method, #dispatch_child, #dispatch_from_registry, #dispatch_leaf, #dispatch_mount, #entity_create, #entity_delete, #entity_list, #entity_modify, entity_noun, #entity_res_path, #entity_show, #execute_action, #execute_leaf, file_matcher, #formatter, #generate_help, #http_config, #initialize, #invoke_action, operation_description, option_sources, option_specs, #options, #persistency, #presets, #progress_bar, #query_read_delete, register_option_spec, #resolve_argument, #resolve_arguments, #transfer, use_options, used_option_sources, #validate_registry

Methods included from OptionDeclarator

#declare_options, #option, #option_specs, #register_option_spec

Constructor Details

This class inherits a constructor from Aspera::Cli::Plugins::Base

Class Method Details

.detect(base_url) ⇒ Hash, NilClass

Returns:



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/aspera/cli/plugins/faspio.rb', line 15

def detect(base_url)
  api = Rest::Client.new(base_url: base_url)
  data, http = api.read('ping', ret: :both)
  server_type = http['Server']
  return unless data.is_a?(Hash) && data.empty?
  return unless server_type.is_a?(String) && server_type.include?('faspio')
  return {
    version: server_type.gsub(%r{^.*/}, ''),
    url:     base_url
  }
end

Instance Method Details

#action_health ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/aspera/cli/plugins/faspio.rb', line 83

def action_health(**)
  nagios = Nagios.new
  begin
    result = build_api.read('ping')
    if result.is_a?(Hash) && result.empty?
      nagios.add_ok('api', 'answered ok')
    else
      nagios.add_critical('api', 'not expected answer')
    end
  rescue StandardError => e
    nagios.add_critical('api', e.to_s)
  end
  Result::ObjectList.new(nagios.status_list)
end

#build_api ⇒ Rest::Client

Build the REST API object based on the configured auth type.

Returns:



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/aspera/cli/plugins/faspio.rb', line 55

def build_api
  base_url = options.get_option(:url, mandatory: true)
  case options.get_option(:auth, mandatory: true)
  when :basic
    basic_auth_api
  when :jwt
    app_client_id = options.get_option(:client_id, mandatory: true)
    Rest::Client.new(
      base_url: base_url,
      auth:     {
        type:            :oauth2,
        grant_method:    :jwt,
        base_url:        "#{base_url}/auth",
        params:          {
          client_id: app_client_id
        },
        use_query:       true,
        payload:         {
          iss: app_client_id, # issuer
          sub: app_client_id  # subject
        },
        private_key_obj: OpenSSL::PKey::RSA.new(options.get_option(:private_key, mandatory: true), options.get_option(:passphrase)),
        headers:         {typ: 'JWT'}
      }
    )
  end
end

#wizard(wizard, app_url) ⇒ Hash

Returns :preset_value, :test_args.

Parameters:

  • wizard (Wizard) —

    The wizard object

  • app_url (String) —

    Tested URL

Returns:

  • (Hash) —

    :preset_value, :test_args



31
32
33
34
35
36
37
38
# File 'lib/aspera/cli/plugins/faspio.rb', line 31

def wizard(wizard, app_url)
  return {
    preset_value: {
      url: app_url
    },
    test_args:    'info'
  }
end