Method: Aspera::Cli::Plugins::Console#execute_action

Defined in:
lib/aspera/cli/plugins/console.rb

#execute_actionObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/aspera/cli/plugins/console.rb', line 67

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')}
      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)}
      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)
          }),
          fields: %w[id contact name status]}
      end
    end
  end
end