Class: Aspera::Cli::Plugins::Console
- Defined in:
- lib/aspera/cli/plugins/console.rb
Constant Summary collapse
- ACTIONS =
i[transfer health].freeze
Constants inherited from Base
Base::ALL_OPS, Base::GLOBAL_OPS, Base::INSTANCE_OPS, Base::MAX_ITEMS, Base::MAX_PAGES
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #execute_action ⇒ Object
-
#initialize(**_) ⇒ Console
constructor
A new instance of Console.
- #parse_extended_filter(filter, query) ⇒ Object
-
#wizard(wizard, app_url) ⇒ Hash
:preset_value, :test_args.
Methods inherited from BasicAuth
#basic_auth_api, #basic_auth_params, declare_options
Methods inherited from Base
#add_manual_header, #config, declare_options, #do_bulk_operation, #entity_execute, #formatter, #instance_identifier, #list_entities_limit_offset_total_count, #lookup_entity_by_field, #lookup_entity_generic, #options, percent_selector, #persistency, #query_read_delete, #transfer, #value_create_modify
Constructor Details
#initialize(**_) ⇒ Console
Returns a new instance of Console.
69 70 71 |
# File 'lib/aspera/cli/plugins/console.rb', line 69 def initialize(**_) super end |
Class Method Details
.detect(address_or_url) ⇒ Hash, NilClass
17 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 |
# File 'lib/aspera/cli/plugins/console.rb', line 17 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
50 51 52 |
# File 'lib/aspera/cli/plugins/console.rb', line 50 def time_to_string(time) return time.strftime('%Y-%m-%d %H:%M:%S') end |
Instance Method Details
#execute_action ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/aspera/cli/plugins/console.rb', line 88 def execute_action api_console = basic_auth_api('api') command = .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 Main.result_object_list(nagios.status_list) when :transfer command = .get_next_command(i[current smart]) case command when :smart command = .get_next_command(i[list submit]) case command when :list return Main.result_object_list(api_console.read('smart_transfers')) when :submit smart_id = .get_next_argument('smart_id') params = .get_next_argument('transfer parameters', validation: Hash) return Main.result_object_list(api_console.create("smart_transfers/#{smart_id}", params)) end when :current command = .get_next_command(i[list show files start pause cancel resume rerun change_rate change_policy move_forwards move_back]) case command when :list # https://developer.ibm.com/apis/catalog/aspera--aspera-console-rest-api/Developer+Guides#transfer-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 if (filter = query.delete('filter')) parse_extended_filter(filter, query) end return Main.result_object_list( api_console.read('transfers', query), fields: %w[id contact name status] ) when :show transfer_id = instance_identifier(description: 'transfer ID') return Main.result_single_object(api_console.read("transfers/#{transfer_id}")) when :files transfer_id = instance_identifier(description: 'transfer ID') query = query_read_delete(default: {}) query['limit'] ||= 100 return Main.result_object_list(api_console.read("transfers/#{transfer_id}/files", query)) when :start, :pause, :cancel, :resume, :rerun, :change_rate, :change_policy, :move_forwards, :move_back transfer_id = instance_identifier(description: 'transfer ID') return Main.result_single_object(api_console.update("transfers/#{transfer_id}/#{command}", query_read_delete)) end end end end |
#parse_extended_filter(filter, query) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/aspera/cli/plugins/console.rb', line 73 def parse_extended_filter(filter, query) raise BadArgument, "Invalid filter syntax: #{filter}, shall be (field op val)and(field op val)..." unless filter.start_with?('(') && filter.end_with?(')') filter[1..-2].split(')and(').each_with_index do |expr, i| m = expr.match(EXPR_RE) raise BadArgument, "Invalid expression: #{expr}, shall be: <field> <op> <val>" unless m t = m.captures i += 1 query["filter#{i}"] = t[0] query["comp#{i}"] = t[1] query["val#{i}"] = t[2] end end |
#wizard(wizard, app_url) ⇒ Hash
Returns :preset_value, :test_args.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/aspera/cli/plugins/console.rb', line 58 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 |