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,374 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
# cspell:ignore errstr fstat zstr zmode zuid zgid zctime zatime zmtime fcount dcount ascmdtypes EDOCROOT
|
|
7
|
+
require_relative '../../log'
|
|
8
|
+
require_relative '../../assert'
|
|
9
|
+
|
|
10
|
+
module Aspera
|
|
11
|
+
module Plugins
|
|
12
|
+
module Server
|
|
13
|
+
# Run `ascmd` commands using specified executor (usually, remotely on transfer node)
|
|
14
|
+
# Equivalent of SDK "command client"
|
|
15
|
+
# execute: "ascmd -h" to get syntax
|
|
16
|
+
#
|
|
17
|
+
# Protocol (see `ascmdtypes.h`):
|
|
18
|
+
# - Input: one command per line (`as_<operation> <arguments>`), then `as_exit`.
|
|
19
|
+
# - Output: one reply per command, `ascmd` continues after a failed command.
|
|
20
|
+
# The first reply is the system information: sent at start (protocol 1), or for `as_session_init` (protocol 2).
|
|
21
|
+
# - Replies and their fields are Type-Length-Value: type (1 byte), length (4 bytes), value. Numbers are big endian.
|
|
22
|
+
class AsCmd
|
|
23
|
+
# Operations:
|
|
24
|
+
# - `args`: Integer: the arguments are split into one command per group of this size (at least one group).
|
|
25
|
+
# Range: all arguments in a single command, their number in the range.
|
|
26
|
+
# - `reply`: types of reply of a successful command (else: `error`).
|
|
27
|
+
OPERATION_SPECS = {
|
|
28
|
+
ls: {args: 1, reply: %i[file dir]},
|
|
29
|
+
rm: {args: 1, reply: %i[success]},
|
|
30
|
+
mv: {args: 2, reply: %i[success]},
|
|
31
|
+
cp: {args: 2, reply: %i[success]},
|
|
32
|
+
mkdir: {args: 1, reply: %i[success]},
|
|
33
|
+
du: {args: 1, reply: %i[size]},
|
|
34
|
+
md5sum: {args: 1, reply: %i[md5sum]},
|
|
35
|
+
df: {args: 0..1, reply: %i[df]},
|
|
36
|
+
info: {args: 0..0, reply: %i[info]}
|
|
37
|
+
}.freeze
|
|
38
|
+
|
|
39
|
+
# Enumerations of the protocol start at one: TLV type = index in the list + `ENUM_START`
|
|
40
|
+
ENUM_START = 1
|
|
41
|
+
|
|
42
|
+
# Reply types (`as_ftype_e`)
|
|
43
|
+
REPLY_TYPES = %i[file dir size error info success exit df md5sum].freeze
|
|
44
|
+
|
|
45
|
+
# Fields of structures, in the order of their enumeration: name and base type, plus `:multiple` for a field that repeats (Array of values).
|
|
46
|
+
# Fields `mode`, `uid` and `gid` are not sent by `ascmd`.
|
|
47
|
+
STRUCTURES = {
|
|
48
|
+
# as_fstat_e
|
|
49
|
+
stat: [
|
|
50
|
+
%i[name zstr], %i[size int64], %i[mode int32], %i[zmode zstr], %i[uid int32], %i[zuid zstr], %i[gid int32], %i[zgid zstr],
|
|
51
|
+
%i[ctime epoch], %i[zctime zstr], %i[mtime epoch], %i[zmtime zstr], %i[atime epoch], %i[zatime zstr], %i[symlink zstr],
|
|
52
|
+
%i[errno int32], %i[errstr zstr]
|
|
53
|
+
],
|
|
54
|
+
# as_info_e
|
|
55
|
+
info: [
|
|
56
|
+
%i[platform zstr], %i[version zstr], %i[lang zstr], %i[territory zstr], %i[codeset zstr], %i[lc_ctype zstr], %i[lc_numeric zstr],
|
|
57
|
+
%i[lc_time zstr], %i[lc_all zstr], %i[dev zstr multiple], %i[browse_caps zstr], %i[protocol zstr]
|
|
58
|
+
],
|
|
59
|
+
# as_size_e
|
|
60
|
+
size: [%i[size int64], %i[fcount int32], %i[dcount int32], %i[failed_fcount int32], %i[failed_dcount int32]],
|
|
61
|
+
# as_error_e
|
|
62
|
+
error: [%i[errno int32], %i[errstr zstr]],
|
|
63
|
+
# as_mnt_e
|
|
64
|
+
mnt: [
|
|
65
|
+
%i[fs zstr], %i[dir zstr], %i[type zstr], %i[total int64], %i[used int64], %i[free int64], %i[fcount int64], %i[errno int32],
|
|
66
|
+
%i[errstr zstr]
|
|
67
|
+
],
|
|
68
|
+
# as_md5sum_e
|
|
69
|
+
md5sum: [%i[md5sum zstr]]
|
|
70
|
+
}.freeze
|
|
71
|
+
|
|
72
|
+
# Size of the header of a TLV: type (1 byte) and length (4 bytes)
|
|
73
|
+
TLV_HEADER_SIZE = 5
|
|
74
|
+
# `ascmd` reads a command line with `fgets` in a buffer of `AS_MAX_BUFFER` (4096): newline and NUL included
|
|
75
|
+
MAX_LINE_BYTES = 4094
|
|
76
|
+
|
|
77
|
+
# A decoded reply
|
|
78
|
+
Reply = Data.define(:type, :value)
|
|
79
|
+
|
|
80
|
+
private_constant :OPERATION_SPECS, :ENUM_START, :REPLY_TYPES, :STRUCTURES, :TLV_HEADER_SIZE, :MAX_LINE_BYTES, :Reply
|
|
81
|
+
|
|
82
|
+
# list of supported actions
|
|
83
|
+
OPERATIONS = OPERATION_SPECS.keys.freeze
|
|
84
|
+
|
|
85
|
+
# Raised when one or more commands of `ascmd` failed. The other commands were executed.
|
|
86
|
+
# Subclass `NotFound` or `AccessDenied` when all commands failed for this reason.
|
|
87
|
+
class Error < StandardError
|
|
88
|
+
# A failed command
|
|
89
|
+
# @!attribute [r] errno [Integer, nil] Error number (-1: error of `ascmd` itself), `nil` if no reply
|
|
90
|
+
# @!attribute [r] errstr [String] Error message
|
|
91
|
+
# @!attribute [r] arguments [Array<String>] Arguments of the command
|
|
92
|
+
Failure = Data.define(:errno, :errstr, :arguments)
|
|
93
|
+
|
|
94
|
+
# @return [Symbol] the operation
|
|
95
|
+
attr_reader :operation
|
|
96
|
+
# @return [Array<Failure>] failed commands, in order
|
|
97
|
+
attr_reader :failures
|
|
98
|
+
|
|
99
|
+
# @param operation [Symbol] the operation
|
|
100
|
+
# @param failures [Array<Failure>] failed commands
|
|
101
|
+
def initialize(operation, failures)
|
|
102
|
+
@operation = operation
|
|
103
|
+
@failures = failures
|
|
104
|
+
super(failures.map { |f| "ascmd: #{f.errstr}#{" (#{f.errno})" unless f.errno.nil?}" }.join("\n"))
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# @return [String] one line per failed command, with its arguments
|
|
108
|
+
def extended_message
|
|
109
|
+
@failures.map { |f| %Q{errno=#{f.errno} errstr="#{f.errstr}" command=#{@operation} arguments=#{f.arguments.join(',')}} }.join("\n")
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# All commands failed: file or folder not found
|
|
114
|
+
class NotFound < Error; end
|
|
115
|
+
|
|
116
|
+
# All commands failed: access refused (permissions of the file, or path outside the docroot)
|
|
117
|
+
class AccessDenied < Error; end
|
|
118
|
+
|
|
119
|
+
# Code `AS_EDOCROOT` of Aspera (path outside the docroot), the same on all platforms
|
|
120
|
+
AS_EDOCROOT = 28_672
|
|
121
|
+
# Error numbers (`as_err_t` in `aserrno.h`) by error class: they are error codes of the system of the server.
|
|
122
|
+
# As in `aserrno.h`, a platform other than Windows is POSIX (same values on Linux, macOS, AIX).
|
|
123
|
+
# `unknown`: `ascmd` failed at start, before the system information: only the codes with the same meaning on both.
|
|
124
|
+
ERRNO_CLASSES = {
|
|
125
|
+
# ENOENT ENOTDIR, EPERM EACCES
|
|
126
|
+
posix: {NotFound => [2, 20], AccessDenied => [1, 13, AS_EDOCROOT]},
|
|
127
|
+
# ERROR_FILE_NOT_FOUND ERROR_PATH_NOT_FOUND ERROR_DIRECTORY, ERROR_ACCESS_DENIED
|
|
128
|
+
windows: {NotFound => [2, 3, 267], AccessDenied => [5, AS_EDOCROOT]},
|
|
129
|
+
unknown: {NotFound => [2], AccessDenied => [AS_EDOCROOT]}
|
|
130
|
+
}.freeze
|
|
131
|
+
# Start of field `platform` of the system information on Windows (`as_platform_os`), else the output of `uname`
|
|
132
|
+
WINDOWS_PLATFORM = 'Microsoft Windows '
|
|
133
|
+
private_constant :AS_EDOCROOT, :ERRNO_CLASSES, :WINDOWS_PLATFORM
|
|
134
|
+
|
|
135
|
+
# @param command_executor [Object] provides the "execute" method, taking a command to execute, and stdin to feed to it, typically: ssh or local
|
|
136
|
+
def initialize(command_executor)
|
|
137
|
+
@command_executor = command_executor
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# Execute an operation in one session of `ascmd`: one command per group of arguments.
|
|
141
|
+
# All commands are executed, even after one failed.
|
|
142
|
+
# @param operation [Symbol] One of OPERATIONS
|
|
143
|
+
# @param arguments [Array<String>] Paths (`mv`, `cp`: source and destination pairs)
|
|
144
|
+
# @param version [Integer] Protocol: 1 or 2
|
|
145
|
+
# @param host [String, nil] Sent with `as_session_init` (protocol 2)
|
|
146
|
+
# @return [true, Array<Hash>, Hash] depending on operation:
|
|
147
|
+
# `rm`, `mv`, `cp`, `mkdir`: `true`;
|
|
148
|
+
# `ls`: entries of all paths;
|
|
149
|
+
# `du`, `md5sum`: one Hash per path, with key `path`;
|
|
150
|
+
# `df`: mount points;
|
|
151
|
+
# `info`: system information.
|
|
152
|
+
# @raise [Error] if one or more commands failed: `NotFound` or `AccessDenied` when all failed for this reason
|
|
153
|
+
# @raise [ParameterError] if the arguments do not fit the operation, or cannot be sent to `ascmd`
|
|
154
|
+
def execute_single(operation, arguments, version: 2, host: nil)
|
|
155
|
+
arguments = [] if arguments.nil?
|
|
156
|
+
Log.log.debug { "execute_single:#{operation}:#{arguments}" }
|
|
157
|
+
Aspera.assert_values(operation, OPERATIONS)
|
|
158
|
+
Aspera.assert_values(version, [1, 2]) { 'protocol' }
|
|
159
|
+
Aspera.assert_array_all(arguments, String) { 'arguments' }
|
|
160
|
+
commands = command_arguments(operation, arguments)
|
|
161
|
+
remote_cmd = 'ascmd'
|
|
162
|
+
lines = []
|
|
163
|
+
if version.eql?(2)
|
|
164
|
+
lines.push(['as_session_init', "--protocol=#{version}", (quote("--host=#{host}") unless host.nil?)].compact.join(' '))
|
|
165
|
+
remote_cmd += ' -V2'
|
|
166
|
+
end
|
|
167
|
+
commands.each { |args| lines.push(["as_#{operation}", *args.map { |arg| quote(arg) }].join(' ')) }
|
|
168
|
+
lines.each do |line|
|
|
169
|
+
Aspera.assert(line.bytesize <= MAX_LINE_BYTES, type: ParameterError) { "ascmd: command longer than #{MAX_LINE_BYTES} bytes: #{line[0, 80]}..." }
|
|
170
|
+
end
|
|
171
|
+
lines.push('as_exit', '')
|
|
172
|
+
stdin_input = lines.join("\n")
|
|
173
|
+
Log.log.trace1 { "execute_single:#{stdin_input}" }
|
|
174
|
+
output = @command_executor.execute(remote_cmd, input: stdin_input)
|
|
175
|
+
Aspera.assert(!output.empty?, 'empty answer from server')
|
|
176
|
+
replies = each_tlv(output).map { |id, value| decode_reply(id, value) }
|
|
177
|
+
Log.log.trace1 { "execute_single:replies=#{replies}" }
|
|
178
|
+
system_info = replies.shift
|
|
179
|
+
# `ascmd` failed to start, e.g. invalid docroot
|
|
180
|
+
raise error_for(operation, [failure(system_info.value, [])], nil) if system_info.type.eql?(:error)
|
|
181
|
+
Aspera.assert(system_info.type.eql?(:info)) { "ascmd: expecting system information first, but have: #{system_info.type}" }
|
|
182
|
+
Aspera.assert(replies.length <= commands.length) { "ascmd: #{replies.length} replies for #{commands.length} commands" }
|
|
183
|
+
failures = []
|
|
184
|
+
commands.each_with_index do |args, index|
|
|
185
|
+
reply = replies[index]
|
|
186
|
+
if reply.nil?
|
|
187
|
+
# `ascmd` stopped before this command
|
|
188
|
+
failures.push(Error::Failure.new(errno: nil, errstr: 'no reply', arguments: args))
|
|
189
|
+
elsif reply.type.eql?(:error)
|
|
190
|
+
failures.push(failure(reply.value, args))
|
|
191
|
+
else
|
|
192
|
+
Aspera.assert_values(reply.type, OPERATION_SPECS[operation][:reply]) { "ascmd: reply to #{operation}" }
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
raise error_for(operation, failures, system_info.value) unless failures.empty?
|
|
196
|
+
return result_of(operation, commands, replies)
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
private
|
|
200
|
+
|
|
201
|
+
# Arguments of each command of the operation
|
|
202
|
+
# @param operation [Symbol] One of OPERATIONS
|
|
203
|
+
# @param arguments [Array<String>] Arguments of the operation
|
|
204
|
+
# @return [Array<Array<String>>] arguments of each command
|
|
205
|
+
def command_arguments(operation, arguments)
|
|
206
|
+
count = OPERATION_SPECS[operation][:args]
|
|
207
|
+
case count
|
|
208
|
+
when Integer
|
|
209
|
+
Aspera.assert(!arguments.empty? && (arguments.length % count).zero?, type: ParameterError) do
|
|
210
|
+
"ascmd #{operation}: expecting a non-zero multiple of #{count} arguments, but have #{arguments.length}"
|
|
211
|
+
end
|
|
212
|
+
arguments.each_slice(count).to_a
|
|
213
|
+
when Range
|
|
214
|
+
Aspera.assert(count.cover?(arguments.length), type: ParameterError) { "ascmd #{operation}: expecting #{count} arguments, but have #{arguments.length}" }
|
|
215
|
+
[arguments]
|
|
216
|
+
else Aspera.error_unexpected_value(count) { 'args' }
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
# Argument of a command line of `ascmd`: in double quotes, `"` and `\` escaped.
|
|
221
|
+
# A newline cannot be escaped: it ends the command, the rest would be another command.
|
|
222
|
+
# @param value [String] the argument
|
|
223
|
+
# @return [String] quoted argument
|
|
224
|
+
def quote(value)
|
|
225
|
+
Aspera.assert(!value.match?(/[\n\0]/), type: ParameterError) { "ascmd: newline and NUL characters are not supported: #{value.inspect}" }
|
|
226
|
+
%Q{"#{value.gsub(/["\\]/) { |s| "\\#{s}" }}"}
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
# @param error [Hash] Value of a reply `error`
|
|
230
|
+
# @param arguments [Array<String>] Arguments of the command
|
|
231
|
+
# @return [Error::Failure]
|
|
232
|
+
def failure(error, arguments)
|
|
233
|
+
Error::Failure.new(errno: error[:errno], errstr: error[:errstr], arguments: arguments)
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
# @param operation [Symbol] the operation
|
|
237
|
+
# @param failures [Array<Error::Failure>] failed commands
|
|
238
|
+
# @param info [Hash, nil] system information of the server, `nil` if `ascmd` failed at start
|
|
239
|
+
# @return [Error] of the class of the error numbers of the failures when they all have the same, else `Error`
|
|
240
|
+
def error_for(operation, failures, info)
|
|
241
|
+
classes = ERRNO_CLASSES[errno_platform(info)]
|
|
242
|
+
failure_classes = failures.map { |f| classes.find { |_, codes| codes.include?(f.errno) }&.first || Error }.uniq
|
|
243
|
+
(failure_classes.one? ? failure_classes.first : Error).new(operation, failures)
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
# @param info [Hash, nil] system information of the server, `nil` if `ascmd` failed at start
|
|
247
|
+
# @return [Symbol] key of `ERRNO_CLASSES`
|
|
248
|
+
def errno_platform(info)
|
|
249
|
+
platform = info&.dig(:platform)
|
|
250
|
+
return :unknown if platform.nil? || platform.empty?
|
|
251
|
+
platform.start_with?(WINDOWS_PLATFORM) ? :windows : :posix
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
# Result of the operation, from the replies of its successful commands
|
|
255
|
+
# @param operation [Symbol] One of OPERATIONS
|
|
256
|
+
# @param commands [Array<Array<String>>] Arguments of each command
|
|
257
|
+
# @param replies [Array<Reply>] Reply of each command
|
|
258
|
+
def result_of(operation, commands, replies)
|
|
259
|
+
case operation
|
|
260
|
+
when :rm, :mv, :cp, :mkdir then true
|
|
261
|
+
when :ls
|
|
262
|
+
replies.flat_map do |reply|
|
|
263
|
+
case reply.type
|
|
264
|
+
when :dir then reply.value
|
|
265
|
+
when :file then [reply.value]
|
|
266
|
+
else Aspera.error_unexpected_value(reply.type) { 'reply' }
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
when :du, :md5sum then commands.zip(replies).map { |args, reply| {path: args.first}.merge(reply.value) }
|
|
270
|
+
when :df, :info then replies.first.value
|
|
271
|
+
else Aspera.error_unexpected_value(operation) { 'operation' }
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
# Iterate on a sequence of TLV
|
|
276
|
+
# @param data [String] Binary data
|
|
277
|
+
# @yieldparam id [Integer] TLV type
|
|
278
|
+
# @yieldparam value [String] TLV value
|
|
279
|
+
# @return [Enumerator] if no block given
|
|
280
|
+
def each_tlv(data)
|
|
281
|
+
return enum_for(__method__, data) unless block_given?
|
|
282
|
+
offset = 0
|
|
283
|
+
while offset < data.bytesize
|
|
284
|
+
Aspera.assert(offset + TLV_HEADER_SIZE <= data.bytesize) { "ascmd: truncated header at #{offset}" }
|
|
285
|
+
id, length = data.unpack('CL>', offset: offset)
|
|
286
|
+
offset += TLV_HEADER_SIZE
|
|
287
|
+
Aspera.assert(offset + length <= data.bytesize) { "ascmd: truncated value at #{offset}, length #{length}" }
|
|
288
|
+
yield(id, data.byteslice(offset, length))
|
|
289
|
+
offset += length
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
# @param id [Integer] TLV type of the reply
|
|
294
|
+
# @param value [String] TLV value
|
|
295
|
+
# @return [Reply]
|
|
296
|
+
def decode_reply(id, value)
|
|
297
|
+
type = enum_value(REPLY_TYPES, id)
|
|
298
|
+
Aspera.assert(!type.nil?) { "ascmd: unknown reply type: #{id}" }
|
|
299
|
+
decoded =
|
|
300
|
+
case type
|
|
301
|
+
when :file then decode_structure(:stat, value)
|
|
302
|
+
# entries are replies `file`
|
|
303
|
+
when :dir
|
|
304
|
+
each_tlv(value).map do |entry_id, entry|
|
|
305
|
+
Aspera.assert(enum_value(REPLY_TYPES, entry_id).eql?(:file)) { "ascmd: dir: unexpected entry type: #{entry_id}" }
|
|
306
|
+
decode_structure(:stat, entry)
|
|
307
|
+
end
|
|
308
|
+
# mount points one after the other, each one starts with its first field
|
|
309
|
+
when :df then decode_structure(:mnt, value, list: true)
|
|
310
|
+
when :size, :error, :info, :md5sum then decode_structure(type, value)
|
|
311
|
+
when :success then true
|
|
312
|
+
else Aspera.error_unexpected_value(type) { 'reply' }
|
|
313
|
+
end
|
|
314
|
+
Reply.new(type: type, value: decoded)
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
# @param name [Symbol] Structure name
|
|
318
|
+
# @param data [String] Its fields as TLV
|
|
319
|
+
# @param list [Boolean] `true`: several structures, each one starts with its first field
|
|
320
|
+
# @return [Hash, Array<Hash>] decoded structure, or list of structures
|
|
321
|
+
def decode_structure(name, data, list: false)
|
|
322
|
+
structures = []
|
|
323
|
+
each_tlv(data) do |id, value|
|
|
324
|
+
structures.push({}) if structures.empty? || (list && id.eql?(ENUM_START))
|
|
325
|
+
field_name, type, repeat = enum_value(STRUCTURES[name], id)
|
|
326
|
+
Aspera.assert(!field_name.nil?) { "ascmd: #{name}: unknown field: #{id}" }
|
|
327
|
+
decoded = decode_value(type, value)
|
|
328
|
+
fields = structures.last
|
|
329
|
+
case repeat
|
|
330
|
+
when nil
|
|
331
|
+
Aspera.assert(!fields.key?(field_name)) { "ascmd: #{name}: duplicate field: #{field_name}" }
|
|
332
|
+
fields[field_name] = decoded
|
|
333
|
+
when :multiple then (fields[field_name] ||= []).push(decoded)
|
|
334
|
+
else Aspera.error_unexpected_value(repeat) { 'field' }
|
|
335
|
+
end
|
|
336
|
+
end
|
|
337
|
+
return structures if list
|
|
338
|
+
return structures.first || {}
|
|
339
|
+
end
|
|
340
|
+
|
|
341
|
+
# @param list [Array] Values of an enumeration of the protocol, in order
|
|
342
|
+
# @param id [Integer] TLV type
|
|
343
|
+
# @return [Object, nil] the value, `nil` if unknown (a negative index would wrap around)
|
|
344
|
+
def enum_value(list, id)
|
|
345
|
+
list[id - ENUM_START] if id >= ENUM_START
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
# @param type [Symbol] Base type
|
|
349
|
+
# @param value [String] Binary value
|
|
350
|
+
# @return [String, Integer, Time] decoded value
|
|
351
|
+
def decode_value(type, value)
|
|
352
|
+
case type
|
|
353
|
+
when :zstr then value.unpack1('Z*').force_encoding(Encoding::UTF_8)
|
|
354
|
+
# signed: errno is -1 for an error of ascmd itself
|
|
355
|
+
when :int32 then decode_number(value, 'l>', 4)
|
|
356
|
+
when :int64 then decode_number(value, 'Q>', 8)
|
|
357
|
+
# signed: seconds since 1970
|
|
358
|
+
when :epoch then Time.at(decode_number(value, 'q>', 8))
|
|
359
|
+
else Aspera.error_unexpected_value(type) { 'base type' }
|
|
360
|
+
end
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
# @param value [String] Binary value
|
|
364
|
+
# @param format [String] Format of `unpack1`
|
|
365
|
+
# @param size [Integer] Expected size in bytes
|
|
366
|
+
# @return [Integer]
|
|
367
|
+
def decode_number(value, format, size)
|
|
368
|
+
Aspera.assert(value.bytesize.eql?(size)) { "ascmd: expecting #{size} bytes, but have #{value.bytesize}" }
|
|
369
|
+
value.unpack1(format)
|
|
370
|
+
end
|
|
371
|
+
end
|
|
372
|
+
end
|
|
373
|
+
end
|
|
374
|
+
end
|
|
@@ -3,34 +3,44 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
4
|
# SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
|
|
6
|
-
require_relative 'basic_auth'
|
|
7
|
-
require_relative '../sync_actions'
|
|
8
|
-
require_relative '../ascp_logs_actions'
|
|
6
|
+
require_relative '../../cli/plugins/basic_auth'
|
|
7
|
+
require_relative '../xfer/sync_actions'
|
|
8
|
+
require_relative '../xfer/ascp_logs_actions'
|
|
9
9
|
require_relative '../../transfer/result'
|
|
10
10
|
require_relative '../../transfer/spec'
|
|
11
|
-
require_relative '
|
|
11
|
+
require_relative 'ascmd'
|
|
12
12
|
require_relative '../../ssh'
|
|
13
13
|
require_relative '../../nagios'
|
|
14
14
|
require_relative '../../log'
|
|
15
15
|
require_relative '../../assert'
|
|
16
16
|
require_relative '../../environment'
|
|
17
|
+
require_relative '../xfer/transfer_agent'
|
|
17
18
|
require 'shellwords'
|
|
18
19
|
require 'tmpdir'
|
|
19
20
|
module Aspera
|
|
20
|
-
module
|
|
21
|
-
module
|
|
21
|
+
module Plugins
|
|
22
|
+
module Server
|
|
22
23
|
# Operations on HSTS with SSH/FASP (ascmd/ascp)
|
|
23
|
-
class
|
|
24
|
-
include
|
|
25
|
-
|
|
24
|
+
class Commands < Cli::Plugins::Base
|
|
25
|
+
include Cli::Plugins::BasicAuth
|
|
26
|
+
|
|
27
|
+
include Aspera::Plugins::Xfer::SyncActions
|
|
28
|
+
include Aspera::Plugins::Xfer::AscpLogsActions
|
|
26
29
|
|
|
27
30
|
SSH_SCHEME = 'ssh'
|
|
28
31
|
LOCAL_SCHEME = 'local'
|
|
29
32
|
HTTPS_SCHEME = 'https'
|
|
30
33
|
URI_SCHEMES = [SSH_SCHEME, LOCAL_SCHEME, HTTPS_SCHEME].freeze
|
|
34
|
+
# Schema of option `ssh_options`, in the schemas of the bundle (manifest `schemas`)
|
|
35
|
+
SSH_OPTIONS = 'server_opts:components.schemas.SshOptions'
|
|
31
36
|
|
|
32
37
|
private_constant :SSH_SCHEME, :URI_SCHEMES
|
|
33
38
|
|
|
39
|
+
# A command of `ascmd` refused by the server exits with the code of its category
|
|
40
|
+
Cli::ExitCode.add_error(AsCmd::Error, label: 'ascmd', code: Cli::ExitCode::API)
|
|
41
|
+
Cli::ExitCode.add_error(AsCmd::NotFound, label: 'ascmd', code: Cli::ExitCode::NOT_FOUND)
|
|
42
|
+
Cli::ExitCode.add_error(AsCmd::AccessDenied, label: 'ascmd', code: Cli::ExitCode::AUTH)
|
|
43
|
+
|
|
34
44
|
class LocalExecutor
|
|
35
45
|
def execute(ascmd_path, input:)
|
|
36
46
|
Environment.secure_execute(ascmd_path, mode: :capture, stdin_data: input, binmode: true, exception: false).first
|
|
@@ -90,6 +100,8 @@ module Aspera
|
|
|
90
100
|
@ascmd_executor = nil
|
|
91
101
|
@server_transfer_spec = nil
|
|
92
102
|
@ssh_opts = options.get_option(:ssh_options).symbolize_keys
|
|
103
|
+
# After a failed authentication, Net::SSH asks for a password (or the passphrase of a key) in a terminal: only with option `interactive`
|
|
104
|
+
@ssh_opts[:non_interactive] = !options.get_option(:interactive) unless @ssh_opts.key?(:non_interactive)
|
|
93
105
|
end
|
|
94
106
|
|
|
95
107
|
# Read command line options
|
|
@@ -121,14 +133,14 @@ module Aspera
|
|
|
121
133
|
if !server_uri.scheme.eql?(SSH_SCHEME)
|
|
122
134
|
Log.log.warn('URL scheme is https but no token was provided in transfer spec.')
|
|
123
135
|
Log.log.warn("If you want to access the server, not using WSS for session, then use a URL with scheme \"#{SSH_SCHEME}\" and proper SSH port")
|
|
124
|
-
assumed_url = "#{SSH_SCHEME}://#{server_transfer_spec['remote_host']}:#{Transfer::Spec::SSH_PORT}"
|
|
136
|
+
assumed_url = "#{SSH_SCHEME}://#{server_transfer_spec['remote_host']}:#{Aspera::Transfer::Spec::SSH_PORT}"
|
|
125
137
|
Log.log.warn { "Assuming proper URL is: #{assumed_url}" }
|
|
126
138
|
server_uri = URI.parse(assumed_url)
|
|
127
139
|
end
|
|
128
140
|
# Scheme is SSH
|
|
129
141
|
if options.get_option(:username).nil?
|
|
130
|
-
options.set_option(:username, Transfer::Spec::ACCESS_KEY_TRANSFER_USER)
|
|
131
|
-
Log.log.info { "No username provided: Assuming default transfer user: #{Transfer::Spec::ACCESS_KEY_TRANSFER_USER}" }
|
|
142
|
+
options.set_option(:username, Aspera::Transfer::Spec::ACCESS_KEY_TRANSFER_USER)
|
|
143
|
+
Log.log.info { "No username provided: Assuming default transfer user: #{Aspera::Transfer::Spec::ACCESS_KEY_TRANSFER_USER}" }
|
|
132
144
|
end
|
|
133
145
|
server_transfer_spec['remote_user'] = options.get_option(:username, mandatory: true)
|
|
134
146
|
if !server_uri.port.nil?
|
|
@@ -144,7 +156,6 @@ module Aspera
|
|
|
144
156
|
end
|
|
145
157
|
ssh_key_list = options.get_option(:ssh_keys)
|
|
146
158
|
if !ssh_key_list.nil?
|
|
147
|
-
Aspera.assert_array_all(ssh_key_list, String) { 'ssh_keys' }
|
|
148
159
|
ssh_key_list.map! { |p| File.expand_path(p) }
|
|
149
160
|
Log.dump(:ssh_keys, ssh_key_list)
|
|
150
161
|
if !ssh_key_list.empty?
|
|
@@ -162,7 +173,7 @@ module Aspera
|
|
|
162
173
|
end
|
|
163
174
|
# if user provided transfer spec has a token, we will use bypass keys
|
|
164
175
|
cred_set = true if transfer.user_transfer_spec['token'].is_a?(String)
|
|
165
|
-
Aspera.assert(cred_set, 'Either password, key
|
|
176
|
+
Aspera.assert(cred_set, 'Either password, key, or transfer spec token must be provided', type: Cli::BadArgument)
|
|
166
177
|
return server_transfer_spec
|
|
167
178
|
end
|
|
168
179
|
|
|
@@ -172,30 +183,31 @@ module Aspera
|
|
|
172
183
|
|
|
173
184
|
# --- DSL ---
|
|
174
185
|
|
|
175
|
-
option :ssh_keys, description: 'SSH key path list', allowed: Type::STRING_ARRAY
|
|
186
|
+
option :ssh_keys, description: 'SSH key path list', allowed: Cli::Option::Type::STRING_ARRAY
|
|
176
187
|
option :passphrase, description: 'SSH private key passphrase'
|
|
177
|
-
option :ssh_options, description: 'SSH options',
|
|
188
|
+
option :ssh_options, description: 'SSH options', schema: SSH_OPTIONS
|
|
178
189
|
|
|
179
190
|
command :health, description: 'Check transfer health'
|
|
180
191
|
command(:upload, description: 'Upload files to server', transfer_paths: :send, action: lambda do |**|
|
|
181
|
-
server_transfer_spec['direction'] = Transfer::Spec.transfer_type_to_direction(:upload)
|
|
182
|
-
|
|
192
|
+
server_transfer_spec['direction'] = Aspera::Transfer::Spec.transfer_type_to_direction(:upload)
|
|
193
|
+
Xfer::TransferAgent.result_transfer(transfer.start(server_transfer_spec))
|
|
183
194
|
end)
|
|
184
195
|
command(
|
|
185
196
|
:download,
|
|
186
197
|
description: 'Download files from server',
|
|
187
198
|
transfer_paths: :receive,
|
|
188
199
|
action: lambda do |**|
|
|
189
|
-
server_transfer_spec['direction'] = Transfer::Spec.transfer_type_to_direction(:download)
|
|
190
|
-
|
|
200
|
+
server_transfer_spec['direction'] = Aspera::Transfer::Spec.transfer_type_to_direction(:download)
|
|
201
|
+
Xfer::TransferAgent.result_transfer(transfer.start(server_transfer_spec))
|
|
191
202
|
end
|
|
192
203
|
)
|
|
193
204
|
command :sync, description: 'Synchronize files with server'
|
|
194
205
|
commands_under :sync do
|
|
195
206
|
Sync::Operations::DIRECTIONS.each do |dir|
|
|
196
|
-
command dir, description: "#{dir.capitalize}-sync with server", transfer_paths: :send, arguments: SyncActions::PATH_AND_INFO_ARGS
|
|
207
|
+
command dir, description: "#{dir.capitalize}-sync with server", transfer_paths: :send, arguments: Aspera::Plugins::Xfer::SyncActions::PATH_AND_INFO_ARGS
|
|
197
208
|
end
|
|
198
209
|
sync_admin_commands :admin
|
|
210
|
+
sync_logs_command :logs
|
|
199
211
|
end
|
|
200
212
|
|
|
201
213
|
commands_under :health do
|
|
@@ -206,7 +218,7 @@ module Aspera
|
|
|
206
218
|
ascp_logs_commands(:logs, arguments: [{name: :paths, description: 'Log files on the server (gzip supported)', multiple: true}])
|
|
207
219
|
|
|
208
220
|
# AsCmd operations (available only when SSH/local - not WSS)
|
|
209
|
-
# Arguments
|
|
221
|
+
# Arguments: paths, one command of `ascmd` per path (`mv`, `cp`: per source and destination pair)
|
|
210
222
|
PATHS_ARGS = [{name: :paths, multiple: true}].freeze
|
|
211
223
|
private_constant :PATHS_ARGS
|
|
212
224
|
|
|
@@ -214,7 +226,7 @@ module Aspera
|
|
|
214
226
|
:ls, description: 'List files', condition: :ascmd_available?, aliases: [:browse], arguments: PATHS_ARGS,
|
|
215
227
|
action: lambda do |paths:, **|
|
|
216
228
|
execute_ascmd(:ls, paths) do |result|
|
|
217
|
-
Result::ObjectList.new(result.map(&:stringify_keys), fields: %w[zmode zuid zgid size mtime name])
|
|
229
|
+
Cli::Result::ObjectList.new(result.map(&:stringify_keys), fields: %w[zmode zuid zgid size mtime name])
|
|
218
230
|
end
|
|
219
231
|
end
|
|
220
232
|
)
|
|
@@ -226,31 +238,32 @@ module Aspera
|
|
|
226
238
|
:df, read_only: true, description: 'Show disk usage', condition: :ascmd_available?,
|
|
227
239
|
action: lambda do |**|
|
|
228
240
|
execute_ascmd(:df, []) do |result|
|
|
229
|
-
Result::ObjectList.new(result.map(&:stringify_keys))
|
|
241
|
+
Cli::Result::ObjectList.new(result.map(&:stringify_keys))
|
|
230
242
|
end
|
|
231
243
|
end
|
|
232
244
|
)
|
|
233
245
|
command :du, read_only: true, description: 'Show file sizes', condition: :ascmd_available?, arguments: PATHS_ARGS
|
|
234
246
|
command :md5sum, read_only: true, description: 'Compute MD5 checksums', condition: :ascmd_available?, arguments: PATHS_ARGS
|
|
235
247
|
command :info, description: 'Show server system information', condition: :ascmd_available?,
|
|
236
|
-
action: ->(**) { execute_ascmd(:info, []) { |r| Result::SingleObject.new(r.stringify_keys) } }
|
|
248
|
+
action: ->(**) { execute_ascmd(:info, []) { |r| Cli::Result::SingleObject.new(r.stringify_keys) } }
|
|
237
249
|
|
|
238
250
|
# Generate ascmd handlers - convention: action_<op>
|
|
239
251
|
%i[rm mkdir].each do |op|
|
|
240
252
|
define_action_method([op]) do |paths:, **|
|
|
241
|
-
execute_ascmd(op, paths) { Result::Success.new }
|
|
253
|
+
execute_ascmd(op, paths) { Cli::Result::Success.new }
|
|
242
254
|
end
|
|
243
255
|
end
|
|
244
256
|
|
|
245
257
|
%i[mv cp].each do |op|
|
|
246
258
|
define_action_method([op]) do |paths:, **|
|
|
247
|
-
execute_ascmd(op, source_destination_pairs(paths)) { Result::Success.new }
|
|
259
|
+
execute_ascmd(op, source_destination_pairs(paths)) { Cli::Result::Success.new }
|
|
248
260
|
end
|
|
249
261
|
end
|
|
250
262
|
|
|
263
|
+
# One row per path
|
|
251
264
|
%i[du md5sum].each do |op|
|
|
252
265
|
define_action_method([op]) do |paths:, **|
|
|
253
|
-
execute_ascmd(op, paths) { |r| Result::
|
|
266
|
+
execute_ascmd(op, paths) { |r| Cli::Result::ObjectList.new(r.map(&:stringify_keys)) }
|
|
254
267
|
end
|
|
255
268
|
end
|
|
256
269
|
|
|
@@ -296,12 +309,12 @@ module Aspera
|
|
|
296
309
|
'paths' => [{'source' => 'faux:///pingfile?1k', 'destination' => '.fasping'}]
|
|
297
310
|
})
|
|
298
311
|
statuses = transfer.start(probe_ts)
|
|
299
|
-
if statuses.is_a?(Transfer::Result::Success)
|
|
312
|
+
if statuses.is_a?(Aspera::Transfer::Result::Success)
|
|
300
313
|
nagios.add_ok('transfer', 'ok')
|
|
301
314
|
else
|
|
302
|
-
nagios.add_critical('transfer', statuses.is_a?(Transfer::Result::Error) ? statuses.exception.message : statuses.to_s)
|
|
315
|
+
nagios.add_critical('transfer', statuses.is_a?(Aspera::Transfer::Result::Error) ? statuses.exception.message : statuses.to_s)
|
|
303
316
|
end
|
|
304
|
-
Result::ObjectList.new(nagios.status_list)
|
|
317
|
+
Cli::Result::ObjectList.new(nagios.status_list)
|
|
305
318
|
end
|
|
306
319
|
|
|
307
320
|
# --- ascmd handlers ---
|
|
@@ -368,7 +381,10 @@ module Aspera
|
|
|
368
381
|
result = ascmd.execute_single(op, arguments)
|
|
369
382
|
yield(result)
|
|
370
383
|
rescue AsCmd::Error => e
|
|
371
|
-
|
|
384
|
+
# Same class, for the exit code of its category, with the arguments of each failed command
|
|
385
|
+
raise e.exception(e.extended_message)
|
|
386
|
+
rescue ParameterError => e
|
|
387
|
+
raise Cli::BadArgument, e.message
|
|
372
388
|
end
|
|
373
389
|
end
|
|
374
390
|
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
openapi: 3.1.0
|
|
2
|
+
info:
|
|
3
|
+
title: Options of bundle server
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
description: Schema definitions of the options of bundle `server`
|
|
6
|
+
license:
|
|
7
|
+
name: Apache-2.0
|
|
8
|
+
identifier: Apache-2.0
|
|
9
|
+
paths: {}
|
|
10
|
+
components:
|
|
11
|
+
schemas:
|
|
12
|
+
SshOptions:
|
|
13
|
+
type: object
|
|
14
|
+
description: >-
|
|
15
|
+
Options of the SSH client library `Net::SSH` (method `start`), for the commands executed over SSH (e.g. `browse`, `delete`).
|
|
16
|
+
Refer to https://net-ssh.github.io/net-ssh/Net/SSH.html#method-c-start
|
|
17
|
+
# Open: any option of `Net::SSH.start`, checked by the gem (the list depends on its version)
|
|
18
|
+
additionalProperties: true
|
|
19
|
+
properties:
|
|
20
|
+
use_agent:
|
|
21
|
+
type: boolean
|
|
22
|
+
description: Use the keys of a running `ssh-agent`.
|
|
23
|
+
default: false
|
|
24
|
+
passphrase:
|
|
25
|
+
type: string
|
|
26
|
+
description: Passphrase of the SSH private keys (also set by option `passphrase`).
|
|
27
|
+
verbose:
|
|
28
|
+
description: >-
|
|
29
|
+
Log level of `Net::SSH`: an `Integer`, from `0` (debug) to `4` (fatal).
|
|
30
|
+
Default: warnings.
|