Class: Aspera::Cli::Plugins::Console
- Defined in:
- lib/aspera/cli/plugins/console.rb
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
-
#action_health(api_console:) ⇒ Object
--- health ---.
- #action_transfer_current_files(api_console:, transfer_id:) ⇒ Object
-
#action_transfer_current_list(api_console:) ⇒ Object
--- transfer current ---.
-
#action_transfer_smart_submit(api_console:, smart_id:, transfer_params:) ⇒ Object
--- transfer smart ---.
-
#initialize(**_) ⇒ Console
constructor
A new instance of Console.
-
#setup_api ⇒ Hash
Build the Console REST API.
-
#wizard(wizard, app_url) ⇒ Hash
:preset_value, :test_args.
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, #entity_create, #entity_delete, entity_display_name, #entity_list, #entity_modify, #entity_res_path, #entity_show, #execute_action, #execute_leaf, file_matcher, #formatter, #generate_help, #http_config, #invoke_action, option, #options, #persistency, #presets, #progress_bar, #query_read_delete, #resolve_argument, root_setup, #transfer, use_options, used_option_sources
Constructor Details
#initialize(**_) ⇒ Console
Returns a new instance of Console.
70 71 72 |
# File 'lib/aspera/cli/plugins/console.rb', line 70 def initialize(**_) super end |
Class Method Details
.detect(address_or_url) ⇒ Hash, NilClass
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.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(api_console:) ⇒ Object
--- health ---
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/aspera/cli/plugins/console.rb', line 136 def action_health(api_console:) 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 Result::ObjectList.new(nagios.status_list) end |
#action_transfer_current_files(api_console:, transfer_id:) ⇒ Object
163 164 165 166 167 |
# File 'lib/aspera/cli/plugins/console.rb', line 163 def action_transfer_current_files(api_console:, transfer_id:, **) query = query_read_delete(default: {}) query['limit'] ||= 100 Result::ObjectList.new(api_console.read("transfers/#{transfer_id}/files", query)) end |
#action_transfer_current_list(api_console:) ⇒ Object
--- transfer current ---
149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/aspera/cli/plugins/console.rb', line 149 def action_transfer_current_list(api_console:) 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 |
#action_transfer_smart_submit(api_console:, smart_id:, transfer_params:) ⇒ Object
--- transfer smart ---
171 172 173 |
# File 'lib/aspera/cli/plugins/console.rb', line 171 def action_transfer_smart_submit(api_console:, smart_id:, transfer_params:, **) Result::ObjectList.new(api_console.create("smart_transfers/#{smart_id}", transfer_params)) end |
#setup_api ⇒ Hash
Build the Console REST API.
130 131 132 |
# File 'lib/aspera/cli/plugins/console.rb', line 130 def setup_api(**) {api_console: basic_auth_api('api')} end |
#wizard(wizard, app_url) ⇒ Hash
Returns :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: .get_option(:username, mandatory: true), password: .get_option(:password, mandatory: true) }, test_args: 'transfer list' } end |