Class: Aspera::Plugins::Console::Commands
- Inherits:
-
Cli::Plugins::Base
- Object
- Cli::Plugins::Base
- Aspera::Plugins::Console::Commands
- Includes:
- Cli::Plugins::BasicAuth
- Defined in:
- lib/aspera/plugins/console/commands.rb
Constant Summary collapse
- API_SCHEMA =
'console'
Constants inherited from Cli::Plugins::Base
Cli::Plugins::Base::FILTER_ARGS
Instance Attribute Summary
Attributes inherited from Cli::Plugins::Base
Class Method Summary collapse
- .detect(address_or_url) ⇒ Hash, NilClass
-
.time_to_string(time) ⇒ String
Date and time in UTC, as expected by the API, e.g.
Instance Method Summary collapse
-
#action_health ⇒ Object
--- health ---.
-
#action_transfer_current_list ⇒ Object
--- transfer current ---.
-
#api_console ⇒ Rest::Client
Console REST API, built from CLI options on first use.
-
#wizard(wizard, app_url) ⇒ Hash
:preset_value, :test_args.
Methods included from Cli::Plugins::BasicAuth
#basic_auth_api, #basic_auth_params, included
Methods included from Cli::Option::Declarator
#declare_options, #option, #option_specs, #register_option_spec
Methods inherited from Cli::Plugins::Base
#action_for, application_name, #bulk_result, #check_argument_access, command, command_registry, commands_under, #config, #crud_api, 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, include_mounts, #initialize, #invoke_action, operation_description, option_sources, option_specs, #options, #persistency, #poll_result, #presets, #progress_bar, #query_read_delete, register_option_spec, #resolve_argument, #resolve_arguments, #transfer, use_options, used_option_sources, #validate_registry
Constructor Details
This class inherits a constructor from Aspera::Cli::Plugins::Base
Class Method Details
.detect(address_or_url) ⇒ Hash, NilClass
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 |
# File 'lib/aspera/plugins/console/commands.rb', line 26 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) ⇒ String
Returns Date and time in UTC, as expected by the API, e.g. 2013-02-28 12:00:00.
61 62 63 |
# File 'lib/aspera/plugins/console/commands.rb', line 61 def time_to_string(time) return time.getutc.strftime('%Y-%m-%d %H:%M:%S') end |
Instance Method Details
#action_health ⇒ Object
--- health ---
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/aspera/plugins/console/commands.rb', line 215 def action_health(**) nagios = Nagios.new begin # Unauthenticated, outside of the API prefix Rest::Client.new(base_url: .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 Cli::Result::ObjectList.new(nagios.status_list) end |
#action_transfer_current_list ⇒ Object
--- transfer current ---
235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/aspera/plugins/console/commands.rb', line 235 def action_transfer_current_list(**) query = query_read_delete(default: {}) query.merge!(DEFAULT_PERIOD) if query['from'].nil? && query['to'].nil? # Dates of the API are in UTC: also a date given without time zone now = Time.now DEFAULT_PERIOD.each_key do |name| query[name] = self.class.time_to_string(Units::Timestamp.parse(query[name], now: now, utc: true)) if query[name].is_a?(String) end parse_extended_filter(query.delete('filter'), query) if query['filter'] Cli::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.
209 210 211 |
# File 'lib/aspera/plugins/console/commands.rb', line 209 def api_console @api_console ||= basic_auth_api('api') end |
#wizard(wizard, app_url) ⇒ Hash
Returns :preset_value, :test_args.
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/aspera/plugins/console/commands.rb', line 69 def wizard(wizard, app_url) username = .get_option(:username, mandatory: true) return { preset_ids: [username], preset_value: { url: app_url, username: username, password: .get_option(:password, mandatory: true) }, test_args: 'transfer current list' } end |