Class: Aspera::Cli::Plugins::Console

Inherits:
BasicAuthPlugin show all
Defined in:
lib/aspera/cli/plugins/console.rb

Constant Summary collapse

ACTIONS =
%i[transfer health].freeze

Constants inherited from Aspera::Cli::Plugin

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

Instance Method Summary collapse

Methods inherited from BasicAuthPlugin

#basic_auth_api, #basic_auth_params, register_options

Methods inherited from Aspera::Cli::Plugin

#do_bulk_operation, #entity_action, #entity_command, #instance_identifier, #old_query_read_delete, #query_read_delete, #value_create_modify, #value_or_query

Constructor Details

#initialize(env) ⇒ Console

Returns a new instance of Console.



12
13
14
15
16
17
18
# File 'lib/aspera/cli/plugins/console.rb', line 12

def initialize(env)
  super(env)
  time_now = Time.now
  options.declare(:filter_from, 'Only after date', values: :date, default: Manager.time_to_string(time_now - DEFAULT_FILTER_AGE_SECONDS))
  options.declare(:filter_to, 'Only before date', values: :date, default: Manager.time_to_string(time_now))
  options.parse_options!
end

Instance Method Details

#execute_actionObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/aspera/cli/plugins/console.rb', line 22

def execute_action
  api_console = basic_auth_api('api')
  command = options.get_next_command(ACTIONS)
  case command
  when :health
    nagios = Nagios.new
    begin
      api_console.read('ssh_keys')
      nagios.add_ok('console api', 'accessible')
    rescue StandardError => e
      nagios.add_critical('console api', e.to_s)
    end
    return nagios.result
  when :transfer
    command = options.get_next_command(%i[current smart])
    case command
    when :smart
      command = options.get_next_command(%i[list submit])
      case command
      when :list
        return {type: :object_list, data: api_console.read('smart_transfers')[:data]}
      when :submit
        smart_id = options.get_next_argument('smart_id')
        params = options.get_next_argument('transfer parameters')
        return {type: :object_list, data: api_console.create('smart_transfers/' + smart_id, params)[:data]}
      end
    when :current
      command = options.get_next_command([:list])
      case command
      when :list
        return {
          type:   :object_list,
          data:   api_console.read('transfers', {
            'from' => options.get_option(:filter_from, mandatory: true),
            'to'   => options.get_option(:filter_to, mandatory: true)
          })[:data],
          fields: %w[id contact name status]}
      end
    end
  end
end