Class: Aspera::Cli::Plugins::Alee

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

Constant Summary collapse

ACTIONS =
%i[health entitlement].freeze

Constants inherited from Base

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

Instance Attribute Summary

Attributes inherited from Base

#context

Instance Method Summary collapse

Methods inherited from BasicAuth

#basic_auth_api, #basic_auth_params, declare_options, #initialize

Methods inherited from Base

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

Constructor Details

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

Instance Method Details

#execute_actionObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/aspera/cli/plugins/alee.rb', line 13

def execute_action
  command = options.get_next_command(ACTIONS)
  case command
  when :health
    nagios = Nagios.new
    begin
      api = Api::Alee.new(nil, nil, version: 'ping')
      result = api.call(operation: 'GET')
      raise "unexpected response: #{result[:http].body}" unless result[:http].body.eql?('pong')
      nagios.add_ok('api', 'answered ok')
    rescue StandardError => e
      nagios.add_critical('api', e.to_s)
    end
    return nagios.result
  when :entitlement
    entitlement_id = options.get_option(:username, mandatory: true)
    customer_id = options.get_option(:password, mandatory: true)
    api_metering = Api::Alee.new(entitlement_id, customer_id)
    return Main.result_single_object(api_metering.read('entitlement'))
  end
end