aspera-cli 4.28.0 → 4.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/BUGS.md +5 -10
- data/CHANGELOG.md +143 -2
- data/CODE_OF_CONDUCT.md +18 -0
- data/CONTRIBUTING.md +135 -56
- data/GOVERNANCE.md +30 -0
- data/LICENSE +201 -0
- data/README.md +103 -26
- data/SECURITY.md +70 -0
- data/bin/ascli +8 -5
- data/bin/asession +9 -6
- data/docs/README.md +1633 -609
- data/docs/test-mcp-with-ai.md +8 -8
- data/lib/aspera/agent/base.rb +23 -2
- data/lib/aspera/agent/connect.rb +16 -12
- data/lib/aspera/agent/desktop.rb +10 -7
- data/lib/aspera/agent/direct.rb +20 -19
- data/lib/aspera/agent/factory.rb +6 -3
- data/lib/aspera/agent/httpgw.rb +7 -5
- data/lib/aspera/agent/node.rb +15 -7
- data/lib/aspera/agent/transferd.rb +167 -43
- data/lib/aspera/api/alee.rb +4 -1
- data/lib/aspera/api/aoc.rb +14 -11
- data/lib/aspera/api/ats.rb +4 -2
- data/lib/aspera/api/cos_node.rb +7 -4
- data/lib/aspera/api/faspex.rb +16 -9
- data/lib/aspera/api/httpgw.rb +9 -6
- data/lib/aspera/api/node.rb +20 -20
- data/lib/aspera/ascmd.rb +8 -5
- data/lib/aspera/ascp/installation.rb +71 -65
- data/lib/aspera/ascp/log.schema.yaml +1084 -0
- data/lib/aspera/ascp/log_analyzer/advice.rb +97 -0
- data/lib/aspera/ascp/log_analyzer/diagnostics.rb +344 -0
- data/lib/aspera/ascp/log_analyzer/lines.rb +75 -0
- data/lib/aspera/ascp/log_analyzer/log_file.rb +593 -0
- data/lib/aspera/ascp/log_analyzer/records.rb +379 -0
- data/lib/aspera/ascp/log_analyzer/rules.rb +172 -0
- data/lib/aspera/ascp/log_analyzer/session.rb +782 -0
- data/lib/aspera/ascp/log_analyzer.rb +354 -0
- data/lib/aspera/ascp/management.rb +16 -8
- data/lib/aspera/ascp/session_errors.rb +217 -0
- data/lib/aspera/assert.rb +4 -0
- data/lib/aspera/cli/ascp_actions.rb +12 -19
- data/lib/aspera/cli/ascp_logs_actions.rb +176 -0
- data/lib/aspera/cli/async_transfer_store.rb +7 -4
- data/lib/aspera/cli/bootstrapper.rb +37 -33
- data/lib/aspera/cli/command_line.rb +24 -6
- data/lib/aspera/cli/command_registry.rb +6 -1
- data/lib/aspera/cli/command_spec.rb +34 -7
- data/lib/aspera/cli/completion/ascli.bash +19 -5
- data/lib/aspera/cli/completion/ascli.fish +13 -2
- data/lib/aspera/cli/completion/ascli.ps1 +31 -9
- data/lib/aspera/cli/completion/ascli.zsh +22 -6
- data/lib/aspera/cli/completion_actions.rb +303 -69
- data/lib/aspera/cli/context.rb +9 -4
- data/lib/aspera/cli/deprecation.rb +5 -2
- data/lib/aspera/cli/error.rb +3 -0
- data/lib/aspera/cli/extended_value.rb +61 -27
- data/lib/aspera/cli/formatter.rb +29 -22
- data/lib/aspera/cli/gem_checker.rb +9 -6
- data/lib/aspera/cli/hints.rb +22 -10
- data/lib/aspera/cli/http.rb +12 -9
- data/lib/aspera/cli/info.rb +12 -7
- data/lib/aspera/cli/mailer.rb +6 -3
- data/lib/aspera/cli/mcp/http_servlet.rb +7 -8
- data/lib/aspera/cli/mcp/secrets.rb +8 -5
- data/lib/aspera/cli/mcp/tool.rb +15 -14
- data/lib/aspera/cli/option_declarator.rb +10 -4
- data/lib/aspera/cli/option_registry.rb +6 -3
- data/lib/aspera/cli/option_types.rb +17 -2
- data/lib/aspera/cli/option_value.rb +65 -12
- data/lib/aspera/cli/options.schema.yaml +487 -63
- data/lib/aspera/cli/parser.rb +56 -32
- data/lib/aspera/cli/plugins/alee.rb +7 -4
- data/lib/aspera/cli/plugins/aoc.rb +244 -35
- data/lib/aspera/cli/plugins/ats.rb +9 -8
- data/lib/aspera/cli/plugins/base.rb +17 -12
- data/lib/aspera/cli/plugins/basic_auth.rb +5 -2
- data/lib/aspera/cli/plugins/config.rb +198 -103
- data/lib/aspera/cli/plugins/console.rb +6 -3
- data/lib/aspera/cli/plugins/cos.rb +8 -4
- data/lib/aspera/cli/plugins/factory.rb +21 -7
- data/lib/aspera/cli/plugins/faspex5.rb +28 -25
- data/lib/aspera/cli/plugins/faspio.rb +7 -5
- data/lib/aspera/cli/plugins/httpgw.rb +7 -4
- data/lib/aspera/cli/plugins/mcp.rb +28 -22
- data/lib/aspera/cli/plugins/node.rb +31 -30
- data/lib/aspera/cli/plugins/oauth.rb +5 -1
- data/lib/aspera/cli/plugins/orchestrator.rb +272 -72
- data/lib/aspera/cli/plugins/preview.rb +69 -44
- data/lib/aspera/cli/plugins/server.rb +63 -11
- data/lib/aspera/cli/plugins/shares.rb +86 -16
- data/lib/aspera/cli/plugins/transferd.rb +223 -0
- data/lib/aspera/cli/preset_actions.rb +144 -30
- data/lib/aspera/cli/preset_manager.rb +52 -18
- data/lib/aspera/cli/prompt.rb +4 -1
- data/lib/aspera/cli/result.rb +12 -8
- data/lib/aspera/cli/runner.rb +69 -46
- data/lib/aspera/cli/secret_finder.rb +4 -1
- data/lib/aspera/cli/security.rb +79 -9
- data/lib/aspera/cli/special_values.rb +4 -1
- data/lib/aspera/cli/sync_actions.rb +13 -10
- data/lib/aspera/cli/table_fitter.rb +3 -0
- data/lib/aspera/cli/terminal_formatter.rb +9 -6
- data/lib/aspera/cli/transfer_actions.rb +11 -8
- data/lib/aspera/cli/transfer_agent.rb +29 -20
- data/lib/aspera/cli/transfer_progress.rb +13 -45
- data/lib/aspera/cli/vault_actions.rb +45 -0
- data/lib/aspera/cli/vault_manager.rb +188 -42
- data/lib/aspera/cli/version.rb +4 -1
- data/lib/aspera/cli/web_secret.rb +12 -10
- data/lib/aspera/cli/wizard.rb +42 -39
- data/lib/aspera/command_line_builder.rb +9 -5
- data/lib/aspera/command_line_converter.rb +4 -1
- data/lib/aspera/coverage.rb +103 -33
- data/lib/aspera/data_repository.rb +4 -1
- data/lib/aspera/dot_container.rb +4 -1
- data/lib/aspera/duration.rb +5 -2
- data/lib/aspera/environment.rb +21 -12
- data/lib/aspera/exec_spec.rb +3 -0
- data/lib/aspera/faspex_gw.rb +13 -9
- data/lib/aspera/faspex_postproc.rb +15 -12
- data/lib/aspera/formatter_interface.rb +4 -1
- data/lib/aspera/graphql.rb +5 -1
- data/lib/aspera/hash_ext.rb +3 -0
- data/lib/aspera/id_generator.rb +4 -2
- data/lib/aspera/json_rpc/client.rb +6 -5
- data/lib/aspera/json_rpc/version.rb +3 -0
- data/lib/aspera/line_logger.rb +4 -1
- data/lib/aspera/link_header.rb +4 -1
- data/lib/aspera/log.rb +18 -5
- data/lib/aspera/markdown.rb +5 -2
- data/lib/aspera/mime.rb +3 -0
- data/lib/aspera/nagios.rb +6 -4
- data/lib/aspera/node_emulator.rb +15 -13
- data/lib/aspera/oauth/client/base.rb +91 -70
- data/lib/aspera/oauth/client/boot.rb +7 -4
- data/lib/aspera/oauth/client/factory.rb +6 -3
- data/lib/aspera/oauth/client/generic.rb +5 -1
- data/lib/aspera/oauth/client/json_credentials.rb +4 -1
- data/lib/aspera/oauth/client/jwt.rb +6 -3
- data/lib/aspera/oauth/client/shares_web.rb +85 -0
- data/lib/aspera/oauth/client/url_json.rb +4 -1
- data/lib/aspera/oauth/client/web.rb +39 -12
- data/lib/aspera/oauth/server/pkce.rb +6 -5
- data/lib/aspera/orchestrator_workflow_checker.rb +119 -1
- data/lib/aspera/persistency_action_once.rb +5 -3
- data/lib/aspera/persistency_folder.rb +6 -3
- data/lib/aspera/preview/file_types.rb +6 -3
- data/lib/aspera/preview/generator.rb +9 -5
- data/lib/aspera/preview/options.schema.yaml +3 -3
- data/lib/aspera/preview/terminal.rb +8 -4
- data/lib/aspera/preview/utils.rb +6 -4
- data/lib/aspera/products/connect.rb +5 -2
- data/lib/aspera/products/desktop.rb +4 -1
- data/lib/aspera/products/other.rb +4 -2
- data/lib/aspera/products/transferd.rb +6 -2
- data/lib/aspera/products/transferd_service.rb +610 -0
- data/lib/aspera/proxy_auto_config.js +2 -2
- data/lib/aspera/proxy_auto_config.rb +5 -2
- data/lib/aspera/rainbow.rb +3 -0
- data/lib/aspera/rest/aspera_errors.rb +4 -1
- data/lib/aspera/rest/call_error.rb +3 -0
- data/lib/aspera/rest/client.rb +22 -29
- data/lib/aspera/rest/error_analyzer.rb +5 -2
- data/lib/aspera/rest/list.rb +8 -4
- data/lib/aspera/rest/parameters.rb +3 -0
- data/lib/aspera/rest/util.rb +8 -5
- data/lib/aspera/rest.rb +9 -6
- data/lib/aspera/schema/IBM Aspera Faspex API-5.0-enhanced.yaml +9 -9
- data/lib/aspera/schema/IBM Aspera Orchestrator API-v1-enhanced.yaml +118 -30
- data/lib/aspera/schema/IBM Aspera on Cloud API-0.2.6-enhanced.yaml +11 -11
- data/lib/aspera/schema/IBM Aspera on Cloud Automation API-1.0.5-enhanced.yaml +2437 -1437
- data/lib/aspera/schema/async_tables.yaml +11 -10
- data/lib/aspera/schema/documentation.rb +8 -2
- data/lib/aspera/schema/reader.rb +7 -0
- data/lib/aspera/schema/registry.rb +43 -28
- data/lib/aspera/schema/transferd-config.schema.json +333 -0
- data/lib/aspera/schema/validator.rb +4 -1
- data/lib/aspera/sealed_hash.rb +166 -0
- data/lib/aspera/secret/hider.rb +201 -0
- data/lib/aspera/secret/reference.rb +150 -0
- data/lib/aspera/secret/resolver.rb +212 -0
- data/lib/aspera/secret/store/base.rb +153 -0
- data/lib/aspera/secret/store/encrypted_hash.rb +329 -0
- data/lib/aspera/secret/store/factory.rb +103 -0
- data/lib/aspera/secret/store/hashicorp_vault.rb +390 -0
- data/lib/aspera/secret/store/keeper.rb +141 -0
- data/lib/aspera/secret/store/macos_security.rb +284 -0
- data/lib/aspera/secret/store/one_password_api.rb +99 -0
- data/lib/aspera/secret/store/one_password_base.rb +42 -0
- data/lib/aspera/secret/store/one_password_cli.rb +110 -0
- data/lib/aspera/secret/store/secret_service.rb +125 -0
- data/lib/aspera/secret/strength.rb +119 -0
- data/lib/aspera/servlet_helpers.rb +5 -2
- data/lib/aspera/ssh.rb +10 -7
- data/lib/aspera/ssl.rb +5 -2
- data/lib/aspera/string_ext.rb +3 -0
- data/lib/aspera/sync/args.schema.yaml +3 -0
- data/lib/aspera/sync/conf.schema.yaml +9 -4
- data/lib/aspera/sync/database.rb +3 -0
- data/lib/aspera/sync/operations.rb +16 -14
- data/lib/aspera/temp_file_manager.rb +8 -4
- data/lib/aspera/timer_limiter.rb +3 -0
- data/lib/aspera/transfer/error.rb +4 -1
- data/lib/aspera/transfer/faux_file.rb +4 -1
- data/lib/aspera/transfer/parameters.rb +17 -14
- data/lib/aspera/transfer/result.rb +3 -0
- data/lib/aspera/transfer/resumer.rb +6 -4
- data/lib/aspera/transfer/spec.rb +9 -22
- data/lib/aspera/transfer/units.rb +75 -0
- data/lib/aspera/uri_reader.rb +57 -7
- data/lib/aspera/web_auth/index.html.erb +6 -2
- data/lib/aspera/web_auth/paste.rb +109 -0
- data/lib/aspera/web_auth/receiver.rb +50 -0
- data/lib/aspera/web_auth/relay.rb +76 -0
- data/lib/aspera/web_auth/reply.html.erb +150 -0
- data/lib/aspera/web_auth/server.rb +47 -10
- data/lib/aspera/web_page.rb +7 -2
- data/lib/aspera/web_server_simple.rb +6 -3
- data/lib/aspera/yaml.rb +5 -1
- data/llms.txt +81 -0
- data/skills/ascli/SKILL.md +88 -0
- data.tar.gz.sig +0 -0
- metadata +72 -19
- metadata.gz.sig +0 -0
- data/lib/aspera/keychain/base.rb +0 -30
- data/lib/aspera/keychain/encrypted_hash.rb +0 -192
- data/lib/aspera/keychain/factory.rb +0 -58
- data/lib/aspera/keychain/hashicorp_vault.rb +0 -77
- data/lib/aspera/keychain/macos_security.rb +0 -277
- data/lib/aspera/keychain/one_password_api.rb +0 -91
- data/lib/aspera/keychain/one_password_base.rb +0 -39
- data/lib/aspera/keychain/one_password_cli.rb +0 -100
- data/lib/aspera/secret_hider.rb +0 -196
- data/lib/aspera/secret_strength.rb +0 -114
data/lib/aspera/assert.rb
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
3
6
|
module Aspera
|
|
4
7
|
# Generic error in gem
|
|
5
8
|
class Error < StandardError
|
|
@@ -30,6 +33,7 @@ module Aspera
|
|
|
30
33
|
# @return [nil]
|
|
31
34
|
def report_error(type, message)
|
|
32
35
|
if type.is_a?(Symbol)
|
|
36
|
+
require_relative 'log'
|
|
33
37
|
Log.log.send(type, message)
|
|
34
38
|
else
|
|
35
39
|
raise type, message
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../agent/factory'
|
|
7
|
+
require_relative '../schema/registry'
|
|
8
|
+
require_relative '../schema/reader'
|
|
9
|
+
require_relative '../schema/documentation'
|
|
10
|
+
require_relative '../ascp/session_errors'
|
|
7
11
|
|
|
8
12
|
module Aspera
|
|
9
13
|
module Cli
|
|
@@ -45,21 +49,8 @@ module Aspera
|
|
|
45
49
|
end
|
|
46
50
|
end
|
|
47
51
|
|
|
48
|
-
# Install the transfer SDK (ascp + transferd) from a URL or using the default source.
|
|
49
|
-
# Version defaults to `Info::SDK_VERSION`; pass `LATEST` as argument to install the latest available version.
|
|
50
|
-
# @param version [String, nil] version to install; nil means use the default SDK version
|
|
51
|
-
# @return [Result::Status] installation result message
|
|
52
|
-
def install_transfer_sdk(version: nil)
|
|
53
|
-
asked_version = version.nil? ? Info::SDK_VERSION : version
|
|
54
|
-
asked_version = nil if asked_version.eql?(SpecialValues::LATEST)
|
|
55
|
-
sdk_url = options.get_option(:sdk_url, mandatory: true)
|
|
56
|
-
sdk_url = nil if sdk_url.eql?(SpecialValues::DEF)
|
|
57
|
-
name, ver, folder = Ascp::Installation.instance.install_sdk(url: sdk_url, version: asked_version)
|
|
58
|
-
return Result::Status.new("Installed #{name} version #{ver} in #{folder}")
|
|
59
|
-
end
|
|
60
|
-
|
|
61
52
|
def action_ascp_info(**)
|
|
62
|
-
|
|
53
|
+
Secret::Hider.instance.add_secret_keys(DataRepository::ELEMENTS)
|
|
63
54
|
data = Ascp::Installation.instance.ascp_info
|
|
64
55
|
data['ts'] = transfer.user_transfer_spec
|
|
65
56
|
DataRepository::ELEMENTS.each_with_object(data) { |i, h| h[i.to_s] = DataRepository.instance.item(i) }
|
|
@@ -73,7 +64,9 @@ module Aspera
|
|
|
73
64
|
Result::SingleObject.new(schema)
|
|
74
65
|
end
|
|
75
66
|
|
|
76
|
-
|
|
67
|
+
# @param kind [Symbol] `management`: codes of the management port, `session`: codes of sessions, as `errcode` in logs
|
|
68
|
+
def action_ascp_errors(kind: :management, **)
|
|
69
|
+
return Result::ObjectList.new(Ascp::SessionErrors.list) if kind.eql?(:session)
|
|
77
70
|
error_data = []
|
|
78
71
|
Ascp::Management::ERRORS.each_pair do |code, prop|
|
|
79
72
|
error_data.push(code: code, mnemonic: prop[:c], retry: prop[:r], info: prop[:a])
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../schema/registry'
|
|
7
|
+
require_relative '../assert'
|
|
8
|
+
require_relative '../log'
|
|
9
|
+
|
|
10
|
+
module Aspera
|
|
11
|
+
module Cli
|
|
12
|
+
# Mixin for Config plugin: commands of `ascp logs`, analysis of `ascp` log files (sessions, statistics and diagnostics)
|
|
13
|
+
module AscpLogsActions
|
|
14
|
+
LOG_FILES = [{name: :paths, description: 'Log files (gzip supported), `-` for standard input, or folders with log files', multiple: true, complete: :file}].freeze
|
|
15
|
+
# Command => description, and default fields
|
|
16
|
+
LISTS = {
|
|
17
|
+
sessions: ['Sessions, with diagnostics', %w[pid session user direction peer status error error_category start transmitted_bytes average_rate loss_rate diagnostics]],
|
|
18
|
+
diagnostics: ['Diagnostics of sessions: id, severity, message', nil],
|
|
19
|
+
multi_sessions: ['Multi-session transfers: sessions with the same transfer identifier', nil],
|
|
20
|
+
snapshots: ['Aggregate rates (bps) per period', nil],
|
|
21
|
+
snapshot_sessions: ['Rates (bps) of sessions per period', nil],
|
|
22
|
+
peers: ['Sessions and errors by peer address', nil],
|
|
23
|
+
transfers: ['Transferred files', %w[session peer start path size status error]],
|
|
24
|
+
licenses: ['Licenses of local and peer systems', nil],
|
|
25
|
+
overdrives: ['Sessions with loss due to overdriving of network or storage, by peer', nil]
|
|
26
|
+
}.freeze
|
|
27
|
+
# Kind of record of log lines => description, and default fields
|
|
28
|
+
RECORDS = {
|
|
29
|
+
samples: ['Periodic statistics of sessions: `Receiver bl` or `Sender bl` line, with its `DS Qs` line', %w[time pid side rate.t rate.c rate.n prog.t prog.e]],
|
|
30
|
+
sessions: ['Sessions: `Session Start`, `Params`, `Stop` and `Statistics` lines, with license, MTU and rate lines of the process', %w[uuid pid start stop op status errstr user peer targetrate effective_rate]],
|
|
31
|
+
transfers: ['Files: `Transfer Start` and `Transfer Stop` lines', %w[uuid start stop op status file size rate]]
|
|
32
|
+
}.freeze
|
|
33
|
+
RECORD_KIND = {name: :kind, description: RECORDS.map { |kind, (description, _)| "#{kind}: #{description}" }.join(', '), allowed: RECORDS.keys}.freeze
|
|
34
|
+
# Default values of option `ascp_logs` (see schema `AscpLogsOptions`)
|
|
35
|
+
DEFAULTS = {'period' => 1, 'zero_bytes' => false, 'mtu' => nil, 'resolve' => false, 'thresholds' => {}, 'timezone' => nil, 'health_minutes' => 60, 'remote_max_size' => 268_435_456}.freeze
|
|
36
|
+
private_constant :LOG_FILES, :LISTS, :RECORDS, :RECORD_KIND, :DEFAULTS
|
|
37
|
+
# When a plugin class includes AscpLogsActions, register the :ascp_logs option
|
|
38
|
+
# in that class's DSL registry so Base#initialize auto-declares it,
|
|
39
|
+
# and add the class-level DSL methods of ClassMethods.
|
|
40
|
+
class << self
|
|
41
|
+
def included(base)
|
|
42
|
+
base.option(:ascp_logs, description: 'Ascp: log analysis (dot-notation: period, zero_bytes, mtu, resolve, thresholds, timezone, health_minutes, remote_max_size)', schema: Schema::Registry::ASCP_LOGS_OPTIONS)
|
|
43
|
+
base.extend(ClassMethods)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Class-level DSL methods added to the plugin class that includes AscpLogsActions.
|
|
48
|
+
module ClassMethods
|
|
49
|
+
# DSL class method: declare the `logs` node and its commands.
|
|
50
|
+
# @param parent [Symbol, Array<Symbol>] path relative to current scope, e.g. :logs
|
|
51
|
+
# @param arguments [Array<Hash>] argument that gives the log files (default: local files)
|
|
52
|
+
def ascp_logs_commands(parent, arguments: LOG_FILES)
|
|
53
|
+
commands_under(parent, description: 'Analyze ascp log files') do
|
|
54
|
+
command(:summary, description: 'Statistics and findings', arguments: arguments, action: :action_ascp_logs_summary)
|
|
55
|
+
command(:health, description: 'Health check for monitoring', arguments: arguments, action: :action_ascp_logs_health)
|
|
56
|
+
LISTS.each do |name, (description, fields)|
|
|
57
|
+
command(name, description: description, arguments: arguments, action: ->(paths:, **) { Result::ObjectList.new(analyze_ascp_logs(paths).public_send(name), fields: fields) })
|
|
58
|
+
end
|
|
59
|
+
command(:records, description: 'Log lines parsed into records, with the field names of the log', arguments: [RECORD_KIND] + arguments, action: :action_ascp_logs_records)
|
|
60
|
+
command(:fields, description: 'Description of the fields of records', arguments: [RECORD_KIND], action: :action_ascp_logs_fields)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def action_ascp_logs_summary(paths:, **)
|
|
66
|
+
Result::SingleObject.new(analyze_ascp_logs(paths).summary)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Health check for monitoring. Reports failed sessions and low efficiency sessions over the last N minutes.
|
|
70
|
+
# @param paths [Array<String>] Log files or folders
|
|
71
|
+
# @param now [Time, Integer, nil] Current reference time (can be injected for testing)
|
|
72
|
+
# @return [Aspera::Cli::Result::ObjectList] Nagios status list
|
|
73
|
+
def action_ascp_logs_health(paths:, now: nil, **)
|
|
74
|
+
require_relative '../nagios'
|
|
75
|
+
analyzer = analyze_ascp_logs(paths)
|
|
76
|
+
params = ascp_logs_params
|
|
77
|
+
health_minutes = params['health_minutes'].to_i
|
|
78
|
+
|
|
79
|
+
ref_time = now ? now.to_i : Time.now.to_i
|
|
80
|
+
|
|
81
|
+
failed_count = 0
|
|
82
|
+
low_efficiency_count = 0
|
|
83
|
+
|
|
84
|
+
analyzer.log_files.each do |log_file|
|
|
85
|
+
windows_log = log_file.path.match?(/\w:/)
|
|
86
|
+
log_file.sessions.each do |s|
|
|
87
|
+
start_time = s[:start]
|
|
88
|
+
next unless start_time && start_time >= (ref_time - health_minutes * 60) && start_time <= ref_time
|
|
89
|
+
|
|
90
|
+
s.report(windows_log: windows_log)
|
|
91
|
+
failed_count += 1 if s[:status] == 'failed'
|
|
92
|
+
low_efficiency_count += 1 if s.diagnostics.any? { |d| d['id'] == 'low_efficiency' }
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
nagios = Nagios.new
|
|
97
|
+
msg = "#{failed_count} failed, #{low_efficiency_count} low efficiency in last #{health_minutes} min"
|
|
98
|
+
if failed_count.positive?
|
|
99
|
+
nagios.add_critical('ascp logs', msg)
|
|
100
|
+
elsif low_efficiency_count.positive?
|
|
101
|
+
nagios.add_warning('ascp logs', msg)
|
|
102
|
+
else
|
|
103
|
+
nagios.add_ok('ascp logs', msg)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
Result::ObjectList.new(nagios.status_list)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def action_ascp_logs_records(kind:, paths:, **)
|
|
110
|
+
require_relative '../ascp/log_analyzer'
|
|
111
|
+
ascp_logs_files(paths) do |files|
|
|
112
|
+
check_ascp_logs_paths(files)
|
|
113
|
+
Result::ObjectList.new(Ascp::LogAnalyzer::Records.list(kind, files, timezone: ascp_logs_params['timezone']), fields: RECORDS[kind].last)
|
|
114
|
+
end
|
|
115
|
+
rescue ParameterError => e
|
|
116
|
+
raise BadArgument, e.message
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def action_ascp_logs_fields(kind:, **)
|
|
120
|
+
require_relative '../ascp/log_analyzer'
|
|
121
|
+
require_relative '../schema/documentation'
|
|
122
|
+
builder = Schema::Documentation.new(TerminalFormatter, Schema::Registry.instance.reader(Ascp::LogAnalyzer::Records::SCHEMAS[kind])).build
|
|
123
|
+
Result::ObjectList.new(builder.rows, fields: builder.columns)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
private
|
|
127
|
+
|
|
128
|
+
# @param paths [Array<String>] log files or folders
|
|
129
|
+
# @return [Aspera::Ascp::LogAnalyzer]
|
|
130
|
+
def analyze_ascp_logs(paths)
|
|
131
|
+
require_relative '../ascp/log_analyzer'
|
|
132
|
+
params = ascp_logs_params
|
|
133
|
+
user_thresholds = (params['thresholds'] || {}).transform_keys(&:to_s)
|
|
134
|
+
analyzer = Ascp::LogAnalyzer.new(
|
|
135
|
+
period: params['period'] * 60,
|
|
136
|
+
zero_bytes: params['zero_bytes'],
|
|
137
|
+
mtu: params['mtu'],
|
|
138
|
+
resolve: params['resolve'],
|
|
139
|
+
thresholds: user_thresholds,
|
|
140
|
+
timezone: params['timezone']
|
|
141
|
+
)
|
|
142
|
+
ascp_logs_files(paths) do |files|
|
|
143
|
+
check_ascp_logs_paths(files)
|
|
144
|
+
files.each do |path|
|
|
145
|
+
Log.log.debug { "Analyzing: #{path}" }
|
|
146
|
+
analyzer.add(path)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
analyzer.warnings.each { |warning| Log.log.warn(warning) }
|
|
150
|
+
analyzer
|
|
151
|
+
rescue ParameterError => e
|
|
152
|
+
raise BadArgument, e.message
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Local log files or folders to analyze, for the paths given as arguments.
|
|
156
|
+
# A plugin that gets logs elsewhere (e.g. `server logs`) redefines this method: files exist only during the block.
|
|
157
|
+
# @param paths [Array<String>] arguments of the command
|
|
158
|
+
# @yieldparam files [Array<String>] local log files or folders
|
|
159
|
+
def ascp_logs_files(paths)
|
|
160
|
+
yield(paths)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# @return [Hash] value of option `ascp_logs`, with defaults
|
|
164
|
+
def ascp_logs_params
|
|
165
|
+
DEFAULTS.merge((options.get_option(:ascp_logs) || {}).transform_keys(&:to_s))
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
# Standard input (`-`) is read by the analyzer
|
|
169
|
+
def check_ascp_logs_paths(paths)
|
|
170
|
+
paths.each do |path|
|
|
171
|
+
Aspera.assert(path == Ascp::LogAnalyzer::STDIN_PATH || File.exist?(path), type: BadArgument) { "No such file or folder: #{path}" }
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../log'
|
|
7
|
+
require_relative '../secret/hider'
|
|
5
8
|
require 'json'
|
|
6
9
|
require 'securerandom'
|
|
7
10
|
|
|
@@ -63,7 +66,7 @@ module Aspera
|
|
|
63
66
|
# Keys whose name starts with '_' are in-process references (e.g. '_agent_ref'), and secrets (e.g. agent `password`)
|
|
64
67
|
# are not written on disk: they are intentionally excluded from the JSON serialization — at every nesting level.
|
|
65
68
|
# @param job_id [String] the ascli-generated UUID
|
|
66
|
-
# @param data [Hash] fields to store (will be JSON-
|
|
69
|
+
# @param data [Hash] fields to store (will be JSON-serialized)
|
|
67
70
|
def write(job_id, data)
|
|
68
71
|
Aspera.assert_type(job_id, String) { 'job_id' }
|
|
69
72
|
Aspera.assert_type(data, Hash) { 'data' }
|
|
@@ -113,7 +116,7 @@ module Aspera
|
|
|
113
116
|
case value
|
|
114
117
|
when Hash
|
|
115
118
|
value.each_with_object({}) do |(k, v), h|
|
|
116
|
-
h[k] = persistable(v) unless k.to_s.start_with?('_') ||
|
|
119
|
+
h[k] = persistable(v) unless k.to_s.start_with?('_') || Secret::Hider.instance.secret?(k, v)
|
|
117
120
|
end
|
|
118
121
|
when Array
|
|
119
122
|
value.map { |v| persistable(v) }
|
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative 'plugins/factory'
|
|
7
|
+
require_relative 'extended_value'
|
|
8
|
+
require_relative 'special_values'
|
|
9
|
+
require_relative 'info'
|
|
10
|
+
require_relative 'transfer_progress'
|
|
11
|
+
require_relative 'preset_manager'
|
|
12
|
+
require_relative 'vault_manager'
|
|
13
|
+
require_relative 'http'
|
|
14
|
+
require_relative '../ascp/installation'
|
|
15
|
+
require_relative '../products/transferd'
|
|
16
|
+
require_relative '../transfer/parameters'
|
|
17
|
+
require_relative '../proxy_auto_config'
|
|
18
|
+
require_relative '../environment'
|
|
19
|
+
require_relative '../persistency_folder'
|
|
20
|
+
require_relative '../rest'
|
|
21
|
+
require_relative '../log'
|
|
22
|
+
require_relative '../assert'
|
|
23
|
+
require_relative '../oauth/client/web'
|
|
24
|
+
require_relative '../ssl'
|
|
25
|
+
require_relative '../schema/registry'
|
|
22
26
|
|
|
23
27
|
module Aspera
|
|
24
28
|
module Cli
|
|
@@ -28,7 +32,7 @@ module Aspera
|
|
|
28
32
|
#
|
|
29
33
|
# Responsibilities:
|
|
30
34
|
# - resolve context.main_folder (option :home)
|
|
31
|
-
# - populate context.persistency, context.presets, context.http_config, context.progress_bar
|
|
35
|
+
# - populate context.persistency, context.presets, context.vault, context.http_config, context.progress_bar
|
|
32
36
|
# - register plugin lookup folders
|
|
33
37
|
# - register @preset / @vault extended-value handlers
|
|
34
38
|
# - configure global singletons: Rest::Parameters, OAuth::Factory, SSL, Transfer::Parameters,
|
|
@@ -73,16 +77,15 @@ module Aspera
|
|
|
73
77
|
|
|
74
78
|
# Run the full bootstrap sequence.
|
|
75
79
|
# Must be called after context.options and context.formatter are set.
|
|
76
|
-
# On return, context.persistency, context.presets, context.http_config and
|
|
80
|
+
# On return, context.persistency, context.presets, context.vault, context.http_config and
|
|
77
81
|
# context.progress_bar are populated and all global singletons are configured.
|
|
78
82
|
#
|
|
79
83
|
# @param gem_plugins_folder [String] folder of built-in plugins (from Plugins::Config)
|
|
80
|
-
|
|
81
|
-
def run(gem_plugins_folder:, vault_value_cb:)
|
|
84
|
+
def run(gem_plugins_folder:)
|
|
82
85
|
setup_main_folder
|
|
83
86
|
setup_persistency_and_plugin_folders(gem_plugins_folder)
|
|
84
87
|
setup_config_file
|
|
85
|
-
setup_extended_value_handlers
|
|
88
|
+
setup_extended_value_handlers
|
|
86
89
|
setup_progress_bar
|
|
87
90
|
setup_pac_executor
|
|
88
91
|
setup_rest_and_transfer_runtime
|
|
@@ -94,7 +97,7 @@ module Aspera
|
|
|
94
97
|
def setup_main_folder
|
|
95
98
|
@context.options.declare(
|
|
96
99
|
:home, description: 'Home folder for tool',
|
|
97
|
-
on_set: @context.method(:main_folder=),
|
|
100
|
+
on_set: @context.method(:main_folder=), complete: :folder, security: :low,
|
|
98
101
|
default: default_app_main_folder(app_name: Info::CMD_NAME)
|
|
99
102
|
)
|
|
100
103
|
@context.options.parse_options!
|
|
@@ -105,13 +108,13 @@ module Aspera
|
|
|
105
108
|
def setup_persistency_and_plugin_folders(gem_plugins_folder)
|
|
106
109
|
@context.persistency = PersistencyFolder.new(File.join(@context.main_folder, PERSISTENCY_FOLDER))
|
|
107
110
|
Plugins::Factory.instance.add_lookup_folder(gem_plugins_folder)
|
|
108
|
-
Plugins::Factory.instance.add_lookup_folder(File.join(@context.main_folder, ASPERA_PLUGINS_FOLDERNAME))
|
|
111
|
+
Plugins::Factory.instance.add_lookup_folder(File.join(@context.main_folder, ASPERA_PLUGINS_FOLDERNAME), security: :low)
|
|
109
112
|
end
|
|
110
113
|
|
|
111
114
|
# Declare + parse :config_file option: sets context.presets + context.http_config
|
|
112
115
|
def setup_config_file
|
|
113
116
|
@context.options.declare(
|
|
114
|
-
:config_file, description: 'Path to YAML file with preset configuration',
|
|
117
|
+
:config_file, description: 'Path to YAML file with preset configuration', complete: :file,
|
|
115
118
|
default: File.join(@context.main_folder, DEFAULT_CONFIG_FILENAME)
|
|
116
119
|
)
|
|
117
120
|
@context.options.parse_options!
|
|
@@ -119,15 +122,16 @@ module Aspera
|
|
|
119
122
|
@context.http_config = Http.new
|
|
120
123
|
end
|
|
121
124
|
|
|
122
|
-
#
|
|
123
|
-
def setup_extended_value_handlers
|
|
125
|
+
# context.vault + register @preset and @vault extended-value handlers + global config default preset
|
|
126
|
+
def setup_extended_value_handlers
|
|
124
127
|
@context.options.declare(:secret, description: 'Secret for access keys')
|
|
125
|
-
@context.options.declare(:vault, schema: Schema::Registry::VAULT_OPTIONS)
|
|
128
|
+
@context.options.declare(:vault, schema: Schema::Registry::VAULT_OPTIONS, convert: VaultManager.method(:convert_option))
|
|
126
129
|
@context.options.declare(:vault_password, description: 'Vault password')
|
|
130
|
+
@context.vault = VaultManager.new(@context.options, @context.main_folder)
|
|
127
131
|
# Register @preset and @vault handlers BEFORE parse_options! so that
|
|
128
132
|
# values like --secret=@preset:name are correctly evaluated at parse time.
|
|
129
|
-
ExtendedValue.instance.on(EXTEND_PRESET) { |v| @context.presets.by_name(v) }
|
|
130
|
-
ExtendedValue.instance.on(EXTEND_VAULT,
|
|
133
|
+
ExtendedValue.instance.on(EXTEND_PRESET, description: 'Option preset, or its parameter: <name>[.<parameter>]') { |v| @context.presets.by_name(v) }
|
|
134
|
+
ExtendedValue.instance.on(EXTEND_VAULT, description: 'Secret from vault: <label>.<field> of the default store, or //<store>/<path>[#<field>]') { |v| @context.vault.value(v) }
|
|
131
135
|
@context.options.parse_options!
|
|
132
136
|
# Load global config default preset (equivalent of add_plugin_default_preset(:config))
|
|
133
137
|
default_config_name = @context.presets.plugin_default_name(CONF_GLOBAL_SYM)
|
|
@@ -148,7 +152,7 @@ module Aspera
|
|
|
148
152
|
|
|
149
153
|
# Declare + parse :fpac / :proxy_credentials: sets up PAC executor
|
|
150
154
|
def setup_pac_executor
|
|
151
|
-
@context.options.declare(:fpac, description: 'Proxy auto configuration script')
|
|
155
|
+
@context.options.declare(:fpac, description: 'Proxy auto configuration script', security: :low)
|
|
152
156
|
@context.options.declare(:proxy_credentials, description: 'HTTP proxy credentials for fpac: user, password', allowed: [Array, NilClass])
|
|
153
157
|
@context.options.parse_options!
|
|
154
158
|
pac_script = @context.options.get_option(:fpac)
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative 'error'
|
|
7
|
+
require_relative '../dot_container'
|
|
8
|
+
require_relative '../log'
|
|
9
|
+
require_relative '../assert'
|
|
7
10
|
|
|
8
11
|
module Aspera
|
|
9
12
|
module Cli
|
|
@@ -116,6 +119,10 @@ module Aspera
|
|
|
116
119
|
@current_option = nil
|
|
117
120
|
# When set, only positional arguments after this token are available
|
|
118
121
|
@arguments_after = nil
|
|
122
|
+
# Last positional token consumed by `shift_arguments`
|
|
123
|
+
@last_shifted = nil
|
|
124
|
+
# Token of the last command word (set by `mark_command`)
|
|
125
|
+
@command_token = nil
|
|
119
126
|
process_options = true
|
|
120
127
|
argv.each do |value|
|
|
121
128
|
if process_options && value.eql?(Option::STOP)
|
|
@@ -205,9 +212,18 @@ module Aspera
|
|
|
205
212
|
else Aspera.error_unexpected_value(multiple) { 'multiple' }
|
|
206
213
|
end
|
|
207
214
|
selected.each { |t| t.consumed = true }
|
|
215
|
+
@last_shifted = selected.last unless selected.empty?
|
|
208
216
|
selected.map(&:value)
|
|
209
217
|
end
|
|
210
218
|
|
|
219
|
+
# Remember the last consumed positional token as the current command word.
|
|
220
|
+
# Options placed after it can then be selected with `each_long_option_with_value(after_command: true)`.
|
|
221
|
+
# @return [nil]
|
|
222
|
+
def mark_command
|
|
223
|
+
@command_token = @last_shifted
|
|
224
|
+
nil
|
|
225
|
+
end
|
|
226
|
+
|
|
211
227
|
# Add an argument before the available positional arguments
|
|
212
228
|
# @param value [String] argument value
|
|
213
229
|
def unshift_argument(value)
|
|
@@ -216,9 +232,11 @@ module Aspera
|
|
|
216
232
|
end
|
|
217
233
|
|
|
218
234
|
# Consume all long options with a value, whether applied or not.
|
|
235
|
+
# @param after_command [Boolean] `true`: only options placed after the last command word (see `mark_command`)
|
|
219
236
|
# @yieldparam tok [Option] long option token with a value
|
|
220
|
-
def each_long_option_with_value
|
|
221
|
-
@tokens.
|
|
237
|
+
def each_long_option_with_value(after_command: false)
|
|
238
|
+
start = after_command && @command_token ? @tokens.index { |t| t.equal?(@command_token) } + 1 : 0
|
|
239
|
+
@tokens.drop(start).each do |tok|
|
|
222
240
|
next unless tok.is_a?(Option) && tok.short_char.nil? && !tok.value.nil?
|
|
223
241
|
yield(tok)
|
|
224
242
|
tok.consumed = true
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative 'command_spec'
|
|
7
|
+
require_relative 'option_types'
|
|
4
8
|
|
|
5
9
|
module Aspera
|
|
6
10
|
module Cli
|
|
@@ -322,6 +326,7 @@ module Aspera
|
|
|
322
326
|
# Rule: an argument following an optional one, or one that takes all remaining arguments, is never read reliably
|
|
323
327
|
raise ArgumentError, "#{where}: mandatory after optional #{previous.name}" if previous && arg.mandatory && !previous.mandatory
|
|
324
328
|
raise ArgumentError, "#{where}: after #{previous.name}, which takes all remaining arguments" if previous&.multiple.eql?(true)
|
|
329
|
+
raise ArgumentError, "#{where}: complete: #{arg.complete.inspect} is not one of #{Complete::KINDS.inspect}" unless arg.complete.nil? || Complete::KINDS.include?(arg.complete)
|
|
325
330
|
unless arg.lookup.nil?
|
|
326
331
|
# Rule: the percent-selector lookup is only used for identifiers
|
|
327
332
|
raise ArgumentError, "#{where}: lookup: requires type: :identifier" unless arg.type.eql?(:identifier)
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../schema/registry'
|
|
7
|
+
require_relative 'option_types'
|
|
8
|
+
require_relative 'security'
|
|
5
9
|
|
|
6
10
|
module Aspera
|
|
7
11
|
module Cli
|
|
@@ -24,7 +28,16 @@ module Aspera
|
|
|
24
28
|
# Style: use Symbol for named methods; ->(){} for 1-liners; lambda do…end for 2–3 statements.
|
|
25
29
|
# @!attribute allowed [Array<Symbol>, nil] Allowed Symbol values; when set, type is forced to Symbol and accept_list is applied
|
|
26
30
|
# @!attribute interactive [Boolean] When true, prompts for this argument (only) when no CLI args are provided
|
|
27
|
-
# @!attribute
|
|
31
|
+
# @!attribute evaluate [Symbol] How the value is read, one of `EVALUATIONS`. Default `:extended`.
|
|
32
|
+
# `:extended`: extended value (`@json:`, `@file:`, `@val:`...); a value without prefix stays a string.
|
|
33
|
+
# `:smart`: `true`/`yes`/`false`/`no` and numbers are converted, else extended value (as dotted options).
|
|
34
|
+
# `:none`: the string as typed, not evaluated (e.g. `@env:`).
|
|
35
|
+
# @!attribute complete [Symbol, nil] Values proposed by shell completion, one of `Complete::KINDS` (e.g. `:file`)
|
|
36
|
+
# @!attribute omit_absent [Boolean] For an optional argument: when not given, it is not passed to the action,
|
|
37
|
+
# so that the action (with its own default) can tell it from a value `nil` (`@none:`)
|
|
38
|
+
# Ways to evaluate the value of an argument, see `ArgumentSpec#evaluate`
|
|
39
|
+
EVALUATIONS = %i[extended smart none].freeze
|
|
40
|
+
|
|
28
41
|
ArgumentSpec = Struct.new(
|
|
29
42
|
:name,
|
|
30
43
|
:description,
|
|
@@ -37,7 +50,9 @@ module Aspera
|
|
|
37
50
|
:lookup,
|
|
38
51
|
:allowed,
|
|
39
52
|
:interactive,
|
|
40
|
-
:
|
|
53
|
+
:evaluate,
|
|
54
|
+
:complete,
|
|
55
|
+
:omit_absent,
|
|
41
56
|
keyword_init: true
|
|
42
57
|
) do
|
|
43
58
|
def initialize(**kwargs)
|
|
@@ -45,8 +60,11 @@ module Aspera
|
|
|
45
60
|
kwargs[:multiple] = false if kwargs[:multiple].nil?
|
|
46
61
|
kwargs[:bulk] = false if kwargs[:bulk].nil?
|
|
47
62
|
kwargs[:interactive] = false if kwargs[:interactive].nil?
|
|
48
|
-
kwargs[:
|
|
49
|
-
kwargs[:
|
|
63
|
+
kwargs[:evaluate] = :extended if kwargs[:evaluate].nil?
|
|
64
|
+
kwargs[:omit_absent] = false if kwargs[:omit_absent].nil?
|
|
65
|
+
raise ArgumentError, "omit_absent: only for an optional argument: #{kwargs[:name]}" if kwargs[:omit_absent] && kwargs[:mandatory]
|
|
66
|
+
kwargs[:type] = String unless kwargs.key?(:type) || kwargs[:allowed]
|
|
67
|
+
raise ArgumentError, "evaluate: #{kwargs[:evaluate].inspect}, expecting one of: #{EVALUATIONS.join(', ')}" unless EVALUATIONS.include?(kwargs[:evaluate])
|
|
50
68
|
super
|
|
51
69
|
end
|
|
52
70
|
|
|
@@ -80,6 +98,8 @@ module Aspera
|
|
|
80
98
|
# @!attribute shorthand [String, nil] For a `Hash` option: a `String` value is stored as `{shorthand => value}`
|
|
81
99
|
# @!attribute deprecation [Hash, nil] Forwarded to options.declare as deprecation: `{last:, message:}`
|
|
82
100
|
# @!attribute schema [String, nil] JSON schema name; also derives description when nil
|
|
101
|
+
# @!attribute complete [Symbol, nil] Values proposed by shell completion, one of `Complete::KINDS` (e.g. `:file`)
|
|
102
|
+
# @!attribute security [Symbol, nil] Most restrictive security level at which the option is available (`:low`: executes code), see `Security`
|
|
83
103
|
OptionSpec = Struct.new(
|
|
84
104
|
:name,
|
|
85
105
|
:description,
|
|
@@ -90,6 +110,8 @@ module Aspera
|
|
|
90
110
|
:shorthand,
|
|
91
111
|
:deprecation,
|
|
92
112
|
:schema,
|
|
113
|
+
:complete,
|
|
114
|
+
:security,
|
|
93
115
|
keyword_init: true
|
|
94
116
|
) do
|
|
95
117
|
# Declare this option on a parser, resolving the `on_set` callback.
|
|
@@ -106,7 +128,9 @@ module Aspera
|
|
|
106
128
|
on_set: resolved_on_set(target),
|
|
107
129
|
shorthand: shorthand,
|
|
108
130
|
deprecation: deprecation,
|
|
109
|
-
schema: schema
|
|
131
|
+
schema: schema,
|
|
132
|
+
complete: complete,
|
|
133
|
+
security: security
|
|
110
134
|
)
|
|
111
135
|
end
|
|
112
136
|
|
|
@@ -182,6 +206,7 @@ module Aspera
|
|
|
182
206
|
# @!attribute condition [Symbol, nil] Instance method returning Boolean; if false command is hidden from dispatch
|
|
183
207
|
# @!attribute query_schema [String, nil] Schema path for --query help; when set, the runner hints `--query=help`
|
|
184
208
|
# @!attribute mount [MountSpec, Hash, nil] Expose children of another plugin's registry under this node
|
|
209
|
+
# @!attribute security [Symbol, nil] Most restrictive security level at which the command is available (`:low`: executes code), see `Security`
|
|
185
210
|
CommandSpec = Struct.new(
|
|
186
211
|
:id,
|
|
187
212
|
:parent,
|
|
@@ -194,9 +219,11 @@ module Aspera
|
|
|
194
219
|
:condition,
|
|
195
220
|
:query_schema,
|
|
196
221
|
:mount,
|
|
222
|
+
:security,
|
|
197
223
|
keyword_init: true
|
|
198
224
|
) do
|
|
199
225
|
def initialize(**kwargs)
|
|
226
|
+
Aspera.assert_values(kwargs[:security], Security::LEVELS + [nil]) { "#{kwargs[:id]}: security" }
|
|
200
227
|
# Coerce each element of arguments: from Hash to ArgumentSpec if needed
|
|
201
228
|
if kwargs[:arguments]
|
|
202
229
|
kwargs[:arguments] = kwargs[:arguments].map do |a|
|
|
@@ -18,10 +18,13 @@ _ascli_complete() {
|
|
|
18
18
|
rest=${rest#"$word"}
|
|
19
19
|
done
|
|
20
20
|
local cur=${words[${#words[@]} - 1]}
|
|
21
|
-
# Readline replaces only the text after the last word break character
|
|
21
|
+
# Readline replaces only the text after the last word break character, but with it if it is `@` or `$` (special prefixes)
|
|
22
22
|
local prefix=${cur%"${line##*["$COMP_WORDBREAKS"]}"}
|
|
23
|
+
[[ $prefix == *[@\$] ]] && prefix=${prefix%?}
|
|
23
24
|
# words[0] is the program name itself: pass the words before the cursor, then the word at cursor
|
|
24
|
-
local output directive entry
|
|
25
|
+
local output directive entry files_prefix
|
|
26
|
+
# A word that continues is not followed by a space: `key=`, `key.`, `folder/`, `@modifier:`
|
|
27
|
+
local continues='([=./]|@[a-z0-9_]+:)$'
|
|
25
28
|
output=$(ascli config completion candidates -- "${words[@]:1:${#words[@]}-2}" "$cur" 2>/dev/null)
|
|
26
29
|
directive=${output##*$'\n'}
|
|
27
30
|
output=${output%"$directive"}
|
|
@@ -29,12 +32,23 @@ _ascli_complete() {
|
|
|
29
32
|
while IFS= read -r entry; do
|
|
30
33
|
# Remove the description
|
|
31
34
|
word=${entry%%$'\t'*}
|
|
32
|
-
[[ -n $word && $word == "$cur"* ]]
|
|
35
|
+
[[ -n $word && $word == "$cur"* ]] || continue
|
|
36
|
+
COMPREPLY+=("${word#"$prefix"}")
|
|
37
|
+
[[ $word =~ $continues ]] && compopt -o nospace 2>/dev/null
|
|
33
38
|
done <<<"$output"
|
|
34
39
|
case $directive in
|
|
35
|
-
:files)
|
|
40
|
+
:files | ":files "* | :folders | ":folders "*)
|
|
41
|
+
# Beginning of the word that is not part of the path, e.g. `--key=@file:`
|
|
42
|
+
files_prefix=${directive#:files}
|
|
43
|
+
files_prefix=${files_prefix#:folders}
|
|
44
|
+
files_prefix=${files_prefix# }
|
|
45
|
+
local kind=file
|
|
46
|
+
[[ $directive == :folders* ]] && kind=directory
|
|
36
47
|
compopt -o filenames 2>/dev/null
|
|
37
|
-
while IFS= read -r word; do
|
|
48
|
+
while IFS= read -r word; do
|
|
49
|
+
word=$files_prefix$word
|
|
50
|
+
COMPREPLY+=("${word#"$prefix"}")
|
|
51
|
+
done < <(compgen -A "$kind" -- "${cur#"$files_prefix"}")
|
|
38
52
|
;;
|
|
39
53
|
":hint "*)
|
|
40
54
|
# Two entries: bash displays them, but inserts nothing
|