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
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
-
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
|
|
6
|
-
require_relative '../agent/factory'
|
|
7
|
-
require_relative '../schema/registry'
|
|
8
|
-
require_relative 'option_declarator'
|
|
9
|
-
require_relative '../transfer/result'
|
|
10
|
-
require_relative '../transfer/spec'
|
|
11
|
-
require_relative 'info'
|
|
12
|
-
require_relative 'async_transfer_store'
|
|
13
|
-
require_relative '../log'
|
|
14
|
-
require_relative '../assert'
|
|
15
|
-
require_relative '../secret/hider'
|
|
16
|
-
require_relative 'security'
|
|
17
|
-
require 'securerandom'
|
|
18
|
-
|
|
19
|
-
module Aspera
|
|
20
|
-
module Cli
|
|
21
|
-
# The Transfer agent is a common interface to start a transfer using
|
|
22
|
-
# one of the supported transfer agents.
|
|
23
|
-
# Provide CLI options to select one of the transfer agents (FASP/ascp client)
|
|
24
|
-
class TransferAgent
|
|
25
|
-
# `@args` special value for --sources : read file list from arguments
|
|
26
|
-
FILE_LIST_FROM_ARGS = '@args'
|
|
27
|
-
# `@ts` special value for --sources : read file list from transfer spec (--ts)
|
|
28
|
-
FILE_LIST_FROM_TRANSFER_SPEC = '@ts'
|
|
29
|
-
FILE_LIST_OPTIONS = [FILE_LIST_FROM_ARGS, FILE_LIST_FROM_TRANSFER_SPEC, 'Array'].freeze
|
|
30
|
-
DEFAULT_TRANSFER_NOTIFY_TEMPLATE = <<~END_OF_TEMPLATE
|
|
31
|
-
From: <%=from_name%> <<%=from_email%>>
|
|
32
|
-
To: <<%=to%>>
|
|
33
|
-
Subject: <%=subject%>
|
|
34
|
-
|
|
35
|
-
Transfer is: <%=status%>
|
|
36
|
-
|
|
37
|
-
<%=ts.to_yaml%>
|
|
38
|
-
END_OF_TEMPLATE
|
|
39
|
-
CP4I_REMOTE_HOST_LB = 'N/A'
|
|
40
|
-
# Transfer spec parameters overridden by option `ts`
|
|
41
|
-
TS_DEFAULTS = {
|
|
42
|
-
'create_dir' => true,
|
|
43
|
-
'resume_policy' => 'sparse_csum'
|
|
44
|
-
}.freeze
|
|
45
|
-
private_constant :FILE_LIST_FROM_TRANSFER_SPEC,
|
|
46
|
-
:FILE_LIST_OPTIONS,
|
|
47
|
-
:DEFAULT_TRANSFER_NOTIFY_TEMPLATE,
|
|
48
|
-
:TS_DEFAULTS
|
|
49
|
-
|
|
50
|
-
extend OptionDeclarator
|
|
51
|
-
|
|
52
|
-
option :ts, description: 'Override transfer spec values', schema: Schema::Registry::TRANSFER_SPEC, on_set: :user_transfer_spec=
|
|
53
|
-
option :to_folder, description: 'Destination folder for transferred files', complete: :destination_folder
|
|
54
|
-
option :sources, description: "How list of transferred files is provided (#{FILE_LIST_OPTIONS.join(',')})", default: FILE_LIST_FROM_ARGS
|
|
55
|
-
option :src_type, description: 'Type of file list', allowed: %i[list pair], default: :list
|
|
56
|
-
option :transfer, description: 'Transfer agent type, or agent parameters with optional agent key', allowed: [Hash, String], shorthand: 'agent', schema: Schema::Registry::TRANSFER_AGENT_OPTIONS
|
|
57
|
-
option :transfer_info, description: 'Parameters for transfer agent', deprecation: {last: '4.26.2', message: 'use --transfer instead'}, schema: Schema::Registry::TRANSFER_AGENT_OPTIONS
|
|
58
|
-
|
|
59
|
-
# @param context [Context] Application context
|
|
60
|
-
def initialize(context)
|
|
61
|
-
Aspera.assert_type(context, Context) { 'context' }
|
|
62
|
-
Aspera.assert_type(context.options, Parser) { 'context.options' }
|
|
63
|
-
@context = context
|
|
64
|
-
# Command line can override transfer spec
|
|
65
|
-
@user_transfer_spec = TS_DEFAULTS.dup
|
|
66
|
-
# the currently selected transfer agent
|
|
67
|
-
@agent = nil
|
|
68
|
-
# source/destination pair, like "paths" of transfer spec
|
|
69
|
-
@transfer_paths = nil
|
|
70
|
-
# HTTPGW URL provided by webapp
|
|
71
|
-
@httpgw_url_lambda = nil
|
|
72
|
-
# Instance variables used by `on_set` callbacks are set above
|
|
73
|
-
self.class.declare_options(@context.options, target: self)
|
|
74
|
-
@context.options.parse_options!
|
|
75
|
-
@notification_cb = nil
|
|
76
|
-
if !@context.options.get_option(:notify_to).nil?
|
|
77
|
-
@notification_cb = ->(transfer_spec, global_status) do
|
|
78
|
-
@context.mailer.send_email_template(email_template_default: DEFAULT_TRANSFER_NOTIFY_TEMPLATE, values: {
|
|
79
|
-
subject: "#{Info::CMD_NAME} transfer: #{global_status}",
|
|
80
|
-
status: global_status,
|
|
81
|
-
ts: transfer_spec
|
|
82
|
-
})
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
attr_reader :user_transfer_spec
|
|
88
|
-
|
|
89
|
-
# `on_set` callback of option `ts`: values override defaults
|
|
90
|
-
# @param value [Hash] transfer spec parameters
|
|
91
|
-
def user_transfer_spec=(value)
|
|
92
|
-
@user_transfer_spec = TS_DEFAULTS.merge(value)
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
# @return [Hash] agent type (key `agent`) and agent parameters, from options `transfer` and deprecated `transfer_info`
|
|
96
|
-
def transfer_options
|
|
97
|
-
@context.options.get_option(:transfer_info).deep_merge(@context.options.get_option(:transfer))
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
def agent_instance=(instance)
|
|
101
|
-
@agent = instance
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
# analyze options and create new agent if not already created or set
|
|
105
|
-
def agent_instance
|
|
106
|
-
return @agent unless @agent.nil?
|
|
107
|
-
# agent type: from composite option 'agent' key, default :direct
|
|
108
|
-
raw_type = transfer_options['agent'] || :direct
|
|
109
|
-
agent_type = Parser.get_from_list(raw_type.to_s, 'transfer agent', Agent::Factory::ALL.keys)
|
|
110
|
-
# set keys as symbols, strip internal keys not forwarded to the agent constructor
|
|
111
|
-
agent_options = transfer_options.except('agent', 'asynchronous').symbolize_keys
|
|
112
|
-
agent_options[:progress] = @context.progress_bar
|
|
113
|
-
agent_options[:config_dir] = @context.main_folder
|
|
114
|
-
# special cases
|
|
115
|
-
case agent_type
|
|
116
|
-
when :node
|
|
117
|
-
if !agent_options.key?(:url)
|
|
118
|
-
param_set_name = @context.presets.plugin_default_name(:node)
|
|
119
|
-
Aspera.assert(!param_set_name.nil?, type: Cli::BadArgument) { "No default node configured. Please specify #{Options.option_name_to_line(:transfer)}.url or #{Options.option_name_to_line(:transfer)}" }
|
|
120
|
-
agent_options.merge!(@context.presets.by_name(param_set_name).symbolize_keys)
|
|
121
|
-
end
|
|
122
|
-
when :direct
|
|
123
|
-
# By default, no native `ascp` progress bar
|
|
124
|
-
agent_options[:quiet] = true unless agent_options.key?(:quiet)
|
|
125
|
-
# Native `ascp` progress bar requested: no other progress bar, unless option `progress_bar` is set
|
|
126
|
-
agent_options[:progress] = nil if !agent_options[:quiet] && @context.options.option_def(:progress_bar).source.eql?(:default)
|
|
127
|
-
agent_options[:check_ignore_cb] = ->(host, port) { @context.http_config.ignore_cert?(host, port) }
|
|
128
|
-
# JRuby
|
|
129
|
-
agent_options[:trusted_certs] = @context.http_config.trusted_cert_locations unless agent_options.key?(:trusted_certs)
|
|
130
|
-
when :httpgw
|
|
131
|
-
unless agent_options.key?(:url) || @httpgw_url_lambda.nil?
|
|
132
|
-
Log.log.debug('retrieving HTTPGW URL from webapp')
|
|
133
|
-
agent_options[:url] = @httpgw_url_lambda.call
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
# get agent instance
|
|
137
|
-
self.agent_instance = Agent::Factory.instance.create(agent_type, agent_options)
|
|
138
|
-
Log.log.debug { "transfer agent is a #{@agent.class}" }
|
|
139
|
-
return @agent
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
# Get destination folder
|
|
143
|
-
# @param direction [String] `send`` or `receive``
|
|
144
|
-
# @return [String] Destination folder for transfers (with default based on direction)
|
|
145
|
-
def destination_folder(direction)
|
|
146
|
-
dest_folder = @context.options.get_option(:to_folder)
|
|
147
|
-
# do not expand path, if user wants to expand path: user @path:
|
|
148
|
-
return dest_folder unless dest_folder.nil?
|
|
149
|
-
dest_folder = @user_transfer_spec['destination_root']
|
|
150
|
-
return dest_folder unless dest_folder.nil?
|
|
151
|
-
# default: / on remote, . on local
|
|
152
|
-
case direction.to_s
|
|
153
|
-
when Transfer::Spec::DIRECTION_SEND then dest_folder = '/'
|
|
154
|
-
when Transfer::Spec::DIRECTION_RECEIVE then dest_folder = '.'
|
|
155
|
-
else Aspera.error_unexpected_value(direction)
|
|
156
|
-
end
|
|
157
|
-
return dest_folder
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
# @return [Array] list of source files
|
|
161
|
-
def source_list
|
|
162
|
-
return ts_source_paths.map do |i|
|
|
163
|
-
i['source']
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
# @param httpgw_url_proc [Proc]
|
|
168
|
-
def httpgw_url_cb=(httpgw_url_proc)
|
|
169
|
-
Aspera.assert_type(httpgw_url_proc, Proc) { 'httpgw_url_cb' }
|
|
170
|
-
@httpgw_url_lambda = httpgw_url_proc
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
# Transform the list of paths to a list of hash with source/dest
|
|
174
|
-
# @param file_list [Array<Hash>]
|
|
175
|
-
def list_to_paths(file_list)
|
|
176
|
-
source_type = @context.options.get_option(:src_type, mandatory: true)
|
|
177
|
-
@transfer_paths =
|
|
178
|
-
case source_type
|
|
179
|
-
when :list
|
|
180
|
-
# when providing a list, just specify source
|
|
181
|
-
file_list.map { |i| {'source' => i} }
|
|
182
|
-
when :pair
|
|
183
|
-
Aspera.assert(file_list.length.even?, type: Cli::BadArgument) { "When using pair, provide an even number of paths: #{file_list.length}" }
|
|
184
|
-
file_list.each_slice(2).map { |s, d| {'source' => s, 'destination' => d} }
|
|
185
|
-
else Aspera.error_unexpected_value(source_type)
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
# This is how the list of files to be transferred is specified
|
|
190
|
-
# get paths suitable for transfer spec from command line
|
|
191
|
-
# computation is done only once, cache is kept in @transfer_paths
|
|
192
|
-
# @param default [nil, Array<String>] If set, used as default file for --sources=@args
|
|
193
|
-
# @return [Array, nil] of Hash {source: (mandatory), destination: (optional)}
|
|
194
|
-
def ts_source_paths(default: nil)
|
|
195
|
-
# return cache if set
|
|
196
|
-
return @transfer_paths unless @transfer_paths.nil?
|
|
197
|
-
# start with lower priority : get paths from transfer spec on command line
|
|
198
|
-
@transfer_paths = @user_transfer_spec['paths'] if @user_transfer_spec.key?('paths')
|
|
199
|
-
# is there a source list option ?
|
|
200
|
-
sources = @context.options.get_option(:sources)
|
|
201
|
-
@transfer_paths =
|
|
202
|
-
case sources
|
|
203
|
-
when FILE_LIST_FROM_ARGS
|
|
204
|
-
Log.log.debug('getting file list as parameters')
|
|
205
|
-
Aspera.assert_type(default, Array, NilClass)
|
|
206
|
-
# get remaining arguments
|
|
207
|
-
list = @context.options.get_next_argument('source file list', multiple: true, default: default)
|
|
208
|
-
raise Cli::BadArgument, 'specify at least one file on command line or use ' \
|
|
209
|
-
"--sources=#{FILE_LIST_FROM_TRANSFER_SPEC} to use transfer spec" if !list.is_a?(Array) || list.empty?
|
|
210
|
-
list_to_paths(list)
|
|
211
|
-
when FILE_LIST_FROM_TRANSFER_SPEC
|
|
212
|
-
Log.log.debug('assume list provided in transfer spec')
|
|
213
|
-
special_case_direct_with_list =
|
|
214
|
-
(transfer_options['agent'] || :direct).to_sym.eql?(:direct) &&
|
|
215
|
-
Transfer::Parameters.ascp_args_file_list?(transfer_options['ascp_args'])
|
|
216
|
-
Aspera.assert(!@transfer_paths.nil? || special_case_direct_with_list, type: Cli::BadArgument) { 'transfer spec on command line must have sources' }
|
|
217
|
-
# can be nil
|
|
218
|
-
@transfer_paths
|
|
219
|
-
when Array
|
|
220
|
-
Log.log.debug('getting file list as extended value')
|
|
221
|
-
Aspera.assert_array_all(sources, String, type: Cli::BadArgument) { 'sources must be a Array of String' }
|
|
222
|
-
list_to_paths(sources)
|
|
223
|
-
else Aspera.error_unexpected_value(sources) { 'sources' }
|
|
224
|
-
end
|
|
225
|
-
Log.dump(:paths, @transfer_paths)
|
|
226
|
-
return @transfer_paths
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
# Start a transfer and wait for completion, plugins shall use this method
|
|
230
|
-
# @param transfer_spec [Hash] transfer specification
|
|
231
|
-
# @param oauth_api [Rest::Client, nil] API whose OAuth token renews the bearer token of the transfer, if rejected
|
|
232
|
-
def start(transfer_spec, oauth_api: nil)
|
|
233
|
-
# check parameters
|
|
234
|
-
Aspera.assert_type(transfer_spec, Hash) { 'transfer_spec' }
|
|
235
|
-
raise "Wrong remote host: #{CP4I_REMOTE_HOST_LB}" if transfer_spec['remote_host'].eql?(CP4I_REMOTE_HOST_LB)
|
|
236
|
-
# process :src option
|
|
237
|
-
case transfer_spec['direction']
|
|
238
|
-
when Transfer::Spec::DIRECTION_RECEIVE
|
|
239
|
-
# init default if required in any case
|
|
240
|
-
@user_transfer_spec['destination_root'] ||= destination_folder(transfer_spec['direction'])
|
|
241
|
-
when Transfer::Spec::DIRECTION_SEND
|
|
242
|
-
if transfer_spec.dig('tags', Transfer::Spec::TAG_RESERVED, 'node', 'access_key')
|
|
243
|
-
# gen4
|
|
244
|
-
@user_transfer_spec.delete('destination_root') if @user_transfer_spec.key?('destination_root_id')
|
|
245
|
-
elsif transfer_spec.key?('token')
|
|
246
|
-
# gen3
|
|
247
|
-
# in that case, destination is set in return by application (API/upload_setup)
|
|
248
|
-
# but to_folder was used in initial API call
|
|
249
|
-
@user_transfer_spec.delete('destination_root')
|
|
250
|
-
else
|
|
251
|
-
# init default if required
|
|
252
|
-
@user_transfer_spec['destination_root'] ||= destination_folder(transfer_spec['direction'])
|
|
253
|
-
end
|
|
254
|
-
end
|
|
255
|
-
# update command line paths, unless destination already has one
|
|
256
|
-
@user_transfer_spec['paths'] = transfer_spec['paths'] || ts_source_paths
|
|
257
|
-
# updated transfer spec with command line
|
|
258
|
-
transfer_spec.deep_merge!(@user_transfer_spec)
|
|
259
|
-
# Files are written where the client chooses, see Security: only for an agent that writes on the local system
|
|
260
|
-
receives_locally = transfer_spec['direction'].eql?(Transfer::Spec::DIRECTION_RECEIVE) && agent_instance.local_destination?
|
|
261
|
-
transfer_spec['destination_root'] = Security.instance.writable_path(transfer_spec['destination_root']) if receives_locally && transfer_spec['destination_root']
|
|
262
|
-
# resolve pseudo-parameter: target_rate -> target_rate_kbps (overrides target_rate_kbps if both are present)
|
|
263
|
-
Transfer::Spec.resolve_target_rate(transfer_spec)
|
|
264
|
-
# recursively remove values that are nil (user wants to delete)
|
|
265
|
-
transfer_spec.deep_do { |hash, key, value, _unused| hash.delete(key) if value.nil? }
|
|
266
|
-
# if TS from app has content_protection (e.g. F5), that means content is protected: ask password if not provided
|
|
267
|
-
transfer_spec['content_protection_password'] = @context.options.prompt_user_input('content protection password', sensitive: true) if transfer_spec['content_protection'].eql?('decrypt') && !transfer_spec.key?('content_protection_password')
|
|
268
|
-
# Secrets of transfer spec (e.g. `token` from the application) are hidden wherever they appear (logs, results)
|
|
269
|
-
Secret::Hider.instance.add_secrets_in(transfer_spec)
|
|
270
|
-
# Option `dry_run`: no transfer, the final transfer spec is the result
|
|
271
|
-
return Transfer::Result.dry_run(transfer_spec) if dry_run?
|
|
272
|
-
# Renews the bearer token of the transfer: only possible with OAuth
|
|
273
|
-
token_regenerator = -> { oauth_api.oauth.renewed_authorization } if oauth_api&.auth_params&.fetch(:type, nil).eql?(:oauth2)
|
|
274
|
-
# create transfer agent
|
|
275
|
-
agent_instance.start_transfer(transfer_spec, token_regenerator: token_regenerator)
|
|
276
|
-
# --- async mode ---
|
|
277
|
-
if transfer_options['asynchronous']
|
|
278
|
-
agent_type = (transfer_options['agent'] || 'direct').to_s
|
|
279
|
-
# In-process agents (direct, httpgw) expose last_job_id directly.
|
|
280
|
-
# Remote-daemon agents do not override last_job_id (returns nil): generate a UUID.
|
|
281
|
-
job_id = agent_instance.last_job_id || SecureRandom.uuid
|
|
282
|
-
# Base agent_params from transfer options (strip internal keys)
|
|
283
|
-
agent_params = transfer_options.except('agent', 'asynchronous')
|
|
284
|
-
# For daemon agents: capture any runtime-resolved connection detail
|
|
285
|
-
case agent_type
|
|
286
|
-
when 'desktop'
|
|
287
|
-
agent_params['application_id'] = agent_instance.application_id
|
|
288
|
-
when 'connect'
|
|
289
|
-
agent_params['app_id'] = agent_instance.app_id
|
|
290
|
-
when 'transferd'
|
|
291
|
-
agent_params['url'] = agent_instance.daemon_endpoint
|
|
292
|
-
end
|
|
293
|
-
# Register an in-process agent reference for direct/httpgw agents so that
|
|
294
|
-
# config transfer status can re-query them while the same process is alive
|
|
295
|
-
# (e.g. MCP server mode). The ref is stored in AsyncTransferStore's memory map,
|
|
296
|
-
# never on disk.
|
|
297
|
-
async_store.register_agent_ref(job_id, agent_instance) if %w[direct httpgw].include?(agent_type)
|
|
298
|
-
# transfer_id: in-process agents use job_id; transferd has a reader; other daemon agents keep @transfer_id
|
|
299
|
-
transfer_id =
|
|
300
|
-
case agent_type
|
|
301
|
-
when 'direct', 'httpgw' then job_id
|
|
302
|
-
when 'transferd' then agent_instance.transfer_id.to_s
|
|
303
|
-
else agent_instance.instance_variable_get(:@transfer_id).to_s
|
|
304
|
-
end
|
|
305
|
-
async_store.write(job_id, {
|
|
306
|
-
'job_id' => job_id,
|
|
307
|
-
'agent_type' => agent_type,
|
|
308
|
-
'transfer_id' => transfer_id,
|
|
309
|
-
'agent_params' => agent_params,
|
|
310
|
-
'status' => 'running',
|
|
311
|
-
'bytes_transferred' => 0,
|
|
312
|
-
'started_at' => Time.now.utc.iso8601,
|
|
313
|
-
'ended_at' => nil,
|
|
314
|
-
'error' => nil
|
|
315
|
-
})
|
|
316
|
-
Log.log.info { "Async transfer started: job_id=#{job_id}, agent=#{agent_type}" }
|
|
317
|
-
return Transfer::Result.async(job_id: job_id)
|
|
318
|
-
end
|
|
319
|
-
# --- synchronous mode (default) ---
|
|
320
|
-
result = agent_instance.wait_for_completion
|
|
321
|
-
@notification_cb&.call(transfer_spec, result)
|
|
322
|
-
return result
|
|
323
|
-
end
|
|
324
|
-
|
|
325
|
-
# @return [Boolean] `true` if option `dry_run` is set: transfers are not started (see `start`)
|
|
326
|
-
def dry_run?
|
|
327
|
-
@context.options.get_option(:dry_run)
|
|
328
|
-
end
|
|
329
|
-
|
|
330
|
-
# For a command that changes something before its transfer (e.g. creates a package), or that does not transfer with `start`:
|
|
331
|
-
# fail before any change with option `dry_run`
|
|
332
|
-
# @raise [Cli::BadArgument] if option `dry_run` is set
|
|
333
|
-
def assert_no_dry_run
|
|
334
|
-
Aspera.assert(!dry_run?, type: Cli::BadArgument) { 'Option dry_run is not supported by this command' }
|
|
335
|
-
end
|
|
336
|
-
|
|
337
|
-
# shut down if agent requires it
|
|
338
|
-
def shutdown
|
|
339
|
-
@agent.shutdown if @agent.respond_to?(:shutdown)
|
|
340
|
-
end
|
|
341
|
-
|
|
342
|
-
# Lazy accessor for the async transfer store (shared with TransferActions via context.transfer).
|
|
343
|
-
def async_store
|
|
344
|
-
@async_store ||= AsyncTransferStore.new(@context.persistency)
|
|
345
|
-
end
|
|
346
|
-
end
|
|
347
|
-
end
|
|
348
|
-
end
|
|
@@ -1,244 +0,0 @@
|
|
|
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
|
-
# Helper class to build command line from a parameter list (key-value hash)
|
|
13
|
-
# Constructor takes hash: `{ 'param1':'value1', ...}`
|
|
14
|
-
# `process_param` is called repeatedly with all known parameters
|
|
15
|
-
# `add_to_exec_spec` is called to get resulting param list and env var (also checks that all params were used)
|
|
16
|
-
class CommandLineBuilder
|
|
17
|
-
# Supported keys in JSON schema
|
|
18
|
-
PROPERTY_KEYS = [
|
|
19
|
-
'description', # [String] Description
|
|
20
|
-
'type', # [String,Array] Accepted type(s) for non-enum
|
|
21
|
-
'default', # [String] Default value if not specified
|
|
22
|
-
'enum', # [Array] Set with list of values for enum types accepted in transfer spec
|
|
23
|
-
'items', # [Array]
|
|
24
|
-
'properties', # [Array]
|
|
25
|
-
'required', # [Array]
|
|
26
|
-
'$comment', # [String]
|
|
27
|
-
'x-cli-envvar', # [String] Name of env var
|
|
28
|
-
'x-cli-option', # [String] Command line option (starts with "-")
|
|
29
|
-
'x-cli-false', # [String]. Option to use when switch value is false
|
|
30
|
-
'x-cli-short', # [String] Command line option (starts with "-")
|
|
31
|
-
'x-cli-switch', # [Boolean] `true` if option has no arg, else by default option has a value
|
|
32
|
-
'x-cli-special', # [Boolean] `true` if special handling (deferred)
|
|
33
|
-
'x-cli-convert', # [String,Hash] Method name for Convert object or Conversion for enum ts to arg
|
|
34
|
-
'x-cli-complete', # [String] Values proposed by shell completion: `file`, `folder` (see `Cli::Complete::KINDS`)
|
|
35
|
-
'x-agents', # [Array] Supported agents (for doc only), if not specified: all
|
|
36
|
-
'x-ts-name', # [Boolean,String] (async) true if same name in transfer spec, else real name in transfer spec, else ignored
|
|
37
|
-
'x-ts-convert', # [String] (async) Name of methods to convert value from transfer spec to `conf` API.
|
|
38
|
-
'x-unit', # [String] (async) Time unit of the integer value in `conf` (e.g. `ms`), command line option is a DURATION
|
|
39
|
-
'x-deprecation' # [String] Deprecation message for doc
|
|
40
|
-
].freeze
|
|
41
|
-
|
|
42
|
-
private_constant :PROPERTY_KEYS
|
|
43
|
-
|
|
44
|
-
class << self
|
|
45
|
-
# Called by provider of definition before constructor of this class so that schema has all mandatory fields
|
|
46
|
-
# @param name_sym [Symbol] name of the schema to read
|
|
47
|
-
# @param ascp [Boolean] `true` if `ascp` mode
|
|
48
|
-
# @return [Aspera::Schema::Reader] validated schema reader
|
|
49
|
-
def read_schema(name_sym, ascp: false)
|
|
50
|
-
validate_schema(Schema::Registry.instance.reader(name_sym), ascp: ascp)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# @param agent [Symbol] Transfer agent name
|
|
54
|
-
# @param properties [Hash] Transfer spec parameter information
|
|
55
|
-
# @return [Boolean] `true` if given agent supports that field
|
|
56
|
-
def supported_by_agent(agent, properties)
|
|
57
|
-
!properties.key?('x-agents') || properties['x-agents'].include?(agent.to_s)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# Documentation of the command line option of a property: `annotate` of `Schema::Documentation`
|
|
61
|
-
# @param node [Hash] Schema of the property
|
|
62
|
-
# @param formatter [FormatterInterface] Formatter of the documentation
|
|
63
|
-
# @return [Array<String>] Lines added to the description, empty if no option
|
|
64
|
-
def doc_lines(node, formatter)
|
|
65
|
-
envvar_prefix = ''
|
|
66
|
-
cli_option =
|
|
67
|
-
if node.key?('x-cli-envvar')
|
|
68
|
-
envvar_prefix = 'env:'
|
|
69
|
-
node['x-cli-envvar']
|
|
70
|
-
elsif node['x-cli-switch']
|
|
71
|
-
false_part = node.key?('x-cli-false') ? " / #{node['x-cli-false']}" : ''
|
|
72
|
-
"#{node['x-cli-option']}#{false_part}"
|
|
73
|
-
elsif node['x-cli-option']
|
|
74
|
-
arg_type = node.key?('enum') ? '{enum}' : "{#{[node['type']].flatten.join('|')}}"
|
|
75
|
-
conversion_tag = node.key?('x-cli-convert') ? 'conversion' : nil
|
|
76
|
-
sep = node['x-cli-option'].start_with?('--') ? '=' : ' '
|
|
77
|
-
"#{node['x-cli-option']}#{sep}#{"(#{conversion_tag})" if conversion_tag}#{arg_type}"
|
|
78
|
-
end
|
|
79
|
-
return [] unless cli_option
|
|
80
|
-
short = node.key?('x-cli-short') ? "(#{node['x-cli-short']})" : nil
|
|
81
|
-
["(#{'special:' if node['x-cli-special']}#{envvar_prefix}#{formatter.markdown_text("`#{cli_option}`")})#{short}"]
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
private
|
|
85
|
-
|
|
86
|
-
# `ascp`: mandatory type
|
|
87
|
-
DIRECT_PROPERTIES = %w[x-cli-option x-cli-envvar x-cli-special].freeze
|
|
88
|
-
|
|
89
|
-
# Fill default values for some fields in the schema
|
|
90
|
-
# @param schema [Schema::Reader] The JSON schema
|
|
91
|
-
# @param ascp [Boolean] `true` if `ascp`
|
|
92
|
-
# @return [Schema::Reader] The JSON schema
|
|
93
|
-
def validate_schema(schema, ascp: false)
|
|
94
|
-
Aspera.assert_type(schema, Schema::Reader) { 'schema' }
|
|
95
|
-
Aspera.assert(schema.current.key?('properties')) { "Schema must have 'properties': #{schema}" }
|
|
96
|
-
schema.each_property do |property_schema, name, _full_name|
|
|
97
|
-
node = property_schema.current
|
|
98
|
-
unsupported_keys = node.keys - PROPERTY_KEYS
|
|
99
|
-
Aspera.assert(unsupported_keys.empty?) { "Unsupported definition keys: #{unsupported_keys}" }
|
|
100
|
-
Aspera.assert(node.key?('type') || node.key?('enum')) { "Missing type for #{name} in #{schema.current.dig('description').current}" }
|
|
101
|
-
Aspera.assert(node['type'].eql?('boolean')) { "switch must be bool: #{name}" } if node['x-cli-switch'] && !node['x-cli-special']
|
|
102
|
-
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']
|
|
103
|
-
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'))
|
|
104
|
-
Aspera.assert(supported_by_agent(:direct, node)) { "#{name}: x-cli-option requires agent direct (or nil)" } if node['x-cli-option']
|
|
105
|
-
Aspera.assert(DIRECT_PROPERTIES.any? { |i| node.key?(i) }, name, type: :warn) if ascp && supported_by_agent(:direct, node)
|
|
106
|
-
node.freeze
|
|
107
|
-
end
|
|
108
|
-
schema
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
# @param object [Hash] object with parameters
|
|
113
|
-
# @param schema [Schema::Reader] JSON schema
|
|
114
|
-
# @param convert [Object] function to convert value
|
|
115
|
-
def initialize(object, schema, convert)
|
|
116
|
-
@object = object # keep reference so that it can be modified by caller before calling `process_params`
|
|
117
|
-
@schema = schema
|
|
118
|
-
@convert = convert
|
|
119
|
-
@result = ExecSpec.new
|
|
120
|
-
@processed_parameters = []
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
# Change required-ness of property in schema
|
|
124
|
-
def required(name, required)
|
|
125
|
-
if required
|
|
126
|
-
@schema['required'].push(name) unless @schema['required']&.include?(name)
|
|
127
|
-
else
|
|
128
|
-
@schema['required'].delete(name)
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
# Add processed parameters to env and args, warns about unused parameters
|
|
133
|
-
# @param exec_spec [ExecSpec]
|
|
134
|
-
def add_to_exec_spec(exec_spec)
|
|
135
|
-
Log.dump(:exec_spec, @result)
|
|
136
|
-
# warn about non translated arguments
|
|
137
|
-
@object.each_pair do |name, value|
|
|
138
|
-
Log.log.warn { "Unknown transfer spec parameter: #{name} = \"#{value}\"" } unless @processed_parameters.include?(name)
|
|
139
|
-
end
|
|
140
|
-
# set result
|
|
141
|
-
exec_spec.env.merge!(@result.env)
|
|
142
|
-
exec_spec.args.concat(@result.args)
|
|
143
|
-
return
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
# Add options directly to command line
|
|
147
|
-
def add_command_line_options(*options)
|
|
148
|
-
options = options.first if options.first.is_a?(Array) && options.length.eql?(1)
|
|
149
|
-
Aspera.assert_type(options, Array)
|
|
150
|
-
options.each { |o| @result.args.push(o.to_s) }
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
def process_params
|
|
154
|
-
@schema['properties'].each_key do |k|
|
|
155
|
-
process_param(k)
|
|
156
|
-
end
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
def read_param(name)
|
|
160
|
-
return process_param(name, read: true)
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
private
|
|
164
|
-
|
|
165
|
-
# Process a parameter from transfer specification and generate command line param or env var
|
|
166
|
-
# @param name [String] of parameter
|
|
167
|
-
# @param read [TrueClass,FalseClass] read and return value of parameter instead of normal processing (for special)
|
|
168
|
-
def process_param(name, read: false)
|
|
169
|
-
properties = @schema['properties'][name]
|
|
170
|
-
# should not happen
|
|
171
|
-
if properties.nil?
|
|
172
|
-
Log.log.warn { "Unknown parameter #{name}" }
|
|
173
|
-
return
|
|
174
|
-
end
|
|
175
|
-
# check mandatory parameter (nil is valid value), TODO: change exception ?
|
|
176
|
-
Aspera.assert(!(@schema['required']&.include?(name) && !properties['x-cli-special'] && !@object.key?(name)), type: Transfer::Error) { "Missing mandatory parameter: #{name}" }
|
|
177
|
-
parameter_value = @object[name]
|
|
178
|
-
# no default setting
|
|
179
|
-
# parameter_value=properties['default'] if parameter_value.nil? and properties.has_key?('default')
|
|
180
|
-
# Check parameter type
|
|
181
|
-
expected_classes =
|
|
182
|
-
[properties['type']].flatten.map do |type|
|
|
183
|
-
case type
|
|
184
|
-
when 'string' then [String]
|
|
185
|
-
when 'array' then [Array]
|
|
186
|
-
when 'object' then [Hash]
|
|
187
|
-
when 'integer' then [Integer]
|
|
188
|
-
when 'boolean' then [TrueClass, FalseClass]
|
|
189
|
-
else Aspera.error_unexpected_value(properties['type']) { "Property #{name}" }
|
|
190
|
-
end
|
|
191
|
-
end.flatten
|
|
192
|
-
# check that value is of expected type
|
|
193
|
-
raise Transfer::Error, "#{name} is #{parameter_value.class} (#{parameter_value}), shall be #{properties['type']}, " \
|
|
194
|
-
unless parameter_value.nil? || expected_classes.include?(parameter_value.class)
|
|
195
|
-
# special processing will be requested with type get_value
|
|
196
|
-
@processed_parameters.push(name) if !properties['x-cli-special'] || read
|
|
197
|
-
|
|
198
|
-
# process only non-nil values
|
|
199
|
-
return if parameter_value.nil?
|
|
200
|
-
|
|
201
|
-
# check that value is of an accepted type (string, integer, boolean)
|
|
202
|
-
Aspera.assert(!(properties.key?('enum') && !properties['enum'].include?(parameter_value))) { "Enum value #{parameter_value} is not allowed for #{name}" }
|
|
203
|
-
|
|
204
|
-
# convert some values if value on command line needs processing from value in structure
|
|
205
|
-
if (convert = properties['x-cli-convert'])
|
|
206
|
-
converted_value =
|
|
207
|
-
case convert
|
|
208
|
-
when Hash then convert[parameter_value]
|
|
209
|
-
when String then @convert.send(convert, parameter_value)
|
|
210
|
-
else Aspera.error_unexpected_value(convert) { "Conversion type for #{name} is Hash or String only." }
|
|
211
|
-
end
|
|
212
|
-
Aspera.assert(!converted_value.nil?) { "No conversion for: #{name}=#{parameter_value}" }
|
|
213
|
-
parameter_value = converted_value
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
return unless self.class.supported_by_agent(:direct, properties)
|
|
217
|
-
|
|
218
|
-
if read
|
|
219
|
-
# just get value (deferred)
|
|
220
|
-
return parameter_value
|
|
221
|
-
elsif properties['x-cli-special']
|
|
222
|
-
# process later
|
|
223
|
-
return
|
|
224
|
-
elsif properties.key?('x-cli-envvar')
|
|
225
|
-
# set in env var
|
|
226
|
-
@result.env[properties['x-cli-envvar']] = parameter_value
|
|
227
|
-
elsif properties['x-cli-switch']
|
|
228
|
-
case parameter_value
|
|
229
|
-
when true
|
|
230
|
-
add_command_line_options(properties['x-cli-option'])
|
|
231
|
-
when false
|
|
232
|
-
add_command_line_options(properties['x-cli-false']) if properties.key?('x-cli-false')
|
|
233
|
-
else Aspera.error_unexpected_value(parameter_value) { name }
|
|
234
|
-
end
|
|
235
|
-
else
|
|
236
|
-
# transform into command line option with value
|
|
237
|
-
# parameter_value=parameter_value.to_s if parameter_value.is_a?(Integer)
|
|
238
|
-
parameter_value = Array(parameter_value)
|
|
239
|
-
# if transfer_spec value is an array, applies option many times
|
|
240
|
-
parameter_value.each { |v| add_command_line_options(properties['x-cli-option'], v) }
|
|
241
|
-
end
|
|
242
|
-
end
|
|
243
|
-
end
|
|
244
|
-
end
|
|
@@ -1,35 +0,0 @@
|
|
|
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
|
-
# conversion class for transfer spec values to CLI values (ascp)
|
|
9
|
-
class CommandLineConverter
|
|
10
|
-
class << self
|
|
11
|
-
# special encoding methods used in YAML (key: convert)
|
|
12
|
-
def remove_hyphen(value); value.tr('-', ''); end
|
|
13
|
-
|
|
14
|
-
# special encoding methods used in YAML (key: convert)
|
|
15
|
-
def json64(value); Base64.strict_encode64(JSON.generate(value)); end
|
|
16
|
-
|
|
17
|
-
# special encoding methods used in YAML (key: convert)
|
|
18
|
-
def base64(value); Base64.strict_encode64(value); end
|
|
19
|
-
|
|
20
|
-
# transform yes/no to true/false
|
|
21
|
-
def yes_to_true(value)
|
|
22
|
-
case value
|
|
23
|
-
when 'yes' then return true
|
|
24
|
-
when 'no' then return false
|
|
25
|
-
else Aspera.error_unexpected_value(value) { 'only: yes or no: ' }
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# Kbps to bps
|
|
30
|
-
def kbps_to_bps(value)
|
|
31
|
-
1000 * value.to_i
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|