Class: Aspera::Cli::Plugins::Httpgw

Inherits:
Aspera::Cli::Plugin show all
Defined in:
lib/aspera/cli/plugins/httpgw.rb

Constant Summary collapse

ACTIONS =
%i[health info].freeze

Constants inherited from Aspera::Cli::Plugin

Aspera::Cli::Plugin::ALL_OPS, Aspera::Cli::Plugin::GLOBAL_OPS, Aspera::Cli::Plugin::INIT_PARAMS, Aspera::Cli::Plugin::INSTANCE_OPS, Aspera::Cli::Plugin::MAX_ITEMS, Aspera::Cli::Plugin::MAX_PAGES, Aspera::Cli::Plugin::REGEX_LOOKUP_ID_BY_FIELD

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Aspera::Cli::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(**env) ⇒ Httpgw

Returns a new instance of Httpgw.



28
29
30
31
32
# File 'lib/aspera/cli/plugins/httpgw.rb', line 28

def initialize(**env)
  super
  options.declare(:url, 'URL of application, e.g. https://app.example.com/aspera/app')
  options.parse_options!
end

Class Method Details

.application_nameObject



12
13
14
# File 'lib/aspera/cli/plugins/httpgw.rb', line 12

def application_name
  'HTTP Gateway'
end

.detect(base_url) ⇒ Object



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

def detect(base_url)
  api = Api::Httpgw.new(url: base_url)
  api_info = api.info
  return {
    url:     base_url,
    version: api_info['version']
  } if api_info.is_a?(Hash) && api_info.key?('download_endpoint')
  return nil
end

Instance Method Details

#execute_actionObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/aspera/cli/plugins/httpgw.rb', line 34

def execute_action
  base_url = options.get_option(:url, mandatory: true)
  command = options.get_next_command(ACTIONS)
  case command
  when :health
    nagios = Nagios.new
    begin
      Api::Httpgw.new(url: base_url)
      nagios.add_ok('api', 'answered ok')
    rescue StandardError => e
      nagios.add_critical('api', e.to_s)
    end
    return nagios.result
  when :info
    api_v1 = Api::Httpgw.new(url: base_url)
    return {type: :single_object, data: api_v1.info}
  end
end