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
|
@@ -4,17 +4,22 @@
|
|
|
4
4
|
# SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
|
|
6
6
|
require_relative '../../assert'
|
|
7
|
-
require_relative '
|
|
7
|
+
require_relative '../../units/timestamp'
|
|
8
|
+
require_relative '../../cli/plugins/basic_auth'
|
|
8
9
|
require_relative '../../nagios'
|
|
9
10
|
|
|
10
11
|
module Aspera
|
|
11
|
-
module
|
|
12
|
-
module
|
|
13
|
-
class
|
|
12
|
+
module Plugins
|
|
13
|
+
module Console
|
|
14
|
+
class Commands < Cli::Plugins::Base
|
|
15
|
+
include Cli::Plugins::BasicAuth
|
|
16
|
+
|
|
17
|
+
API_SCHEMA = 'console'
|
|
14
18
|
STANDARD_PATH = '/aspera/console'
|
|
15
|
-
|
|
19
|
+
# Period of transfers listed if neither `from` nor `to` is given
|
|
20
|
+
DEFAULT_PERIOD = {'from' => 'now-24h', 'to' => 'now'}.freeze
|
|
16
21
|
EXPR_RE = /\A(\S+) (\S+) (.*)\z/
|
|
17
|
-
private_constant :STANDARD_PATH, :
|
|
22
|
+
private_constant :STANDARD_PATH, :DEFAULT_PERIOD, :EXPR_RE
|
|
18
23
|
|
|
19
24
|
class << self
|
|
20
25
|
# @return [Hash,NilClass]
|
|
@@ -51,8 +56,10 @@ module Aspera
|
|
|
51
56
|
return
|
|
52
57
|
end
|
|
53
58
|
|
|
59
|
+
# @param time [Time] Point in time
|
|
60
|
+
# @return [String] Date and time in UTC, as expected by the API, e.g. `2013-02-28 12:00:00`
|
|
54
61
|
def time_to_string(time)
|
|
55
|
-
return time.strftime('%Y-%m-%d %H:%M:%S')
|
|
62
|
+
return time.getutc.strftime('%Y-%m-%d %H:%M:%S')
|
|
56
63
|
end
|
|
57
64
|
end
|
|
58
65
|
|
|
@@ -89,7 +96,7 @@ module Aspera
|
|
|
89
96
|
|
|
90
97
|
commands_under :endpoint do
|
|
91
98
|
command :list, description: operation_description(:list, 'endpoint'),
|
|
92
|
-
action: ->(**) { Result::ObjectList.new(api_console.read('endpoints')) }
|
|
99
|
+
action: ->(**) { Cli::Result::ObjectList.new(api_console.read('endpoints')) }
|
|
93
100
|
end
|
|
94
101
|
|
|
95
102
|
# Payload is not documented in the API: optional
|
|
@@ -108,30 +115,30 @@ module Aspera
|
|
|
108
115
|
ADMIN_UPDATES.each do |verb, arg|
|
|
109
116
|
define_action_method([:admin, verb]) do |**kwargs|
|
|
110
117
|
api_console.create(verb.to_s, kwargs.fetch(arg))
|
|
111
|
-
Result::Success.new
|
|
118
|
+
Cli::Result::Success.new
|
|
112
119
|
end
|
|
113
120
|
end
|
|
114
121
|
|
|
115
122
|
commands_under :ssh_key do
|
|
116
123
|
command :list, description: operation_description(:list, 'SSH key'),
|
|
117
|
-
action: ->(**) { Result::ObjectList.new(api_console.read('ssh_keys')) }
|
|
124
|
+
action: ->(**) { Cli::Result::ObjectList.new(api_console.read('ssh_keys')) }
|
|
118
125
|
end
|
|
119
126
|
|
|
120
127
|
commands_under %i[transfer current] do
|
|
121
128
|
command :list, description: 'List current transfers'
|
|
122
129
|
command :submit, description: 'Submit a simple transfer',
|
|
123
|
-
arguments: [{name: :transfer, type: Hash, schema: Schema::Registry.req_body(
|
|
124
|
-
action: ->(transfer:, **) { Result::SingleObject.new(api_console.create('transfers', transfer)) }
|
|
130
|
+
arguments: [{name: :transfer, type: Hash, schema: Schema::Registry.req_body(API_SCHEMA, 'transfers.post')}],
|
|
131
|
+
action: ->(transfer:, **) { Cli::Result::SingleObject.new(api_console.create('transfers', transfer)) }
|
|
125
132
|
command :show, description: 'Show a transfer',
|
|
126
133
|
arguments: [{name: :transfer_id, type: :identifier}],
|
|
127
|
-
action: ->(transfer_id:, **) { Result::SingleObject.new(api_console.read("transfers/#{transfer_id}")) }
|
|
134
|
+
action: ->(transfer_id:, **) { Cli::Result::SingleObject.new(api_console.read("transfers/#{transfer_id}")) }
|
|
128
135
|
command(
|
|
129
136
|
:files, description: 'List files in a transfer',
|
|
130
137
|
arguments: [{name: :transfer_id, type: :identifier}],
|
|
131
138
|
action: lambda do |transfer_id:, **|
|
|
132
139
|
query = query_read_delete(default: {})
|
|
133
140
|
query['limit'] ||= 100
|
|
134
|
-
Result::ObjectList.new(api_console.read("transfers/#{transfer_id}/files", query))
|
|
141
|
+
Cli::Result::ObjectList.new(api_console.read("transfers/#{transfer_id}/files", query))
|
|
135
142
|
end
|
|
136
143
|
)
|
|
137
144
|
command :start, description: 'Start a transfer',
|
|
@@ -144,18 +151,18 @@ module Aspera
|
|
|
144
151
|
arguments: [{name: :transfer_id, type: :identifier}]
|
|
145
152
|
command :rerun, description: 'Rerun a transfer',
|
|
146
153
|
arguments: [{name: :transfer_id, type: :identifier}],
|
|
147
|
-
action: ->(transfer_id:, **) { Result::SingleObject.new(api_console.create("transfers/#{transfer_id}/rerun", {})) }
|
|
154
|
+
action: ->(transfer_id:, **) { Cli::Result::SingleObject.new(api_console.create("transfers/#{transfer_id}/rerun", {})) }
|
|
148
155
|
command :change_rate, description: 'Change transfer rate',
|
|
149
156
|
arguments: [{name: :transfer_id, type: :identifier},
|
|
150
|
-
{name: :rate, type: Hash, schema: Schema::Registry.req_body(
|
|
157
|
+
{name: :rate, type: Hash, schema: Schema::Registry.req_body(API_SCHEMA, 'transfers/{id}/change_rate.put')}]
|
|
151
158
|
command :change_policy, description: 'Change transfer policy',
|
|
152
159
|
arguments: [{name: :transfer_id, type: :identifier},
|
|
153
|
-
{name: :policy, type: Hash, schema: Schema::Registry.req_body(
|
|
160
|
+
{name: :policy, type: Hash, schema: Schema::Registry.req_body(API_SCHEMA, 'transfers/{id}/change_policy.put')}]
|
|
154
161
|
end
|
|
155
162
|
|
|
156
163
|
commands_under %i[transfer queue] do
|
|
157
164
|
command :list, description: 'List transfers in queue, frontmost first',
|
|
158
|
-
action: ->(queue_id:, **) { Result::ObjectList.new(api_console.read("queues/#{queue_id}/items")) }
|
|
165
|
+
action: ->(queue_id:, **) { Cli::Result::ObjectList.new(api_console.read("queues/#{queue_id}/items")) }
|
|
159
166
|
command :move_forwards, description: 'Move transfer forwards in queue',
|
|
160
167
|
arguments: [{name: :transfer_id, type: :identifier}]
|
|
161
168
|
command :move_back, description: 'Move transfer backwards in queue',
|
|
@@ -165,7 +172,7 @@ module Aspera
|
|
|
165
172
|
# PUT queues/<queue_id>/items/<id>/<verb>
|
|
166
173
|
%i[move_forwards move_back].each do |verb|
|
|
167
174
|
define_action_method([:transfer, :queue, verb]) do |queue_id:, transfer_id:, **|
|
|
168
|
-
Result::SingleObject.new(api_console.update("queues/#{queue_id}/items/#{transfer_id}/#{verb}", {}))
|
|
175
|
+
Cli::Result::SingleObject.new(api_console.update("queues/#{queue_id}/items/#{transfer_id}/#{verb}", {}))
|
|
169
176
|
end
|
|
170
177
|
end
|
|
171
178
|
|
|
@@ -174,25 +181,25 @@ module Aspera
|
|
|
174
181
|
# All share the same REST pattern: PUT transfers/<id>/<verb>.
|
|
175
182
|
%i[start pause cancel resume].each do |verb|
|
|
176
183
|
define_action_method([:transfer, :current, verb]) do |transfer_id:, **|
|
|
177
|
-
Result::SingleObject.new(api_console.update("transfers/#{transfer_id}/#{verb}", {}))
|
|
184
|
+
Cli::Result::SingleObject.new(api_console.update("transfers/#{transfer_id}/#{verb}", {}))
|
|
178
185
|
end
|
|
179
186
|
end
|
|
180
187
|
|
|
181
188
|
# PUT transfers/<id>/<verb> with request body
|
|
182
189
|
{change_rate: :rate, change_policy: :policy}.each do |verb, arg|
|
|
183
190
|
define_action_method([:transfer, :current, verb]) do |transfer_id:, **kwargs|
|
|
184
|
-
Result::SingleObject.new(api_console.update("transfers/#{transfer_id}/#{verb}", kwargs.fetch(arg)))
|
|
191
|
+
Cli::Result::SingleObject.new(api_console.update("transfers/#{transfer_id}/#{verb}", kwargs.fetch(arg)))
|
|
185
192
|
end
|
|
186
193
|
end
|
|
187
194
|
|
|
188
195
|
commands_under %i[transfer smart] do
|
|
189
|
-
command :list, description: 'List smart transfers', action: ->(**) { Result::ObjectList.new(api_console.read('smart_transfers')) }
|
|
196
|
+
command :list, description: 'List smart transfers', action: ->(**) { Cli::Result::ObjectList.new(api_console.read('smart_transfers')) }
|
|
190
197
|
command :submit, description: 'Submit a smart transfer',
|
|
191
|
-
arguments: [{name: :smart_id, type: :identifier}, {name: :transfer, type: Hash, schema: Schema::Registry.req_body(
|
|
192
|
-
action: ->(smart_id:, transfer:, **) { Result::ObjectList.new(api_console.create("smart_transfers/#{smart_id}", transfer)) }
|
|
198
|
+
arguments: [{name: :smart_id, type: :identifier}, {name: :transfer, type: Hash, schema: Schema::Registry.req_body(API_SCHEMA, 'smart_transfers/{id}.post')}],
|
|
199
|
+
action: ->(smart_id:, transfer:, **) { Cli::Result::ObjectList.new(api_console.create("smart_transfers/#{smart_id}", transfer)) }
|
|
193
200
|
command :pause, description: 'Pause a smart transfer',
|
|
194
201
|
arguments: [{name: :smart_id, type: :identifier}],
|
|
195
|
-
action: ->(smart_id:, **) { Result::SingleObject.new(api_console.update("smart_transfers/#{smart_id}/pause", {})) }
|
|
202
|
+
action: ->(smart_id:, **) { Cli::Result::SingleObject.new(api_console.update("smart_transfers/#{smart_id}/pause", {})) }
|
|
196
203
|
end
|
|
197
204
|
|
|
198
205
|
# --- API ---
|
|
@@ -220,20 +227,21 @@ module Aspera
|
|
|
220
227
|
rescue StandardError => e
|
|
221
228
|
nagios.add_critical('console api', e.to_s)
|
|
222
229
|
end
|
|
223
|
-
Result::ObjectList.new(nagios.status_list)
|
|
230
|
+
Cli::Result::ObjectList.new(nagios.status_list)
|
|
224
231
|
end
|
|
225
232
|
|
|
226
233
|
# --- transfer current ---
|
|
227
234
|
|
|
228
235
|
def action_transfer_current_list(**)
|
|
229
236
|
query = query_read_delete(default: {})
|
|
230
|
-
if query['from'].nil? && query['to'].nil?
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
237
|
+
query.merge!(DEFAULT_PERIOD) if query['from'].nil? && query['to'].nil?
|
|
238
|
+
# Dates of the API are in UTC: also a date given without time zone
|
|
239
|
+
now = Time.now
|
|
240
|
+
DEFAULT_PERIOD.each_key do |name|
|
|
241
|
+
query[name] = self.class.time_to_string(Units::Timestamp.parse(query[name], now: now, utc: true)) if query[name].is_a?(String)
|
|
234
242
|
end
|
|
235
243
|
parse_extended_filter(query.delete('filter'), query) if query['filter']
|
|
236
|
-
Result::ObjectList.new(
|
|
244
|
+
Cli::Result::ObjectList.new(
|
|
237
245
|
api_console.read('transfers', query),
|
|
238
246
|
fields: %w[id contact name status]
|
|
239
247
|
)
|
|
@@ -244,10 +252,10 @@ module Aspera
|
|
|
244
252
|
private
|
|
245
253
|
|
|
246
254
|
def parse_extended_filter(filter, query)
|
|
247
|
-
Aspera.assert(filter.start_with?('(') && filter.end_with?(')'), type: BadArgument) { "Invalid filter syntax: #{filter}, shall be (field op val)and(field op val)..." }
|
|
255
|
+
Aspera.assert(filter.start_with?('(') && filter.end_with?(')'), type: Cli::BadArgument) { "Invalid filter syntax: #{filter}, shall be (field op val)and(field op val)..." }
|
|
248
256
|
filter[1..-2].split(')and(').each_with_index do |expr, i|
|
|
249
257
|
m = expr.match(EXPR_RE)
|
|
250
|
-
Aspera.assert(m, type: BadArgument) { "Invalid expression: #{expr}, shall be: <field> <op> <val>" }
|
|
258
|
+
Aspera.assert(m, type: Cli::BadArgument) { "Invalid expression: #{expr}, shall be: <field> <op> <val>" }
|
|
251
259
|
t = m.captures
|
|
252
260
|
i += 1
|
|
253
261
|
query["filter#{i}"] = t[0]
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
name: console
|
|
2
|
+
title: IBM Aspera Console
|
|
3
|
+
commands: true
|
|
4
|
+
schemas:
|
|
5
|
+
- key: console
|
|
6
|
+
file: schemas/IBM Aspera Console-enhanced.yaml
|
|
7
|
+
source:
|
|
8
|
+
url: https://raw.githubusercontent.com/laurent-martin/aspera-api-examples/refs/heads/main/openapi/IBM%20Aspera%20Console-enhanced.yaml
|
|
@@ -0,0 +1,114 @@
|
|
|
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 '../../transfer/spec'
|
|
9
|
+
require_relative '../../rest'
|
|
10
|
+
require_relative '../../oauth/client/factory'
|
|
11
|
+
require_relative '../../oauth/client/generic'
|
|
12
|
+
require_relative '../node/api'
|
|
13
|
+
require 'json'
|
|
14
|
+
require 'xmlsimple'
|
|
15
|
+
|
|
16
|
+
module Aspera
|
|
17
|
+
module Plugins
|
|
18
|
+
module Cos
|
|
19
|
+
# Cloud Object Storage Node API Client
|
|
20
|
+
class Api < Node::Api
|
|
21
|
+
IBM_CLOUD_TOKEN_URL = 'https://iam.cloud.ibm.com/identity'
|
|
22
|
+
TOKEN_FIELD = 'delegated_refresh_token'
|
|
23
|
+
FASP_INFO_KEYS = %w[ATSEndpoint AccessKey].freeze
|
|
24
|
+
SERVICE_CREDS_PARAMS = %w[apikey resource_instance_id endpoints].freeze
|
|
25
|
+
class << self
|
|
26
|
+
def parameters_from_svc_credentials(service_credentials, bucket_region)
|
|
27
|
+
# check necessary contents
|
|
28
|
+
Aspera.assert_type(service_credentials, Hash, type: ParameterError) { 'service_credentials' }
|
|
29
|
+
Log.dump(:service_credentials, service_credentials)
|
|
30
|
+
SERVICE_CREDS_PARAMS.each do |field|
|
|
31
|
+
Aspera.assert(service_credentials.key?(field), type: ParameterError) { "service_credentials must have a field: #{field}" }
|
|
32
|
+
end
|
|
33
|
+
# read endpoints from service provided in service credentials
|
|
34
|
+
endpoints = Aspera::Rest::Client.new(base_url: service_credentials['endpoints']).read('')
|
|
35
|
+
Log.dump(:endpoints, endpoints)
|
|
36
|
+
endpoint = endpoints.dig('service-endpoints', 'regional', bucket_region, 'public', bucket_region)
|
|
37
|
+
Aspera.assert(!endpoint.nil?, type: ParameterError) { "no such region: #{bucket_region}" }
|
|
38
|
+
return {
|
|
39
|
+
instance_id: service_credentials['resource_instance_id'],
|
|
40
|
+
api_key: service_credentials['apikey'],
|
|
41
|
+
endpoint: endpoint
|
|
42
|
+
}
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def initialize(instance_id:, api_key:, endpoint:, bucket:, auth_url: IBM_CLOUD_TOKEN_URL)
|
|
47
|
+
Aspera.assert_type(instance_id, String) { 'resource instance id (crn)' }
|
|
48
|
+
Aspera.assert_type(endpoint, String) { 'endpoint' }
|
|
49
|
+
endpoint = "https://#{endpoint}" unless endpoint.start_with?('http')
|
|
50
|
+
@auth_url = auth_url
|
|
51
|
+
@api_key = api_key
|
|
52
|
+
s3_api = Aspera::Rest::Client.new(
|
|
53
|
+
base_url: endpoint,
|
|
54
|
+
not_auth_codes: %w[401 403], # error codes when not authorized
|
|
55
|
+
headers: {'ibm-service-instance-id' => instance_id},
|
|
56
|
+
auth: {
|
|
57
|
+
type: :oauth2,
|
|
58
|
+
grant_method: :generic,
|
|
59
|
+
base_url: @auth_url,
|
|
60
|
+
grant_type: 'urn:ibm:params:oauth:grant-type:apikey',
|
|
61
|
+
response_type: 'cloud_iam',
|
|
62
|
+
apikey: @api_key
|
|
63
|
+
}
|
|
64
|
+
)
|
|
65
|
+
# read FASP connection information for bucket
|
|
66
|
+
xml_result_text = s3_api.call(
|
|
67
|
+
operation: 'GET',
|
|
68
|
+
subpath: bucket,
|
|
69
|
+
headers: {'Accept' => 'application/xml'},
|
|
70
|
+
query: {'faspConnectionInfo' => nil},
|
|
71
|
+
ret: :resp
|
|
72
|
+
).body
|
|
73
|
+
ats_info = XmlSimple.xml_in(xml_result_text, {'ForceArray' => false})
|
|
74
|
+
Log.dump(:ats_info, ats_info)
|
|
75
|
+
Aspera.assert_hash_all(ats_info, String, nil) { 'ats_info' }
|
|
76
|
+
Aspera.assert((FASP_INFO_KEYS - ats_info.keys).empty?, 'ats_info missing required keys')
|
|
77
|
+
Aspera.assert_hash_all(ats_info['AccessKey'], String, String) { 'ats_info' }
|
|
78
|
+
@storage_credentials = {
|
|
79
|
+
'type' => 'token',
|
|
80
|
+
'token' => {TOKEN_FIELD => nil}
|
|
81
|
+
}
|
|
82
|
+
super(
|
|
83
|
+
base_url: ats_info['ATSEndpoint'],
|
|
84
|
+
auth: {
|
|
85
|
+
type: :basic,
|
|
86
|
+
username: ats_info['AccessKey']['Id'],
|
|
87
|
+
password: ats_info['AccessKey']['Secret']
|
|
88
|
+
},
|
|
89
|
+
add_tspec: {'tags'=>{Aspera::Transfer::Spec::TAG_RESERVED=>{'node'=>{'storage_credentials'=>@storage_credentials}}}}
|
|
90
|
+
)
|
|
91
|
+
# update storage_credentials AND Rest params
|
|
92
|
+
generate_token
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# potentially call this if delegated token is expired
|
|
96
|
+
def generate_token
|
|
97
|
+
# OAuth API to get delegated token
|
|
98
|
+
delegated_oauth = OAuth::Factory.instance.create(
|
|
99
|
+
base_url: @auth_url,
|
|
100
|
+
grant_method: :generic,
|
|
101
|
+
token_field: TOKEN_FIELD,
|
|
102
|
+
grant_type: 'urn:ibm:params:oauth:grant-type:apikey',
|
|
103
|
+
response_type: 'delegated_refresh_token',
|
|
104
|
+
apikey: @api_key,
|
|
105
|
+
receiver_client_ids: 'aspera_ats'
|
|
106
|
+
)
|
|
107
|
+
# get delegated token to be placed in rest call header and in transfer tags
|
|
108
|
+
@storage_credentials['token'][TOKEN_FIELD] = delegated_oauth.token
|
|
109
|
+
headers['X-Aspera-Storage-Credentials'] = JSON.generate(@storage_credentials)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
@@ -3,36 +3,39 @@
|
|
|
3
3
|
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
4
|
# SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
|
|
6
|
-
require_relative 'base'
|
|
7
|
-
require_relative '
|
|
8
|
-
require_relative '../
|
|
9
|
-
require_relative '
|
|
6
|
+
require_relative '../../cli/plugins/base'
|
|
7
|
+
require_relative '../../cli/error'
|
|
8
|
+
require_relative '../node/commands'
|
|
9
|
+
require_relative 'api'
|
|
10
10
|
require_relative '../../assert'
|
|
11
11
|
|
|
12
12
|
module Aspera
|
|
13
|
-
module
|
|
14
|
-
module
|
|
15
|
-
class
|
|
13
|
+
module Plugins
|
|
14
|
+
module Cos
|
|
15
|
+
class Commands < Cli::Plugins::Base
|
|
16
16
|
application_name 'IBM Cloud Object Storage'
|
|
17
17
|
|
|
18
|
+
# Schema of option `service_credentials`, in the schemas of the bundle (manifest `schemas`)
|
|
19
|
+
SERVICE_CREDENTIALS = 'cos_opts:components.schemas.CosServiceCredentials'
|
|
20
|
+
|
|
18
21
|
command :node, description: 'Execute COS node commands',
|
|
19
|
-
mount: {plugin: Node, instance: :cos_node_plugin, only: Node::COMMANDS_COS}
|
|
22
|
+
mount: {plugin: Node::Commands, instance: :cos_node_plugin, only: Node::Commands::COMMANDS_COS}
|
|
20
23
|
|
|
21
24
|
option :bucket, description: 'Bucket name'
|
|
22
25
|
option :endpoint, description: 'Storage endpoint (URL)'
|
|
23
26
|
option :apikey, description: 'Storage API key'
|
|
24
27
|
option :crn, description: 'Resource instance id (CRN)'
|
|
25
|
-
option :service_credentials, description: 'IBM Cloud service credentials', allowed: [Hash, NilClass]
|
|
28
|
+
option :service_credentials, description: 'IBM Cloud service credentials', allowed: [Hash, NilClass], schema: SERVICE_CREDENTIALS
|
|
26
29
|
option :region, description: 'Storage region'
|
|
27
|
-
option :identity, description: "Authentication URL (#{Api::
|
|
30
|
+
option :identity, description: "Authentication URL (#{Api::IBM_CLOUD_TOKEN_URL})", default: Api::IBM_CLOUD_TOKEN_URL
|
|
28
31
|
|
|
29
|
-
use_options Node
|
|
32
|
+
use_options Node::Commands
|
|
30
33
|
|
|
31
34
|
# node - mount target: build the COS Node API and plugin from CLI options.
|
|
32
|
-
# @return [Node] Node plugin instance on the COS bucket
|
|
35
|
+
# @return [Node::Commands] Node plugin instance on the COS bucket
|
|
33
36
|
def cos_node_plugin(**)
|
|
34
37
|
# get service credentials, Hash, e.g. @json:@file:...
|
|
35
|
-
service_credentials = options.get_option(:service_credentials)
|
|
38
|
+
service_credentials = options.get_option(:service_credentials, complete: true)
|
|
36
39
|
cos_node_params = {
|
|
37
40
|
auth_url: options.get_option(:identity, mandatory: true),
|
|
38
41
|
bucket: options.get_option(:bucket, mandatory: true),
|
|
@@ -44,10 +47,10 @@ module Aspera
|
|
|
44
47
|
cos_node_params[:instance_id] = options.get_option(:crn, mandatory: true)
|
|
45
48
|
else
|
|
46
49
|
Aspera.assert(cos_node_params[:endpoint].nil?, 'endpoint not allowed when service credentials provided', type: Cli::BadArgument)
|
|
47
|
-
cos_node_params.merge!(Api
|
|
50
|
+
cos_node_params.merge!(Api.parameters_from_svc_credentials(service_credentials, options.get_option(:region, mandatory: true)))
|
|
48
51
|
end
|
|
49
|
-
api_node = Api
|
|
50
|
-
Node.new(context: context, api: api_node)
|
|
52
|
+
api_node = Api.new(**cos_node_params)
|
|
53
|
+
Node::Commands.new(context: context, api: api_node)
|
|
51
54
|
end
|
|
52
55
|
end
|
|
53
56
|
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
openapi: 3.1.0
|
|
2
|
+
info:
|
|
3
|
+
title: Options of bundle cos
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
description: Schema definitions of the options of bundle `cos`
|
|
6
|
+
license:
|
|
7
|
+
name: Apache-2.0
|
|
8
|
+
identifier: Apache-2.0
|
|
9
|
+
paths: {}
|
|
10
|
+
components:
|
|
11
|
+
schemas:
|
|
12
|
+
CosServiceCredentials:
|
|
13
|
+
type: object
|
|
14
|
+
description: Service credentials of IBM Cloud Object Storage, as saved from the IBM Cloud console (JSON).
|
|
15
|
+
# Open: the credentials saved from the IBM Cloud console have other fields, not used
|
|
16
|
+
additionalProperties: true
|
|
17
|
+
required:
|
|
18
|
+
- apikey
|
|
19
|
+
- resource_instance_id
|
|
20
|
+
- endpoints
|
|
21
|
+
properties:
|
|
22
|
+
apikey:
|
|
23
|
+
type: string
|
|
24
|
+
description: API key of the service.
|
|
25
|
+
resource_instance_id:
|
|
26
|
+
type: string
|
|
27
|
+
description: Identifier (CRN) of the instance of the service.
|
|
28
|
+
endpoints:
|
|
29
|
+
type: string
|
|
30
|
+
description: URL of the list of endpoints of the service, by region.
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../../agent/base'
|
|
7
|
+
require_relative '../../rest'
|
|
8
|
+
require_relative '../../environment'
|
|
9
|
+
require_relative '../../json_rpc/client'
|
|
10
|
+
require_relative '../../products/desktop'
|
|
11
|
+
require_relative '../../products'
|
|
12
|
+
require_relative '../../transfer/spec'
|
|
13
|
+
require 'securerandom'
|
|
14
|
+
|
|
15
|
+
module Aspera
|
|
16
|
+
module Plugins
|
|
17
|
+
module Desktop
|
|
18
|
+
# Client: Aspera for Desktop
|
|
19
|
+
class Agent < Aspera::Agent::Base
|
|
20
|
+
# try twice the main init url in sequence
|
|
21
|
+
START_URIS = ['aspera://', 'aspera://', 'aspera://'].freeze
|
|
22
|
+
# delay between each try to start the app
|
|
23
|
+
SLEEP_SEC_BETWEEN_RETRY = 5
|
|
24
|
+
private_constant :START_URIS, :SLEEP_SEC_BETWEEN_RETRY
|
|
25
|
+
|
|
26
|
+
class << self
|
|
27
|
+
# Uses the local Aspera for Desktop application, on the local host: refused at level `high` (see `Cli::Security`).
|
|
28
|
+
def required_security_level(_options) = :medium
|
|
29
|
+
|
|
30
|
+
# Re-query a previously started transfer from the Desktop JSON-RPC daemon.
|
|
31
|
+
# agent_params must contain 'application_id'; the JSON-RPC URL is auto-discovered.
|
|
32
|
+
# @return [Hash] normalized status hash
|
|
33
|
+
def transfer_status(transfer_id, agent_params)
|
|
34
|
+
app_id = agent_params['application_id']
|
|
35
|
+
client = Aspera::JsonRpc::Client.new(Aspera::Rest::Client.new(base_url: desktop_api_url))
|
|
36
|
+
raw = client.get_transfer(app_id: app_id, transfer_id: transfer_id)
|
|
37
|
+
normalize_status(raw['status'], bytes: raw['bytes_written'].to_i, error: raw['error_desc'])
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Normalize a raw status string into the standard async-transfer hash fields.
|
|
41
|
+
def normalize_status(raw_status, bytes: 0, error: nil)
|
|
42
|
+
result = {'bytes_transferred' => bytes}
|
|
43
|
+
case raw_status
|
|
44
|
+
when 'completed'
|
|
45
|
+
result['status'] = 'completed'
|
|
46
|
+
result['ended_at'] = Time.now.utc.iso8601
|
|
47
|
+
when 'failed'
|
|
48
|
+
result.merge!('status' => 'failed', 'ended_at' => Time.now.utc.iso8601, 'error' => error.to_s)
|
|
49
|
+
when 'cancelled'
|
|
50
|
+
result['status'] = 'cancelled'
|
|
51
|
+
result['ended_at'] = Time.now.utc.iso8601
|
|
52
|
+
else
|
|
53
|
+
result['status'] = 'running'
|
|
54
|
+
end
|
|
55
|
+
result
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Auto-discover the JSON-RPC URL from the Desktop log file (same logic as instance method).
|
|
59
|
+
def desktop_api_url
|
|
60
|
+
log_file = File.join(Aspera::Products.find(Aspera::Products::Desktop.locations).first[:log_root], Aspera::Products::Desktop::LOG_FILENAME)
|
|
61
|
+
url = 'http://127.0.0.1:33024'
|
|
62
|
+
File.open(log_file, 'r') do |file|
|
|
63
|
+
file.each_line do |line|
|
|
64
|
+
line = line.chomp
|
|
65
|
+
url = "http://#{Regexp.last_match(1)}" if line =~ /JSON-RPC server listening on (.*)/
|
|
66
|
+
end
|
|
67
|
+
end if File.exist?(log_file)
|
|
68
|
+
url
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def initialize(**base_options)
|
|
73
|
+
@application_id = SecureRandom.uuid
|
|
74
|
+
@transfer_id = nil
|
|
75
|
+
super
|
|
76
|
+
Aspera.assert(Environment.instance.graphical?, type: EnvironmentError) { 'Using client requires a graphical environment' }
|
|
77
|
+
method_index = 0
|
|
78
|
+
begin
|
|
79
|
+
# curl 'http://127.0.0.1:33024/' -X POST -H 'content-type: application/json' --data-raw '{"jsonrpc":"2.0","params":[],"id":999999,"method":"rpc.discover"}'
|
|
80
|
+
# https://playground.open-rpc.org/?schemaUrl=http://127.0.0.1:33024
|
|
81
|
+
@client_app_api = Aspera::JsonRpc::Client.new(Aspera::Rest::Client.new(base_url: aspera_client_api_url))
|
|
82
|
+
client_info = @client_app_api.get_info
|
|
83
|
+
Log.dump(:client_version, client_info)
|
|
84
|
+
Log.log.debug('Client was reached') if method_index > 0
|
|
85
|
+
rescue Errno::ECONNREFUSED => e
|
|
86
|
+
start_url = START_URIS[method_index]
|
|
87
|
+
method_index += 1
|
|
88
|
+
Aspera.assert(!start_url.nil?) { "Unable to start #{Aspera::Products::Desktop::APP_NAME} #{method_index} times" }
|
|
89
|
+
Log.log.warn { "#{Aspera::Products::Desktop::APP_NAME} is not started (#{e}). Trying to start it ##{method_index}..." }
|
|
90
|
+
Environment.instance.open_uri_graphical(start_url)
|
|
91
|
+
sleep(SLEEP_SEC_BETWEEN_RETRY)
|
|
92
|
+
retry
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Returns the application_id so callers can persist it in agent_params.
|
|
97
|
+
attr_reader :application_id
|
|
98
|
+
|
|
99
|
+
# @return [Hash] `application_id`: for `transfer_status`
|
|
100
|
+
def async_params
|
|
101
|
+
{'application_id' => @application_id}
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# :reek:UnusedParameters token_regenerator
|
|
105
|
+
def start_transfer(transfer_spec, token_regenerator: nil)
|
|
106
|
+
Aspera::Transfer::Spec.fix_transferd_resume_policy(transfer_spec)
|
|
107
|
+
@request_id = SecureRandom.uuid
|
|
108
|
+
# if there is a token, we ask the client app to use well known ssh private keys
|
|
109
|
+
# instead of asking password
|
|
110
|
+
transfer_spec['authentication'] = 'token' if transfer_spec.key?('token')
|
|
111
|
+
result = @client_app_api.start_transfer(app_id: @application_id, desktop_spec: {}, transfer_spec: transfer_spec)
|
|
112
|
+
@transfer_id = result['uuid']
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def wait_for_transfers_completion
|
|
116
|
+
started = false
|
|
117
|
+
pre_calc = false
|
|
118
|
+
begin
|
|
119
|
+
loop do
|
|
120
|
+
transfer = @client_app_api.get_transfer(app_id: @application_id, transfer_id: @transfer_id)
|
|
121
|
+
case transfer['status']
|
|
122
|
+
when 'initiating', 'queued'
|
|
123
|
+
notify_progress(:sessions_init, info: transfer['status'])
|
|
124
|
+
when 'running'
|
|
125
|
+
if !started
|
|
126
|
+
notify_progress(:session_start, session_id: @transfer_id)
|
|
127
|
+
started = true
|
|
128
|
+
end
|
|
129
|
+
if !pre_calc && (transfer['bytes_expected'] != 0)
|
|
130
|
+
notify_progress(:session_size, session_id: @transfer_id, info: transfer['bytes_expected'])
|
|
131
|
+
pre_calc = true
|
|
132
|
+
else
|
|
133
|
+
notify_progress(:transfer, session_id: @transfer_id, info: transfer['bytes_written'])
|
|
134
|
+
end
|
|
135
|
+
when 'completed'
|
|
136
|
+
notify_progress(:session_end, session_id: @transfer_id)
|
|
137
|
+
break
|
|
138
|
+
when 'failed'
|
|
139
|
+
notify_progress(:session_end, session_id: @transfer_id)
|
|
140
|
+
raise Aspera::Transfer::Error, transfer['error_desc']
|
|
141
|
+
when 'cancelled'
|
|
142
|
+
notify_progress(:session_end, session_id: @transfer_id)
|
|
143
|
+
raise Aspera::Transfer::Error, 'Transfer cancelled by user'
|
|
144
|
+
else
|
|
145
|
+
notify_progress(:session_end, session_id: @transfer_id)
|
|
146
|
+
raise Aspera::Transfer::Error, "unknown status: #{transfer['status']}: #{transfer['error_desc']}"
|
|
147
|
+
end
|
|
148
|
+
sleep(1)
|
|
149
|
+
end
|
|
150
|
+
rescue StandardError => e
|
|
151
|
+
return [e]
|
|
152
|
+
end
|
|
153
|
+
return [:success]
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
private
|
|
157
|
+
|
|
158
|
+
# Delegate to the class method (avoids duplication).
|
|
159
|
+
def aspera_client_api_url
|
|
160
|
+
self.class.desktop_api_url
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Component `DesktopAgentOptions` of `TransferAgentOptions` (see `Schema::Registry#add_variants`): parameters of the agent `desktop`
|
|
2
|
+
type: object
|
|
3
|
+
description: >-
|
|
4
|
+
Parameters for the IBM Aspera Desktop Client transfer agent.
|
|
5
|
+
The Desktop Client must be running locally. No additional options are required.
|
|
6
|
+
properties: {}
|