aspera-cli 4.29.1 → 4.30.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 +4 -4
- data/CHANGELOG.md +119 -0
- data/CONTRIBUTING.md +8 -1
- data/README.md +2 -0
- data/TODO.md +4 -5
- data/bin/asession +2 -2
- data/docs/README.md +616 -86
- data/docs/test-mcp-with-ai.md +4 -0
- data/lib/aspera/agent/base.rb +62 -6
- data/lib/aspera/agent/factory.rb +127 -20
- data/lib/aspera/ascp/data_repository.rb +71 -0
- data/lib/aspera/ascp/installation.rb +16 -11
- data/lib/aspera/ascp/log_analyzer/lines.rb +4 -4
- data/lib/aspera/ascp/log_analyzer/log_file.rb +5 -3
- data/lib/aspera/ascp/log_analyzer/records.rb +11 -6
- data/lib/aspera/ascp/log_analyzer.rb +43 -18
- data/lib/aspera/ascp/log_locations.rb +2 -2
- data/lib/aspera/assert.rb +8 -0
- data/lib/aspera/bundle_registry.rb +528 -0
- data/lib/aspera/cli/argument.rb +110 -0
- data/lib/aspera/cli/bool_value.rb +41 -0
- data/lib/aspera/cli/bootstrapper.rb +31 -24
- data/lib/aspera/cli/command/mount.rb +53 -0
- data/lib/aspera/cli/command/registry.rb +434 -0
- data/lib/aspera/cli/command.rb +95 -0
- data/lib/aspera/cli/command_line.rb +91 -91
- data/lib/aspera/cli/complete.rb +22 -0
- data/lib/aspera/cli/completion_actions.rb +28 -26
- data/lib/aspera/cli/context.rb +29 -6
- data/lib/aspera/cli/error.rb +39 -0
- data/lib/aspera/cli/extended_value.rb +25 -4
- data/lib/aspera/cli/formatter.rb +8 -8
- data/lib/aspera/cli/hints.rb +17 -52
- data/lib/aspera/cli/http.rb +17 -12
- data/lib/aspera/cli/mailer.rb +7 -24
- data/lib/aspera/cli/mcp/tool.rb +10 -2
- data/lib/aspera/cli/option/declarator.rb +80 -0
- data/lib/aspera/cli/option/registry.rb +74 -0
- data/lib/aspera/cli/option/source.rb +38 -0
- data/lib/aspera/cli/option/type.rb +37 -0
- data/lib/aspera/cli/option/value.rb +376 -0
- data/lib/aspera/cli/option.rb +78 -0
- data/lib/aspera/cli/options.schema.yaml +28 -783
- data/lib/aspera/cli/parser.rb +73 -41
- data/lib/aspera/cli/plugins/base.rb +122 -42
- data/lib/aspera/cli/plugins/basic_auth.rb +13 -2
- data/lib/aspera/cli/plugins/config.rb +101 -167
- data/lib/aspera/cli/plugins/factory.rb +139 -43
- data/lib/aspera/cli/plugins/mcp.rb +61 -54
- data/lib/aspera/cli/plugins/oauth.rb +19 -6
- data/lib/aspera/cli/poll.rb +14 -20
- data/lib/aspera/cli/preset_actions.rb +11 -3
- data/lib/aspera/cli/preset_manager.rb +16 -6
- data/lib/aspera/cli/result.rb +2 -2
- data/lib/aspera/cli/runner.rb +71 -99
- data/lib/aspera/cli/secret_finder.rb +1 -1
- data/lib/aspera/cli/security.rb +102 -4
- data/lib/aspera/{preview/terminal.rb → cli/terminal_image.rb} +93 -94
- data/lib/aspera/cli/vault_manager.rb +3 -3
- data/lib/aspera/cli/version.rb +1 -1
- data/lib/aspera/cli/wizard.rb +9 -3
- data/lib/aspera/coverage.rb +1 -2
- data/lib/aspera/line_logger.rb +35 -6
- data/lib/aspera/log.rb +3 -2
- data/lib/aspera/oauth/client/base.rb +19 -1
- data/lib/aspera/oauth/client/factory.rb +1 -7
- data/lib/aspera/plugin.schema.yaml +178 -0
- data/lib/aspera/plugins/alee/api.rb +25 -0
- data/lib/aspera/{cli/plugins/alee.rb → plugins/alee/commands.rb} +10 -8
- data/lib/aspera/plugins/alee/plugin.yaml +3 -0
- data/lib/aspera/plugins/aoc/admin_resources.rb +148 -0
- data/lib/aspera/plugins/aoc/api.rb +783 -0
- data/lib/aspera/{cli/plugins/aoc.rb → plugins/aoc/commands.rb} +404 -330
- data/lib/aspera/plugins/aoc/graphql.rb +45 -0
- data/lib/aspera/plugins/aoc/plugin.yaml +31 -0
- data/lib/aspera/{schema → plugins/aoc/schemas}/IBM Aspera on Cloud API-0.2.6-enhanced.yaml +15042 -7076
- data/lib/aspera/plugins/aoc/schemas/options.yaml +47 -0
- data/lib/aspera/plugins/ats/api.rb +51 -0
- data/lib/aspera/{cli/plugins/ats.rb → plugins/ats/commands.rb} +33 -33
- data/lib/aspera/plugins/ats/plugin.yaml +6 -0
- data/lib/aspera/plugins/connect/agent.rb +199 -0
- data/lib/aspera/plugins/connect/plugin.yaml +11 -0
- data/lib/aspera/plugins/connect/schemas/agent_options.yaml +6 -0
- data/lib/aspera/{cli/plugins/console.rb → plugins/console/commands.rb} +41 -33
- data/lib/aspera/plugins/console/plugin.yaml +8 -0
- data/lib/aspera/plugins/cos/api.rb +114 -0
- data/lib/aspera/{cli/plugins/cos.rb → plugins/cos/commands.rb} +19 -16
- data/lib/aspera/plugins/cos/plugin.yaml +9 -0
- data/lib/aspera/plugins/cos/schemas/options.yaml +30 -0
- data/lib/aspera/plugins/desktop/agent.rb +165 -0
- data/lib/aspera/plugins/desktop/plugin.yaml +11 -0
- data/lib/aspera/plugins/desktop/schemas/agent_options.yaml +6 -0
- data/lib/aspera/plugins/direct/agent.rb +518 -0
- data/lib/aspera/plugins/direct/plugin.yaml +11 -0
- data/lib/aspera/plugins/direct/schemas/agent_options.yaml +86 -0
- data/lib/aspera/plugins/faspex4/gateway_options.rb +18 -0
- data/lib/aspera/plugins/faspex4/gw_servlet.rb +122 -0
- data/lib/aspera/plugins/faspex4/plugin.yaml +7 -0
- data/lib/aspera/plugins/faspex4/schemas/options.yaml +57 -0
- data/lib/aspera/plugins/faspex5/api.rb +269 -0
- data/lib/aspera/{cli/plugins/faspex5.rb → plugins/faspex5/commands.rb} +152 -114
- data/lib/aspera/plugins/faspex5/faspex4_post_proc_servlet.rb +241 -0
- data/lib/aspera/plugins/faspex5/plugin.yaml +14 -0
- data/lib/aspera/{schema → plugins/faspex5/schemas}/IBM Aspera Faspex API-5.0-enhanced.yaml +279 -76
- data/lib/aspera/plugins/faspex5/schemas/options.yaml +87 -0
- data/lib/aspera/{cli/plugins/faspio.rb → plugins/faspio/commands.rb} +11 -7
- data/lib/aspera/plugins/faspio/plugin.yaml +8 -0
- data/lib/aspera/{schema → plugins/faspio/schemas}/IBM Aspera faspio Gateway API-1.0.0-enhanced.yaml +4 -2
- data/lib/aspera/plugins/httpgw/agent.rb +126 -0
- data/lib/aspera/plugins/httpgw/api.rb +411 -0
- data/lib/aspera/{cli/plugins/httpgw.rb → plugins/httpgw/commands.rb} +9 -9
- data/lib/aspera/plugins/httpgw/plugin.yaml +12 -0
- data/lib/aspera/plugins/httpgw/schemas/agent_options.yaml +24 -0
- data/lib/aspera/plugins/node/agent.rb +184 -0
- data/lib/aspera/plugins/node/api.rb +699 -0
- data/lib/aspera/{cli/plugins/node.rb → plugins/node/commands.rb} +166 -141
- data/lib/aspera/plugins/node/emulator.rb +774 -0
- data/lib/aspera/plugins/node/plugin.yaml +20 -0
- data/lib/aspera/plugins/node/schemas/agent_options.yaml +20 -0
- data/lib/aspera/plugins/node/schemas/options.yaml +190 -0
- data/lib/aspera/{cli/plugins/orchestrator.rb → plugins/orchestrator/commands.rb} +139 -110
- data/lib/aspera/plugins/orchestrator/plugin.yaml +34 -0
- data/lib/aspera/{schema → plugins/orchestrator/schemas}/IBM Aspera Orchestrator API-v1-enhanced.yaml +486 -16
- data/lib/aspera/plugins/orchestrator/schemas/options.yaml +143 -0
- data/lib/aspera/plugins/orchestrator/workflow_checker.rb +692 -0
- data/lib/aspera/{cli/plugins/preview.rb → plugins/preview/commands.rb} +53 -51
- data/lib/aspera/plugins/preview/file_types.rb +121 -0
- data/lib/aspera/plugins/preview/generator.rb +350 -0
- data/lib/aspera/plugins/preview/plugin.yaml +12 -0
- data/lib/aspera/{preview/options.schema.yaml → plugins/preview/schemas/options.yaml} +1 -1
- data/lib/aspera/plugins/preview/utils.rb +213 -0
- data/lib/aspera/plugins/server/ascmd.rb +374 -0
- data/lib/aspera/{cli/plugins/server.rb → plugins/server/commands.rb} +48 -32
- data/lib/aspera/plugins/server/plugin.yaml +9 -0
- data/lib/aspera/plugins/server/schemas/options.yaml +30 -0
- data/lib/aspera/{cli/plugins/shares.rb → plugins/shares/commands.rb} +29 -21
- data/lib/aspera/plugins/shares/plugin.yaml +10 -0
- data/lib/aspera/plugins/shares/shares_web.rb +97 -0
- data/lib/aspera/plugins/transferd/agent.rb +258 -0
- data/lib/aspera/plugins/transferd/api.rb +180 -0
- data/lib/aspera/plugins/transferd/client.rb +67 -0
- data/lib/aspera/{cli/plugins/transferd.rb → plugins/transferd/commands.rb} +43 -42
- data/lib/aspera/plugins/transferd/config_commands.rb +38 -0
- data/lib/aspera/plugins/transferd/plugin.yaml +27 -0
- data/lib/aspera/plugins/transferd/product.rb +146 -0
- data/lib/aspera/plugins/transferd/schemas/agent_options.yaml +31 -0
- data/lib/aspera/plugins/transferd/schemas/options.yaml +80 -0
- data/lib/aspera/plugins/transferd/service.rb +617 -0
- data/lib/aspera/plugins/xfer/ascp_actions.rb +131 -0
- data/lib/aspera/plugins/xfer/ascp_logs_actions.rb +198 -0
- data/lib/aspera/plugins/xfer/async_transfer_store.rb +131 -0
- data/lib/aspera/plugins/xfer/config_commands.rb +119 -0
- data/lib/aspera/plugins/xfer/helper.rb +19 -0
- data/lib/aspera/plugins/xfer/plugin.yaml +42 -0
- data/lib/aspera/plugins/xfer/schemas/agent_extension.schema.yaml +26 -0
- data/lib/aspera/plugins/xfer/schemas/options.yaml +125 -0
- data/lib/aspera/plugins/xfer/sync_actions.rb +253 -0
- data/lib/aspera/plugins/xfer/transfer_actions.rb +176 -0
- data/lib/aspera/plugins/xfer/transfer_agent.rb +505 -0
- data/lib/aspera/products/cli_v3.rb +34 -0
- data/lib/aspera/products/connect.rb +1 -1
- data/lib/aspera/products/drive.rb +29 -0
- data/lib/aspera/products/hsts.rb +34 -0
- data/lib/aspera/products/transferd.rb +25 -3
- data/lib/aspera/products.rb +54 -0
- data/lib/aspera/prompt.rb +184 -0
- data/lib/aspera/proxy_auto_config.rb +3 -3
- data/lib/aspera/rest/aspera_errors.rb +4 -38
- data/lib/aspera/rest/error_analyzer.rb +6 -2
- data/lib/aspera/rest/list.rb +4 -5
- data/lib/aspera/schema/reader.rb +15 -0
- data/lib/aspera/schema/registry.rb +239 -45
- data/lib/aspera/schema/validator.rb +63 -17
- data/lib/aspera/sealed_hash.rb +4 -0
- data/lib/aspera/secret/hider.rb +159 -24
- data/lib/aspera/secret/reference.rb +8 -0
- data/lib/aspera/secret/resolver.rb +8 -4
- data/lib/aspera/secret/store/base.rb +10 -9
- data/lib/aspera/secret/store/encrypted_hash.rb +6 -6
- data/lib/aspera/secret/store/hashicorp_vault.rb +3 -3
- data/lib/aspera/secret/store/keeper.rb +2 -2
- data/lib/aspera/secret/store/macos_security.rb +2 -3
- data/lib/aspera/secret/store/one_password_api.rb +2 -2
- data/lib/aspera/secret/store/one_password_cli.rb +3 -3
- data/lib/aspera/secret/store/secret_service.rb +2 -2
- data/lib/aspera/ssl.rb +3 -3
- data/lib/aspera/standard_input.rb +20 -0
- data/lib/aspera/{schema → sync}/async_tables.yaml +1 -1
- data/lib/aspera/sync/database.rb +7 -0
- data/lib/aspera/sync/log_parser.rb +138 -0
- data/lib/aspera/sync/operations.rb +59 -34
- data/lib/aspera/transfer/command_line_builder.rb +248 -0
- data/lib/aspera/transfer/command_line_converter.rb +37 -0
- data/lib/aspera/transfer/faux_file.rb +2 -2
- data/lib/aspera/transfer/parameters.rb +9 -10
- data/lib/aspera/transfer/spec.rb +28 -1
- data/lib/aspera/transfer/spec.schema.yaml +30 -5
- data/lib/aspera/units/decimal.rb +1 -1
- data/lib/aspera/units/timestamp.rb +84 -0
- data/lib/aspera/uri_reader.rb +2 -2
- data/lib/aspera/web_auth/paste.rb +2 -2
- data/lib/aspera/web_server_simple.rb +10 -4
- data.tar.gz.sig +0 -0
- metadata +137 -80
- metadata.gz.sig +0 -0
- data/lib/aspera/agent/connect.rb +0 -188
- data/lib/aspera/agent/desktop.rb +0 -154
- data/lib/aspera/agent/direct.rb +0 -496
- data/lib/aspera/agent/httpgw.rb +0 -100
- data/lib/aspera/agent/node.rb +0 -166
- data/lib/aspera/agent/transferd.rb +0 -341
- data/lib/aspera/api/alee.rb +0 -19
- data/lib/aspera/api/aoc.rb +0 -776
- data/lib/aspera/api/ats.rb +0 -49
- data/lib/aspera/api/cos_node.rb +0 -107
- data/lib/aspera/api/faspex.rb +0 -258
- data/lib/aspera/api/httpgw.rb +0 -409
- data/lib/aspera/api/node.rb +0 -684
- data/lib/aspera/ascmd.rb +0 -248
- data/lib/aspera/cli/ascp_actions.rb +0 -113
- data/lib/aspera/cli/ascp_logs_actions.rb +0 -188
- data/lib/aspera/cli/async_transfer_store.rb +0 -129
- data/lib/aspera/cli/command_registry.rb +0 -371
- data/lib/aspera/cli/command_spec.rb +0 -273
- data/lib/aspera/cli/option_declarator.rb +0 -74
- data/lib/aspera/cli/option_registry.rb +0 -72
- data/lib/aspera/cli/option_types.rb +0 -120
- data/lib/aspera/cli/option_value.rb +0 -345
- data/lib/aspera/cli/prompt.rb +0 -186
- data/lib/aspera/cli/sync_actions.rb +0 -181
- data/lib/aspera/cli/transfer_actions.rb +0 -98
- data/lib/aspera/cli/transfer_agent.rb +0 -348
- data/lib/aspera/command_line_builder.rb +0 -244
- data/lib/aspera/command_line_converter.rb +0 -35
- data/lib/aspera/data_repository.rb +0 -69
- data/lib/aspera/faspex_gw.rb +0 -172
- data/lib/aspera/faspex_postproc.rb +0 -237
- data/lib/aspera/graphql.rb +0 -41
- data/lib/aspera/node_emulator.rb +0 -758
- data/lib/aspera/oauth/client/shares_web.rb +0 -94
- data/lib/aspera/orchestrator_workflow_checker.rb +0 -688
- data/lib/aspera/preview/file_types.rb +0 -119
- data/lib/aspera/preview/generator.rb +0 -345
- data/lib/aspera/preview/utils.rb +0 -211
- data/lib/aspera/products/other.rb +0 -92
- data/lib/aspera/products/transferd_service.rb +0 -610
- /data/lib/aspera/{data → ascp/data}/1 +0 -0
- /data/lib/aspera/{data → ascp/data}/2 +0 -0
- /data/lib/aspera/{data → ascp/data}/3 +0 -0
- /data/lib/aspera/{data → ascp/data}/4 +0 -0
- /data/lib/aspera/{data → ascp/data}/5 +0 -0
- /data/lib/aspera/{data → ascp/data}/6 +0 -0
- /data/lib/aspera/{api → plugins/aoc}/queries/bss_subscription_account.graphql +0 -0
- /data/lib/aspera/{api → plugins/aoc}/queries/bss_subscription_usage.graphql +0 -0
- /data/lib/aspera/{schema → plugins/aoc/schemas}/IBM Aspera on Cloud Automation API-1.0.5-enhanced.yaml +0 -0
- /data/lib/aspera/{schema → plugins/console/schemas}/IBM Aspera Console-enhanced.yaml +0 -0
- /data/lib/aspera/{schema → plugins/node/schemas}/IBM Aspera Node API-4.4.6.yaml +0 -0
- /data/lib/aspera/{preview → plugins/preview}/image_error.png +0 -0
- /data/lib/aspera/{preview → plugins/preview}/video_error.png +0 -0
- /data/lib/aspera/{schema → plugins/shares/schemas}/IBM_Aspera_Shares.yaml +0 -0
- /data/lib/{transferd_pb.rb → aspera/plugins/transferd/grpc/transferd_pb.rb} +0 -0
- /data/lib/{transferd_services_pb.rb → aspera/plugins/transferd/grpc/transferd_services_pb.rb} +0 -0
- /data/lib/aspera/{schema → plugins/transferd/schemas}/transferd-config.schema.json +0 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../environment'
|
|
7
|
+
require_relative '../log'
|
|
8
|
+
require_relative '../ascp/log_analyzer'
|
|
9
|
+
|
|
10
|
+
module Aspera
|
|
11
|
+
module Sync
|
|
12
|
+
# Extract the notable events from `async` (Aspera Sync) log files: file conflicts and errors,
|
|
13
|
+
# unsupported file-system events, session lifecycle (start, stop, idle), and `ERR`-level lines.
|
|
14
|
+
# The bulk of the log (synchronized files, transfers, periodic statistics) is skipped.
|
|
15
|
+
# A line looks like: `2026-11-24 20:51:01.275 [d4fc-18637435] LOG [Sync_reporter] SYNC FILE STOP ... status=CONFLICT`
|
|
16
|
+
module LogParser
|
|
17
|
+
# One log line: timestamp, process id, level, optional bracketed component, message
|
|
18
|
+
LINE = /\A(?<time>\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\.\d+) \[[^\]]+\] (?<level>[A-Z]+) (?:\[(?<component>[^\]]+)\] )?(?<message>.*)\z/
|
|
19
|
+
# `status` of `SYNC FILE STOP` that means the file is synchronized, so not notable (also `SYNCHRONIZED(exs)`: already present)
|
|
20
|
+
FILE_STATUS_OK = 'SYNCHRONIZED'
|
|
21
|
+
# `SYNC SESSION <event>` kept (lifecycle); the others (STATS, PROG, READY, NEW, SCAN, PARAMETERS) are skipped
|
|
22
|
+
SESSION_EVENTS = %w[START STOP IDLE].freeze
|
|
23
|
+
SESSION_EVENT = /\ASYNC SESSION (#{SESSION_EVENTS.join('|')})\b/
|
|
24
|
+
# Log levels that are always notable
|
|
25
|
+
NOTABLE_LEVELS = %w[ERR ERROR FATAL].freeze
|
|
26
|
+
# Text of the file-system watcher error (async `Monitor_fsevents.cpp`)
|
|
27
|
+
UNSUPPORTED_EVENT = 'Unsupported file system event'
|
|
28
|
+
# Longest `detail` kept for display: the raw message of an `ERR` line can be very long
|
|
29
|
+
DETAIL_MAX = 200
|
|
30
|
+
# Names of the `async` log files in a folder: current file and its rotations
|
|
31
|
+
ASYNC_FILE = /\Aasync(?:\.\d+)?\.log(?:\.gz)?\z/
|
|
32
|
+
# Linux and Unix: `async` logs to syslog (one of these files, depending on the syslog configuration)
|
|
33
|
+
SYSLOG_FILES = %w[/var/log/aspera.log /var/log/messages /var/log/syslog].freeze
|
|
34
|
+
# Default fields shown for the events
|
|
35
|
+
FIELDS = %w[time level session kind path status detail].freeze
|
|
36
|
+
# Compiled regular expression for each `key=...` read from a message (built once per key)
|
|
37
|
+
FIELD_RE = Hash.new { |cache, key| cache[key] = /\b#{Regexp.escape(key)}=(?:"([^"]*)"|(\S+))/ }
|
|
38
|
+
|
|
39
|
+
class << self
|
|
40
|
+
# @param paths [Array<String, StandardInput>] log files, folders (scanned for `async*.log`), or standard input
|
|
41
|
+
# @param readable [#call, nil] For a folder: tells if a file found in it can be read (e.g. it is in the allowed paths of the caller,
|
|
42
|
+
# also through a symbolic link), else it is skipped. `nil`: all are read.
|
|
43
|
+
# @return [Array<Hash>] notable events, oldest first (across files, by timestamp)
|
|
44
|
+
def notable_events(paths, readable: nil)
|
|
45
|
+
paths.flat_map { |path| path_files(path, readable) }
|
|
46
|
+
.flat_map { |file| file_events(file) }
|
|
47
|
+
.sort_by { |event| event['time'] }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# @return [Array<String>] the `async` log files at the default location of the local host (existing only)
|
|
51
|
+
def default_log_paths
|
|
52
|
+
case Environment.instance.os
|
|
53
|
+
when Environment::OS_MACOS
|
|
54
|
+
[File.join(Dir.home, 'Library', 'Logs', 'Aspera', 'async.log')].select { |file| File.file?(file) }
|
|
55
|
+
when Environment::OS_WINDOWS
|
|
56
|
+
# `async` logs to its working folder on Windows: no fixed default location
|
|
57
|
+
[]
|
|
58
|
+
else
|
|
59
|
+
SYSLOG_FILES.select { |file| File.file?(file) }
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# @return [String] human description of the default location, for an error message
|
|
64
|
+
def default_location_hint
|
|
65
|
+
case Environment.instance.os
|
|
66
|
+
when Environment::OS_MACOS then File.join(Dir.home, 'Library', 'Logs', 'Aspera', 'async.log')
|
|
67
|
+
when Environment::OS_WINDOWS then 'the working folder of async'
|
|
68
|
+
else SYSLOG_FILES.join(', ')
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
private
|
|
73
|
+
|
|
74
|
+
# @param path [String, StandardInput] a log file, the standard input, or a folder (then only the `async*.log` files in it are kept)
|
|
75
|
+
# @param readable [#call, nil] see `notable_events`
|
|
76
|
+
# @return [Array<String, StandardInput>] the files to read
|
|
77
|
+
def path_files(path, readable)
|
|
78
|
+
return [path] unless Ascp::LogAnalyzer.folder?(path)
|
|
79
|
+
Dir.children(path).sort.select { |name| name.match?(ASYNC_FILE) }.map { |name| File.join(path, name) }
|
|
80
|
+
.select { |file| readable.nil? || readable.call(file) }
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# @param file [String, StandardInput] a log file (plain or gzip), or the standard input
|
|
84
|
+
# @return [Array<Hash>] the notable events of the file
|
|
85
|
+
def file_events(file)
|
|
86
|
+
events = []
|
|
87
|
+
Ascp::LogAnalyzer.read_lines(file, Encoding::UTF_8) do |line|
|
|
88
|
+
event = classify(line.scrub.chomp)
|
|
89
|
+
events.push(event) unless event.nil?
|
|
90
|
+
end
|
|
91
|
+
events
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# @param line [String] one log line
|
|
95
|
+
# @return [Hash, nil] the event, or nil if the line is not notable
|
|
96
|
+
def classify(line)
|
|
97
|
+
match = LINE.match(line)
|
|
98
|
+
return if match.nil?
|
|
99
|
+
level = match[:level]
|
|
100
|
+
message = match[:message]
|
|
101
|
+
if message.start_with?('SYNC FILE STOP ')
|
|
102
|
+
status = field(message, 'status')
|
|
103
|
+
return if status.nil? || status.start_with?(FILE_STATUS_OK)
|
|
104
|
+
build(match, kind: "file #{status.downcase}", path: field(message, 'path'), status: status)
|
|
105
|
+
elsif (session = SESSION_EVENT.match(message))
|
|
106
|
+
build(match, kind: "session #{session[1].downcase}", path: field(message, 'local'), status: field(message, 'status') || field(message, 'op'))
|
|
107
|
+
elsif message.include?(UNSUPPORTED_EVENT)
|
|
108
|
+
build(match, kind: 'unsupported-event', detail: message)
|
|
109
|
+
elsif NOTABLE_LEVELS.include?(level)
|
|
110
|
+
build(match, kind: 'error', detail: message)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# @return [Hash] an event record
|
|
115
|
+
def build(match, kind:, path: nil, status: nil, detail: nil)
|
|
116
|
+
{
|
|
117
|
+
'time' => match[:time],
|
|
118
|
+
'level' => match[:level],
|
|
119
|
+
'session' => field(match[:message], 'name'),
|
|
120
|
+
'kind' => kind,
|
|
121
|
+
'path' => path,
|
|
122
|
+
'status' => status,
|
|
123
|
+
'detail' => detail.nil? || detail.length <= DETAIL_MAX ? detail : "#{detail[0, DETAIL_MAX]}…"
|
|
124
|
+
}
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Value of `key=...` in a message: a quoted string (`path="..."`), else a space-delimited token
|
|
128
|
+
# @param message [String] the message part of the line
|
|
129
|
+
# @param key [String] the key to read
|
|
130
|
+
# @return [String, nil] the value, or nil if the key is absent
|
|
131
|
+
def field(message, key)
|
|
132
|
+
match = FIELD_RE[key].match(message)
|
|
133
|
+
match && (match[1] || match[2])
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
# SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
|
|
6
6
|
require_relative '../ascp/installation'
|
|
7
|
-
require_relative '../agent/
|
|
7
|
+
require_relative '../agent/factory'
|
|
8
8
|
require_relative '../transfer/spec'
|
|
9
9
|
require_relative '../units/decimal'
|
|
10
10
|
require_relative '../exec_spec'
|
|
11
|
-
require_relative '../command_line_converter'
|
|
12
|
-
require_relative '../command_line_builder'
|
|
11
|
+
require_relative '../transfer/command_line_converter'
|
|
12
|
+
require_relative '../transfer/command_line_builder'
|
|
13
13
|
require_relative '../log'
|
|
14
14
|
require_relative '../assert'
|
|
15
15
|
require_relative '../units/duration'
|
|
@@ -85,23 +85,25 @@ module Aspera
|
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
# Start the sync process
|
|
88
|
-
# @param sync_info
|
|
89
|
-
# @param opt_ts
|
|
88
|
+
# @param sync_info [Hash] Sync parameters, old or new format
|
|
89
|
+
# @param opt_ts [Hash] Optional transfer spec
|
|
90
|
+
# @param agent_options [Hash] Options of the `direct` agent that runs `async` (`conf` format): parameters of option
|
|
91
|
+
# `transfer` (e.g. `quiet`, `spawn_timeout_sec`) and base options (e.g. `progress`). Empty for the defaults.
|
|
90
92
|
# @yieldparam direction [Symbol] Sync direction (one of DIRECTIONS: :push, :pull, :bidi)
|
|
91
93
|
# @yieldparam local_dir [String] Local directory path
|
|
92
94
|
# @yieldparam remote_dir [String] Remote directory path
|
|
93
95
|
# @yieldreturn [Hash] Transfer spec to use for authentication
|
|
94
|
-
def start(sync_info, opt_ts = nil)
|
|
96
|
+
def start(sync_info, opt_ts = nil, agent_options: {})
|
|
95
97
|
Log.dump(:sync_params_initial, sync_info)
|
|
96
98
|
Aspera.assert_type(sync_info, Hash)
|
|
97
|
-
Aspera.assert(PARAM_KEYS.any? { |k| sync_info.key?(k) }, 'At least one of `local` or `sessions` must be present in async parameters', type:
|
|
99
|
+
Aspera.assert(PARAM_KEYS.any? { |k| sync_info.key?(k) }, 'At least one of `local` or `sessions` must be present in async parameters', type: ParameterError)
|
|
98
100
|
exec_spec = ExecSpec.new(exec: :async)
|
|
99
101
|
if sync_info.key?('local')
|
|
100
102
|
# `conf` format
|
|
101
|
-
Aspera.assert_type(sync_info['local'], Hash) { 'local' }
|
|
103
|
+
Aspera.assert_type(sync_info['local'], Hash, type: ParameterError) { 'local' }
|
|
102
104
|
remote = sync_info['remote']
|
|
103
|
-
Aspera.assert_type(remote, Hash) { 'remote' }
|
|
104
|
-
Aspera.assert_type(remote['path'], String) { 'remote path' }
|
|
105
|
+
Aspera.assert_type(remote, Hash, type: ParameterError) { 'remote' }
|
|
106
|
+
Aspera.assert_type(remote['path'], String, type: ParameterError) { 'remote path' }
|
|
105
107
|
normalize_target_rate(sync_info['transport'])
|
|
106
108
|
# get transfer spec if possible, and feed back to new structure
|
|
107
109
|
if block_given?
|
|
@@ -118,22 +120,32 @@ module Aspera
|
|
|
118
120
|
remote['private_key_paths'] ||= []
|
|
119
121
|
remote['private_key_paths'].concat(add_certificates)
|
|
120
122
|
end
|
|
123
|
+
# Secrets go in environment variables, not in `--conf64`: the command line is visible to other users (`ps`), and logged
|
|
124
|
+
CONF_REMOTE_SECRETS_ENV.each do |key, env_var|
|
|
125
|
+
value = remote.delete(key)
|
|
126
|
+
exec_spec.env[env_var] = value unless value.nil?
|
|
127
|
+
end
|
|
121
128
|
# '--exclusive-mgmt-port=12345', '--arg-err-path=-',
|
|
122
|
-
|
|
129
|
+
conf64 = Base64.strict_encode64(JSON.generate(sync_info))
|
|
130
|
+
# A secret that `async` reads only from the configuration (e.g. the proxy password) is in the encoded value: hide it in logs.
|
|
131
|
+
# The configuration is logged decoded below, with its secrets hidden.
|
|
132
|
+
Secret::Hider.instance.add_secret_values(conf64)
|
|
133
|
+
exec_spec.args = ["--conf64=#{conf64}"]
|
|
123
134
|
Log.dump(:sync_conf, sync_info)
|
|
124
|
-
agent = Agent::
|
|
135
|
+
agent = Agent::Factory.instance.create(:direct, agent_options)
|
|
136
|
+
Aspera.assert(agent.respond_to?(:start_and_monitor_process)) { "agent direct (#{agent.class}) cannot run async: it does not provide start_and_monitor_process" }
|
|
125
137
|
agent.start_and_monitor_process(session: {}, exec_spec: exec_spec)
|
|
126
138
|
else
|
|
127
139
|
# `args` format
|
|
128
140
|
raise StandardError, "Only 'sessions', and optionally 'instance' keys are allowed" unless
|
|
129
141
|
sync_info.keys.push('instance').uniq.sort.eql?(CMDLINE_PARAMS_KEYS)
|
|
130
|
-
Aspera.assert_type(sync_info['sessions'], Array)
|
|
131
|
-
Aspera.assert_type(sync_info['sessions'].first, Hash)
|
|
142
|
+
Aspera.assert_type(sync_info['sessions'], Array, type: ParameterError) { 'sessions' }
|
|
143
|
+
Aspera.assert_type(sync_info['sessions'].first, Hash, type: ParameterError) { 'session' }
|
|
132
144
|
sync_info['sessions'].each { |session| normalize_target_rate(session) }
|
|
133
145
|
if block_given?
|
|
134
146
|
sync_info['sessions'].each do |session|
|
|
135
|
-
Aspera.assert_type(session['local_dir'], String) { 'local_dir' }
|
|
136
|
-
Aspera.assert_type(session['remote_dir'], String) { 'remote_dir' }
|
|
147
|
+
Aspera.assert_type(session['local_dir'], String, type: ParameterError) { 'local_dir' }
|
|
148
|
+
Aspera.assert_type(session['remote_dir'], String, type: ParameterError) { 'remote_dir' }
|
|
137
149
|
transfer_spec = yield(direction_sym(session), session['local_dir'], session['remote_dir'])
|
|
138
150
|
Log.dump(:auth_ts, transfer_spec)
|
|
139
151
|
transfer_spec.deep_merge!(opt_ts) unless opt_ts.nil?
|
|
@@ -144,15 +156,15 @@ module Aspera
|
|
|
144
156
|
end
|
|
145
157
|
end
|
|
146
158
|
if sync_info.key?('instance')
|
|
147
|
-
Aspera.assert_type(sync_info['instance'], Hash)
|
|
148
|
-
instance_builder = CommandLineBuilder.new(sync_info['instance'], ARGS_INSTANCE_SCHEMA, CommandLineConverter)
|
|
159
|
+
Aspera.assert_type(sync_info['instance'], Hash, type: ParameterError) { 'instance' }
|
|
160
|
+
instance_builder = Transfer::CommandLineBuilder.new(sync_info['instance'], ARGS_INSTANCE_SCHEMA, Transfer::CommandLineConverter)
|
|
149
161
|
instance_builder.process_params
|
|
150
162
|
instance_builder.add_to_exec_spec(exec_spec)
|
|
151
163
|
end
|
|
152
164
|
sync_info['sessions'].each do |session_params|
|
|
153
|
-
Aspera.assert_type(session_params, Hash)
|
|
154
|
-
Aspera.assert(session_params.key?('name'), 'session must contain at least: name')
|
|
155
|
-
session_builder = CommandLineBuilder.new(session_params, ARGS_SESSION_SCHEMA, CommandLineConverter)
|
|
165
|
+
Aspera.assert_type(session_params, Hash, type: ParameterError) { 'session' }
|
|
166
|
+
Aspera.assert(session_params.key?('name'), 'session must contain at least: name', type: ParameterError)
|
|
167
|
+
session_builder = Transfer::CommandLineBuilder.new(session_params, ARGS_SESSION_SCHEMA, Transfer::CommandLineConverter)
|
|
156
168
|
session_builder.process_params
|
|
157
169
|
session_builder.add_to_exec_spec(exec_spec)
|
|
158
170
|
end
|
|
@@ -183,7 +195,7 @@ module Aspera
|
|
|
183
195
|
# @param sync_info [Hash] sync parameters in conf or args format
|
|
184
196
|
# @return [Hash] parsed output of asyncadmin
|
|
185
197
|
def admin_status(sync_info)
|
|
186
|
-
Aspera.assert(PARAM_KEYS.any? { |k| sync_info.key?(k) }, 'At least one of `local` or `sessions` must be present in async parameters', type:
|
|
198
|
+
Aspera.assert(PARAM_KEYS.any? { |k| sync_info.key?(k) }, 'At least one of `local` or `sessions` must be present in async parameters', type: ParameterError)
|
|
187
199
|
arguments = [ASYNC_ADMIN_EXECUTABLE, '--quiet']
|
|
188
200
|
if sync_info.key?('local')
|
|
189
201
|
# `conf` format
|
|
@@ -193,7 +205,7 @@ module Aspera
|
|
|
193
205
|
elsif sync_info.dig('local', 'path')
|
|
194
206
|
arguments.push("--local-dir=#{sync_info.dig('local', 'path')}")
|
|
195
207
|
else
|
|
196
|
-
raise
|
|
208
|
+
raise ParameterError, 'Missing either local_db_dir or local.path'
|
|
197
209
|
end
|
|
198
210
|
else
|
|
199
211
|
# `args` format
|
|
@@ -204,7 +216,7 @@ module Aspera
|
|
|
204
216
|
elsif session.key?('local_dir')
|
|
205
217
|
arguments.push("--local-dir=#{session['local_dir']}")
|
|
206
218
|
else
|
|
207
|
-
raise
|
|
219
|
+
raise ParameterError, 'Missing either local_db_dir or local_dir'
|
|
208
220
|
end
|
|
209
221
|
end
|
|
210
222
|
stdout = Environment.secure_execute(*arguments, mode: :capture).first
|
|
@@ -215,7 +227,7 @@ module Aspera
|
|
|
215
227
|
# @param sync_info [Hash] sync parameters in conf or args format
|
|
216
228
|
# @return [String, nil] Path to "local DB dir", i.e. folder that contains folders that contain `snap.db`
|
|
217
229
|
def local_db_folder(sync_info)
|
|
218
|
-
Aspera.assert(PARAM_KEYS.any? { |k| sync_info.key?(k) }, 'At least one of `local` or `sessions` must be present in async parameters', type:
|
|
230
|
+
Aspera.assert(PARAM_KEYS.any? { |k| sync_info.key?(k) }, 'At least one of `local` or `sessions` must be present in async parameters', type: ParameterError)
|
|
219
231
|
if sync_info.key?('local')
|
|
220
232
|
# `conf` format
|
|
221
233
|
if sync_info.key?('local_db_dir')
|
|
@@ -223,7 +235,7 @@ module Aspera
|
|
|
223
235
|
elsif (local_path = sync_info.dig('local', 'path'))
|
|
224
236
|
return local_path
|
|
225
237
|
else
|
|
226
|
-
raise
|
|
238
|
+
raise ParameterError, 'Missing either local_db_dir or local.path'
|
|
227
239
|
end
|
|
228
240
|
else
|
|
229
241
|
# `args` format
|
|
@@ -233,13 +245,13 @@ module Aspera
|
|
|
233
245
|
elsif session.key?('local_dir')
|
|
234
246
|
return session['local_dir']
|
|
235
247
|
else
|
|
236
|
-
raise
|
|
248
|
+
raise ParameterError, 'Missing either local_db_dir or local_dir'
|
|
237
249
|
end
|
|
238
250
|
end
|
|
239
251
|
end
|
|
240
252
|
|
|
241
253
|
def session_name(sync_info)
|
|
242
|
-
Aspera.assert(PARAM_KEYS.any? { |k| sync_info.key?(k) }, 'At least one of `local` or `sessions` must be present in async parameters', type:
|
|
254
|
+
Aspera.assert(PARAM_KEYS.any? { |k| sync_info.key?(k) }, 'At least one of `local` or `sessions` must be present in async parameters', type: ParameterError)
|
|
243
255
|
if sync_info.key?('local')
|
|
244
256
|
# `conf` format
|
|
245
257
|
return sync_info['name']
|
|
@@ -249,9 +261,16 @@ module Aspera
|
|
|
249
261
|
end
|
|
250
262
|
end
|
|
251
263
|
|
|
264
|
+
# @param sync_info [Hash] sync parameters in conf or args format, with the name of the session
|
|
265
|
+
# @return [String] Path of the database file of the session, that may not exist
|
|
266
|
+
def session_db_path(sync_info) = File.join(local_db_folder(sync_info), PRIVATE_FOLDER, session_name(sync_info), ASYNC_DB)
|
|
267
|
+
|
|
268
|
+
# @param sync_info [Hash] sync parameters in conf or args format, with the name of the session
|
|
269
|
+
# @return [String] Path of the database file of the session
|
|
270
|
+
# @raise [ParameterError] If the file does not exist
|
|
252
271
|
def session_db_file(sync_info)
|
|
253
|
-
db_file =
|
|
254
|
-
Aspera.assert(File.exist?(db_file)) { "Database file #{db_file} does not exist" }
|
|
272
|
+
db_file = session_db_path(sync_info)
|
|
273
|
+
Aspera.assert(File.exist?(db_file), type: ParameterError) { "Database file #{db_file} does not exist" }
|
|
255
274
|
db_file
|
|
256
275
|
end
|
|
257
276
|
|
|
@@ -282,7 +301,7 @@ module Aspera
|
|
|
282
301
|
if property.key?('x-ts-name')
|
|
283
302
|
tspec_param = property['x-ts-name']
|
|
284
303
|
if transfer_spec.key?(tspec_param) && !sync_info.key?(name)
|
|
285
|
-
sync_info[name] = property['x-ts-convert'] ? CommandLineConverter.send(property['x-ts-convert'], transfer_spec[tspec_param]) : transfer_spec[tspec_param]
|
|
304
|
+
sync_info[name] = property['x-ts-convert'] ? Transfer::CommandLineConverter.send(property['x-ts-convert'], transfer_spec[tspec_param]) : transfer_spec[tspec_param]
|
|
286
305
|
end
|
|
287
306
|
end
|
|
288
307
|
if property['type'].eql?('object') && property.key?('properties')
|
|
@@ -358,18 +377,24 @@ module Aspera
|
|
|
358
377
|
end
|
|
359
378
|
end
|
|
360
379
|
# Private stuff:
|
|
380
|
+
# Schemas of the arguments of `async`, of the configuration of sync, and of the tables of the `async` database (see `Database`)
|
|
381
|
+
Schema::Registry.register(Schema::Registry::SYNC_ARGS, File.join(__dir__, 'args.schema.yaml'))
|
|
382
|
+
Schema::Registry.register(Schema::Registry::SYNC_CONF, File.join(__dir__, 'conf.schema.yaml'))
|
|
383
|
+
Schema::Registry.register(Schema::Registry::ASYNC_TABLES, File.join(__dir__, 'async_tables.yaml'))
|
|
361
384
|
# Read JSON schema and mapping to command line options
|
|
362
|
-
ARGS_INSTANCE_SCHEMA = CommandLineBuilder.read_schema(Schema::Registry::SYNC_ARGS)
|
|
385
|
+
ARGS_INSTANCE_SCHEMA = Transfer::CommandLineBuilder.read_schema(Schema::Registry::SYNC_ARGS)
|
|
363
386
|
ARGS_SESSION_SCHEMA = ARGS_INSTANCE_SCHEMA.dig(*%w[properties sessions items])
|
|
364
387
|
ARGS_INSTANCE_SCHEMA.dig('properties').current.delete('sessions')
|
|
365
|
-
CONF_SCHEMA = CommandLineBuilder.read_schema(Schema::Registry::SYNC_CONF)
|
|
388
|
+
CONF_SCHEMA = Transfer::CommandLineBuilder.read_schema(Schema::Registry::SYNC_CONF)
|
|
366
389
|
CMDLINE_PARAMS_KEYS = %w[instance sessions].freeze
|
|
367
390
|
ASYNC_ADMIN_EXECUTABLE = 'asyncadmin'
|
|
368
391
|
PRIVATE_FOLDER = "#{Environment.instance.os.eql?(Environment::OS_WINDOWS) ? '~' : '.'}private-asp".freeze
|
|
369
392
|
ASYNC_DB = 'snap.db'
|
|
370
393
|
PARAM_KEYS = %w[local sessions].freeze
|
|
394
|
+
# `conf` format: keys of `remote` that `async` also reads from an environment variable, when absent from the configuration
|
|
395
|
+
CONF_REMOTE_SECRETS_ENV = [%w[pass ASPERA_SCP_PASS], %w[token ASPERA_SCP_TOKEN]].freeze
|
|
371
396
|
|
|
372
|
-
private_constant :ARGS_INSTANCE_SCHEMA, :ARGS_SESSION_SCHEMA, :CMDLINE_PARAMS_KEYS, :ASYNC_ADMIN_EXECUTABLE, :PRIVATE_FOLDER, :ASYNC_DB, :PARAM_KEYS
|
|
397
|
+
private_constant :ARGS_INSTANCE_SCHEMA, :ARGS_SESSION_SCHEMA, :CMDLINE_PARAMS_KEYS, :ASYNC_ADMIN_EXECUTABLE, :PRIVATE_FOLDER, :ASYNC_DB, :PARAM_KEYS, :CONF_REMOTE_SECRETS_ENV
|
|
373
398
|
end
|
|
374
399
|
end
|
|
375
400
|
end
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../log'
|
|
7
|
+
require_relative '../assert'
|
|
8
|
+
require_relative '../schema/registry'
|
|
9
|
+
require_relative '../exec_spec'
|
|
10
|
+
require 'yaml'
|
|
11
|
+
module Aspera
|
|
12
|
+
module Transfer
|
|
13
|
+
# Helper class to build command line from a parameter list (key-value hash)
|
|
14
|
+
# Constructor takes hash: `{ 'param1':'value1', ...}`
|
|
15
|
+
# `process_param` is called repeatedly with all known parameters
|
|
16
|
+
# `add_to_exec_spec` is called to get resulting param list and env var (also checks that all params were used)
|
|
17
|
+
class CommandLineBuilder
|
|
18
|
+
# Supported keys in JSON schema
|
|
19
|
+
PROPERTY_KEYS = [
|
|
20
|
+
'description', # [String] Description
|
|
21
|
+
'type', # [String,Array] Accepted type(s) for non-enum
|
|
22
|
+
'default', # [String] Default value if not specified
|
|
23
|
+
'enum', # [Array] Set with list of values for enum types accepted in transfer spec
|
|
24
|
+
'items', # [Array]
|
|
25
|
+
'properties', # [Array]
|
|
26
|
+
'additionalProperties', # [Boolean] `true`: other keys are accepted
|
|
27
|
+
'required', # [Array]
|
|
28
|
+
'$comment', # [String]
|
|
29
|
+
'x-cli-envvar', # [String] Name of env var
|
|
30
|
+
'x-cli-option', # [String] Command line option (starts with "-")
|
|
31
|
+
'x-cli-false', # [String]. Option to use when switch value is false
|
|
32
|
+
'x-cli-short', # [String] Command line option (starts with "-")
|
|
33
|
+
'x-cli-switch', # [Boolean] `true` if option has no arg, else by default option has a value
|
|
34
|
+
'x-cli-special', # [Boolean] `true` if special handling (deferred)
|
|
35
|
+
'x-cli-convert', # [String,Hash] Method name for Convert object or Conversion for enum ts to arg
|
|
36
|
+
'x-cli-complete', # [String] Values proposed by shell completion: `file`, `folder` (see `Cli::Complete::KINDS`)
|
|
37
|
+
'x-security', # [String] Most restrictive security level that allows the key (see `Cli::Security`); enforced when the option is set, ignored here
|
|
38
|
+
'x-agents', # [Array] Supported agents (for doc only), if not specified: all
|
|
39
|
+
'x-ts-name', # [Boolean,String] (async) true if same name in transfer spec, else real name in transfer spec, else ignored
|
|
40
|
+
'x-ts-convert', # [String] (async) Name of methods to convert value from transfer spec to `conf` API.
|
|
41
|
+
'x-unit', # [String] (async) Time unit of the integer value in `conf` (e.g. `ms`), command line option is a DURATION
|
|
42
|
+
'x-deprecation' # [String] Deprecation message for doc
|
|
43
|
+
].freeze
|
|
44
|
+
|
|
45
|
+
private_constant :PROPERTY_KEYS
|
|
46
|
+
|
|
47
|
+
class << self
|
|
48
|
+
# Called by provider of definition before constructor of this class so that schema has all mandatory fields
|
|
49
|
+
# @param name_sym [Symbol] name of the schema to read
|
|
50
|
+
# @param ascp [Boolean] `true` if `ascp` mode
|
|
51
|
+
# @return [Aspera::Schema::Reader] validated schema reader
|
|
52
|
+
def read_schema(name_sym, ascp: false)
|
|
53
|
+
validate_schema(Schema::Registry.instance.reader(name_sym), ascp: ascp)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# @param agent [Symbol] Transfer agent name
|
|
57
|
+
# @param properties [Hash] Transfer spec parameter information
|
|
58
|
+
# @return [Boolean] `true` if given agent supports that field
|
|
59
|
+
def supported_by_agent(agent, properties)
|
|
60
|
+
!properties.key?('x-agents') || properties['x-agents'].include?(agent.to_s)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Documentation of the command line option of a property: `annotate` of `Schema::Documentation`
|
|
64
|
+
# @param node [Hash] Schema of the property
|
|
65
|
+
# @param formatter [FormatterInterface] Formatter of the documentation
|
|
66
|
+
# @return [Array<String>] Lines added to the description, empty if no option
|
|
67
|
+
def doc_lines(node, formatter)
|
|
68
|
+
envvar_prefix = ''
|
|
69
|
+
cli_option =
|
|
70
|
+
if node.key?('x-cli-envvar')
|
|
71
|
+
envvar_prefix = 'env:'
|
|
72
|
+
node['x-cli-envvar']
|
|
73
|
+
elsif node['x-cli-switch']
|
|
74
|
+
false_part = node.key?('x-cli-false') ? " / #{node['x-cli-false']}" : ''
|
|
75
|
+
"#{node['x-cli-option']}#{false_part}"
|
|
76
|
+
elsif node['x-cli-option']
|
|
77
|
+
arg_type = node.key?('enum') ? '{enum}' : "{#{[node['type']].flatten.join('|')}}"
|
|
78
|
+
conversion_tag = node.key?('x-cli-convert') ? 'conversion' : nil
|
|
79
|
+
sep = node['x-cli-option'].start_with?('--') ? '=' : ' '
|
|
80
|
+
"#{node['x-cli-option']}#{sep}#{"(#{conversion_tag})" if conversion_tag}#{arg_type}"
|
|
81
|
+
end
|
|
82
|
+
return [] unless cli_option
|
|
83
|
+
short = node.key?('x-cli-short') ? "(#{node['x-cli-short']})" : nil
|
|
84
|
+
["(#{'special:' if node['x-cli-special']}#{envvar_prefix}#{formatter.markdown_text("`#{cli_option}`")})#{short}"]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
private
|
|
88
|
+
|
|
89
|
+
# `ascp`: mandatory type
|
|
90
|
+
DIRECT_PROPERTIES = %w[x-cli-option x-cli-envvar x-cli-special].freeze
|
|
91
|
+
|
|
92
|
+
# Fill default values for some fields in the schema
|
|
93
|
+
# @param schema [Schema::Reader] The JSON schema
|
|
94
|
+
# @param ascp [Boolean] `true` if `ascp`
|
|
95
|
+
# @return [Schema::Reader] The JSON schema
|
|
96
|
+
def validate_schema(schema, ascp: false)
|
|
97
|
+
Aspera.assert_type(schema, Schema::Reader) { 'schema' }
|
|
98
|
+
Aspera.assert(schema.current.key?('properties')) { "Schema must have 'properties': #{schema}" }
|
|
99
|
+
schema.each_property do |property_schema, name, _full_name|
|
|
100
|
+
node = property_schema.current
|
|
101
|
+
unsupported_keys = node.keys - PROPERTY_KEYS
|
|
102
|
+
Aspera.assert(unsupported_keys.empty?) { "Unsupported definition keys: #{unsupported_keys}" }
|
|
103
|
+
Aspera.assert(node.key?('type') || node.key?('enum')) { "Missing type for #{name} in #{schema.current.dig('description').current}" }
|
|
104
|
+
Aspera.assert(node['type'].eql?('boolean')) { "switch must be bool: #{name}" } if node['x-cli-switch'] && !node['x-cli-special']
|
|
105
|
+
Aspera.assert(node['x-cli-switch']) { "boolean direct option must have x-cli-switch: #{name}" } if node['type'].eql?('boolean') && node.key?('x-cli-option') && supported_by_agent(:direct, node) && !node['x-cli-special']
|
|
106
|
+
node['x-cli-option'] = "--#{name.to_s.tr('_', '-')}" if node['x-cli-option'].eql?(true) || (node['x-cli-switch'].eql?(true) && !node.key?('x-cli-option'))
|
|
107
|
+
Aspera.assert(supported_by_agent(:direct, node)) { "#{name}: x-cli-option requires agent direct (or nil)" } if node['x-cli-option']
|
|
108
|
+
Aspera.assert(DIRECT_PROPERTIES.any? { |i| node.key?(i) }, name, type: :warn) if ascp && supported_by_agent(:direct, node)
|
|
109
|
+
node.freeze
|
|
110
|
+
end
|
|
111
|
+
schema
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# @param object [Hash] object with parameters
|
|
116
|
+
# @param schema [Schema::Reader] JSON schema
|
|
117
|
+
# @param convert [Object] function to convert value
|
|
118
|
+
def initialize(object, schema, convert)
|
|
119
|
+
@object = object # keep reference so that it can be modified by caller before calling `process_params`
|
|
120
|
+
@schema = schema
|
|
121
|
+
@convert = convert
|
|
122
|
+
@result = ExecSpec.new
|
|
123
|
+
@processed_parameters = []
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Change required-ness of property in schema
|
|
127
|
+
def required(name, required)
|
|
128
|
+
if required
|
|
129
|
+
@schema['required'].push(name) unless @schema['required']&.include?(name)
|
|
130
|
+
else
|
|
131
|
+
@schema['required'].delete(name)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# Add processed parameters to env and args, warns about unused parameters
|
|
136
|
+
# @param exec_spec [ExecSpec]
|
|
137
|
+
def add_to_exec_spec(exec_spec)
|
|
138
|
+
Log.dump(:exec_spec, @result)
|
|
139
|
+
# warn about non translated arguments
|
|
140
|
+
@object.each_pair do |name, value|
|
|
141
|
+
Log.log.warn { "Unknown transfer spec parameter: #{name} = \"#{value}\"" } unless @processed_parameters.include?(name)
|
|
142
|
+
end
|
|
143
|
+
# set result
|
|
144
|
+
exec_spec.env.merge!(@result.env)
|
|
145
|
+
exec_spec.args.concat(@result.args)
|
|
146
|
+
return
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# Add options directly to command line
|
|
150
|
+
def add_command_line_options(*options)
|
|
151
|
+
options = options.first if options.first.is_a?(Array) && options.length.eql?(1)
|
|
152
|
+
Aspera.assert_type(options, Array)
|
|
153
|
+
options.each { |o| @result.args.push(o.to_s) }
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def process_params
|
|
157
|
+
@schema['properties'].each_key do |k|
|
|
158
|
+
process_param(k)
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def read_param(name)
|
|
163
|
+
return process_param(name, read: true)
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
private
|
|
167
|
+
|
|
168
|
+
# Process a parameter from transfer specification and generate command line param or env var
|
|
169
|
+
# @param name [String] of parameter
|
|
170
|
+
# @param read [TrueClass,FalseClass] read and return value of parameter instead of normal processing (for special)
|
|
171
|
+
def process_param(name, read: false)
|
|
172
|
+
properties = @schema['properties'][name]
|
|
173
|
+
# should not happen
|
|
174
|
+
if properties.nil?
|
|
175
|
+
Log.log.warn { "Unknown parameter #{name}" }
|
|
176
|
+
return
|
|
177
|
+
end
|
|
178
|
+
# check mandatory parameter (nil is valid value), TODO: change exception ?
|
|
179
|
+
Aspera.assert(!(@schema['required']&.include?(name) && !properties['x-cli-special'] && !@object.key?(name)), type: Transfer::Error) { "Missing mandatory parameter: #{name}" }
|
|
180
|
+
parameter_value = @object[name]
|
|
181
|
+
# no default setting
|
|
182
|
+
# parameter_value=properties['default'] if parameter_value.nil? and properties.has_key?('default')
|
|
183
|
+
# Check parameter type
|
|
184
|
+
expected_classes =
|
|
185
|
+
[properties['type']].flatten.map do |type|
|
|
186
|
+
case type
|
|
187
|
+
when 'string' then [String]
|
|
188
|
+
when 'array' then [Array]
|
|
189
|
+
when 'object' then [Hash]
|
|
190
|
+
when 'integer' then [Integer]
|
|
191
|
+
when 'boolean' then [TrueClass, FalseClass]
|
|
192
|
+
else Aspera.error_unexpected_value(properties['type']) { "Property #{name}" }
|
|
193
|
+
end
|
|
194
|
+
end.flatten
|
|
195
|
+
# check that value is of expected type
|
|
196
|
+
raise Transfer::Error, "#{name} is #{parameter_value.class} (#{parameter_value}), shall be #{properties['type']}, " \
|
|
197
|
+
unless parameter_value.nil? || expected_classes.include?(parameter_value.class)
|
|
198
|
+
# special processing will be requested with type get_value
|
|
199
|
+
@processed_parameters.push(name) if !properties['x-cli-special'] || read
|
|
200
|
+
|
|
201
|
+
# process only non-nil values
|
|
202
|
+
return if parameter_value.nil?
|
|
203
|
+
|
|
204
|
+
# check that value is of an accepted type (string, integer, boolean)
|
|
205
|
+
Aspera.assert(!(properties.key?('enum') && !properties['enum'].include?(parameter_value)), type: ParameterError) { "Enum value #{parameter_value} is not allowed for #{name}" }
|
|
206
|
+
|
|
207
|
+
# convert some values if value on command line needs processing from value in structure
|
|
208
|
+
if (convert = properties['x-cli-convert'])
|
|
209
|
+
converted_value =
|
|
210
|
+
case convert
|
|
211
|
+
when Hash then convert[parameter_value]
|
|
212
|
+
when String then @convert.send(convert, parameter_value)
|
|
213
|
+
else Aspera.error_unexpected_value(convert) { "Conversion type for #{name} is Hash or String only." }
|
|
214
|
+
end
|
|
215
|
+
Aspera.assert(!converted_value.nil?, type: ParameterError) { "No conversion for: #{name}=#{parameter_value}" }
|
|
216
|
+
parameter_value = converted_value
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
return unless self.class.supported_by_agent(:direct, properties)
|
|
220
|
+
|
|
221
|
+
if read
|
|
222
|
+
# just get value (deferred)
|
|
223
|
+
return parameter_value
|
|
224
|
+
elsif properties['x-cli-special']
|
|
225
|
+
# process later
|
|
226
|
+
return
|
|
227
|
+
elsif properties.key?('x-cli-envvar')
|
|
228
|
+
# set in env var
|
|
229
|
+
@result.env[properties['x-cli-envvar']] = parameter_value
|
|
230
|
+
elsif properties['x-cli-switch']
|
|
231
|
+
case parameter_value
|
|
232
|
+
when true
|
|
233
|
+
add_command_line_options(properties['x-cli-option'])
|
|
234
|
+
when false
|
|
235
|
+
add_command_line_options(properties['x-cli-false']) if properties.key?('x-cli-false')
|
|
236
|
+
else Aspera.error_unexpected_value(parameter_value) { name }
|
|
237
|
+
end
|
|
238
|
+
else
|
|
239
|
+
# transform into command line option with value
|
|
240
|
+
# parameter_value=parameter_value.to_s if parameter_value.is_a?(Integer)
|
|
241
|
+
parameter_value = Array(parameter_value)
|
|
242
|
+
# if transfer_spec value is an array, applies option many times
|
|
243
|
+
parameter_value.each { |v| add_command_line_options(properties['x-cli-option'], v) }
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../assert'
|
|
7
|
+
module Aspera
|
|
8
|
+
module Transfer
|
|
9
|
+
# conversion class for transfer spec values to CLI values (ascp)
|
|
10
|
+
class CommandLineConverter
|
|
11
|
+
class << self
|
|
12
|
+
# special encoding methods used in YAML (key: convert)
|
|
13
|
+
def remove_hyphen(value); value.tr('-', ''); end
|
|
14
|
+
|
|
15
|
+
# special encoding methods used in YAML (key: convert)
|
|
16
|
+
def json64(value); Base64.strict_encode64(JSON.generate(value)); end
|
|
17
|
+
|
|
18
|
+
# special encoding methods used in YAML (key: convert)
|
|
19
|
+
def base64(value); Base64.strict_encode64(value); end
|
|
20
|
+
|
|
21
|
+
# transform yes/no to true/false
|
|
22
|
+
def yes_to_true(value)
|
|
23
|
+
case value
|
|
24
|
+
when 'yes' then return true
|
|
25
|
+
when 'no' then return false
|
|
26
|
+
else Aspera.error_unexpected_value(value) { 'only: yes or no: ' }
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Kbps to bps
|
|
31
|
+
def kbps_to_bps(value)
|
|
32
|
+
1000 * value.to_i
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -24,9 +24,9 @@ module Aspera
|
|
|
24
24
|
def create(name)
|
|
25
25
|
return unless name.start_with?(PREFIX)
|
|
26
26
|
name_params = name.delete_prefix(PREFIX).split('?', 2)
|
|
27
|
-
Aspera.assert(name_params.length.eql?(2), type:
|
|
27
|
+
Aspera.assert(name_params.length.eql?(2), type: ParameterError) { "Format: #{PREFIX}<file path>?<size>" }
|
|
28
28
|
m = name_params[1].downcase.match(/^(\d+)([#{SIZE_UNITS.join('')}]?)$/)
|
|
29
|
-
Aspera.assert(m, type:
|
|
29
|
+
Aspera.assert(m, type: ParameterError) { "Format: <integer>[#{SIZE_UNITS.join(',')}]" }
|
|
30
30
|
size = m[2].empty? ? m[1].to_i : m[1].to_i * (1024**(SIZE_UNITS.index(m[2]) + 1))
|
|
31
31
|
return FauxFile.new(name_params[0], size)
|
|
32
32
|
end
|