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

Inherits:
BasicAuth show all
Defined in:
lib/aspera/cli/plugins/console.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(address_or_url) ⇒ Hash, NilClass

Returns:



18
19
20
21
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
# File 'lib/aspera/cli/plugins/console.rb', line 18

def detect(address_or_url)
  address_or_url = "https://#{address_or_url}" unless address_or_url.match?(%r{^[a-z]{1,6}://})
  urls = [address_or_url]
  urls.push("#{address_or_url}#{STANDARD_PATH}") unless address_or_url.end_with?(STANDARD_PATH)
  error = nil
  urls.each do |base_url|
    next unless base_url.start_with?('https://')
    api = Rest::Client.new(base_url: base_url, redirect_max: 2)
    test_endpoint = 'login'
    http = api.call(
      operation: 'GET',
      subpath:   test_endpoint,
      query:     {local: true},
      ret:       :resp
    )
    next unless http.body.include?('Aspera Console')
    version = 'unknown'
    if (m = http.body.match(/\(v([1-9]\..*)\)/))
      version = m[1]
    end
    url = http.uri.to_s
    return {
      version: version,
      url:     url[0..url.index(test_endpoint) - 2]
    }
  rescue StandardError => e
    error = e
    Log.log.debug { "detect error: #{e}" }
  end
  raise error if error
  return
end

.time_to_string(time) ⇒ Object



51
52
53
# File 'lib/aspera/cli/plugins/console.rb', line 51

def time_to_string(time)
  return time.strftime('%Y-%m-%d %H:%M:%S')
end

Instance Method Details

#action_health ⇒ Object

--- health ---



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/aspera/cli/plugins/console.rb', line 203

def action_health(**)
  nagios = Nagios.new
  begin
    # Unauthenticated, outside of the API prefix
    Rest::Client.new(base_url: options.get_option(:url, mandatory: true)).read('health/up')
    nagios.add_ok('console process', 'up')
  rescue StandardError => e
    nagios.add_critical('console process', e.to_s)
  end
  begin
    api_console.read('ssh_keys')
    nagios.add_ok('console api', 'accessible')
  rescue StandardError => e
    nagios.add_critical('console api', e.to_s)
  end
  Result::ObjectList.new(nagios.status_list)
end

#action_transfer_current_list ⇒ Object

--- transfer current ---



223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/aspera/cli/plugins/console.rb', line 223

def action_transfer_current_list(**)
  query = query_read_delete(default: {})
  if query['from'].nil? && query['to'].nil?
    time_now = Time.now
    query['from'] = self.class.time_to_string(time_now - DEFAULT_FILTER_AGE_SECONDS)
    query['to'] = self.class.time_to_string(time_now)
  end
  parse_extended_filter(query.delete('filter'), query) if query['filter']
  Result::ObjectList.new(
    api_console.read('transfers', query),
    fields: %w[id contact name status]
  )
end

#api_console ⇒ Rest::Client

Console REST API, built from CLI options on first use.

Returns:



197
198
199
# File 'lib/aspera/cli/plugins/console.rb', line 197

def api_console
  @api_console ||= basic_auth_api('api')
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



59
60
61
62
63
64
65
66
67
68
# File 'lib/aspera/cli/plugins/console.rb', line 59

def wizard(wizard, app_url)
  return {
    preset_value: {
      url:      app_url,
      username: options.get_option(:username, mandatory: true),
      password: options.get_option(:password, mandatory: true)
    },
    test_args:    'transfer list'
  }
end