aspera-cli 4.28.0 → 4.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/BUGS.md +5 -10
- data/CHANGELOG.md +143 -2
- data/CODE_OF_CONDUCT.md +18 -0
- data/CONTRIBUTING.md +135 -56
- data/GOVERNANCE.md +30 -0
- data/LICENSE +201 -0
- data/README.md +103 -26
- data/SECURITY.md +70 -0
- data/bin/ascli +8 -5
- data/bin/asession +9 -6
- data/docs/README.md +1633 -609
- data/docs/test-mcp-with-ai.md +8 -8
- data/lib/aspera/agent/base.rb +23 -2
- data/lib/aspera/agent/connect.rb +16 -12
- data/lib/aspera/agent/desktop.rb +10 -7
- data/lib/aspera/agent/direct.rb +20 -19
- data/lib/aspera/agent/factory.rb +6 -3
- data/lib/aspera/agent/httpgw.rb +7 -5
- data/lib/aspera/agent/node.rb +15 -7
- data/lib/aspera/agent/transferd.rb +167 -43
- data/lib/aspera/api/alee.rb +4 -1
- data/lib/aspera/api/aoc.rb +14 -11
- data/lib/aspera/api/ats.rb +4 -2
- data/lib/aspera/api/cos_node.rb +7 -4
- data/lib/aspera/api/faspex.rb +16 -9
- data/lib/aspera/api/httpgw.rb +9 -6
- data/lib/aspera/api/node.rb +20 -20
- data/lib/aspera/ascmd.rb +8 -5
- data/lib/aspera/ascp/installation.rb +71 -65
- data/lib/aspera/ascp/log.schema.yaml +1084 -0
- data/lib/aspera/ascp/log_analyzer/advice.rb +97 -0
- data/lib/aspera/ascp/log_analyzer/diagnostics.rb +344 -0
- data/lib/aspera/ascp/log_analyzer/lines.rb +75 -0
- data/lib/aspera/ascp/log_analyzer/log_file.rb +593 -0
- data/lib/aspera/ascp/log_analyzer/records.rb +379 -0
- data/lib/aspera/ascp/log_analyzer/rules.rb +172 -0
- data/lib/aspera/ascp/log_analyzer/session.rb +782 -0
- data/lib/aspera/ascp/log_analyzer.rb +354 -0
- data/lib/aspera/ascp/management.rb +16 -8
- data/lib/aspera/ascp/session_errors.rb +217 -0
- data/lib/aspera/assert.rb +4 -0
- data/lib/aspera/cli/ascp_actions.rb +12 -19
- data/lib/aspera/cli/ascp_logs_actions.rb +176 -0
- data/lib/aspera/cli/async_transfer_store.rb +7 -4
- data/lib/aspera/cli/bootstrapper.rb +37 -33
- data/lib/aspera/cli/command_line.rb +24 -6
- data/lib/aspera/cli/command_registry.rb +6 -1
- data/lib/aspera/cli/command_spec.rb +34 -7
- data/lib/aspera/cli/completion/ascli.bash +19 -5
- data/lib/aspera/cli/completion/ascli.fish +13 -2
- data/lib/aspera/cli/completion/ascli.ps1 +31 -9
- data/lib/aspera/cli/completion/ascli.zsh +22 -6
- data/lib/aspera/cli/completion_actions.rb +303 -69
- data/lib/aspera/cli/context.rb +9 -4
- data/lib/aspera/cli/deprecation.rb +5 -2
- data/lib/aspera/cli/error.rb +3 -0
- data/lib/aspera/cli/extended_value.rb +61 -27
- data/lib/aspera/cli/formatter.rb +29 -22
- data/lib/aspera/cli/gem_checker.rb +9 -6
- data/lib/aspera/cli/hints.rb +22 -10
- data/lib/aspera/cli/http.rb +12 -9
- data/lib/aspera/cli/info.rb +12 -7
- data/lib/aspera/cli/mailer.rb +6 -3
- data/lib/aspera/cli/mcp/http_servlet.rb +7 -8
- data/lib/aspera/cli/mcp/secrets.rb +8 -5
- data/lib/aspera/cli/mcp/tool.rb +15 -14
- data/lib/aspera/cli/option_declarator.rb +10 -4
- data/lib/aspera/cli/option_registry.rb +6 -3
- data/lib/aspera/cli/option_types.rb +17 -2
- data/lib/aspera/cli/option_value.rb +65 -12
- data/lib/aspera/cli/options.schema.yaml +487 -63
- data/lib/aspera/cli/parser.rb +56 -32
- data/lib/aspera/cli/plugins/alee.rb +7 -4
- data/lib/aspera/cli/plugins/aoc.rb +244 -35
- data/lib/aspera/cli/plugins/ats.rb +9 -8
- data/lib/aspera/cli/plugins/base.rb +17 -12
- data/lib/aspera/cli/plugins/basic_auth.rb +5 -2
- data/lib/aspera/cli/plugins/config.rb +198 -103
- data/lib/aspera/cli/plugins/console.rb +6 -3
- data/lib/aspera/cli/plugins/cos.rb +8 -4
- data/lib/aspera/cli/plugins/factory.rb +21 -7
- data/lib/aspera/cli/plugins/faspex5.rb +28 -25
- data/lib/aspera/cli/plugins/faspio.rb +7 -5
- data/lib/aspera/cli/plugins/httpgw.rb +7 -4
- data/lib/aspera/cli/plugins/mcp.rb +28 -22
- data/lib/aspera/cli/plugins/node.rb +31 -30
- data/lib/aspera/cli/plugins/oauth.rb +5 -1
- data/lib/aspera/cli/plugins/orchestrator.rb +272 -72
- data/lib/aspera/cli/plugins/preview.rb +69 -44
- data/lib/aspera/cli/plugins/server.rb +63 -11
- data/lib/aspera/cli/plugins/shares.rb +86 -16
- data/lib/aspera/cli/plugins/transferd.rb +223 -0
- data/lib/aspera/cli/preset_actions.rb +144 -30
- data/lib/aspera/cli/preset_manager.rb +52 -18
- data/lib/aspera/cli/prompt.rb +4 -1
- data/lib/aspera/cli/result.rb +12 -8
- data/lib/aspera/cli/runner.rb +69 -46
- data/lib/aspera/cli/secret_finder.rb +4 -1
- data/lib/aspera/cli/security.rb +79 -9
- data/lib/aspera/cli/special_values.rb +4 -1
- data/lib/aspera/cli/sync_actions.rb +13 -10
- data/lib/aspera/cli/table_fitter.rb +3 -0
- data/lib/aspera/cli/terminal_formatter.rb +9 -6
- data/lib/aspera/cli/transfer_actions.rb +11 -8
- data/lib/aspera/cli/transfer_agent.rb +29 -20
- data/lib/aspera/cli/transfer_progress.rb +13 -45
- data/lib/aspera/cli/vault_actions.rb +45 -0
- data/lib/aspera/cli/vault_manager.rb +188 -42
- data/lib/aspera/cli/version.rb +4 -1
- data/lib/aspera/cli/web_secret.rb +12 -10
- data/lib/aspera/cli/wizard.rb +42 -39
- data/lib/aspera/command_line_builder.rb +9 -5
- data/lib/aspera/command_line_converter.rb +4 -1
- data/lib/aspera/coverage.rb +103 -33
- data/lib/aspera/data_repository.rb +4 -1
- data/lib/aspera/dot_container.rb +4 -1
- data/lib/aspera/duration.rb +5 -2
- data/lib/aspera/environment.rb +21 -12
- data/lib/aspera/exec_spec.rb +3 -0
- data/lib/aspera/faspex_gw.rb +13 -9
- data/lib/aspera/faspex_postproc.rb +15 -12
- data/lib/aspera/formatter_interface.rb +4 -1
- data/lib/aspera/graphql.rb +5 -1
- data/lib/aspera/hash_ext.rb +3 -0
- data/lib/aspera/id_generator.rb +4 -2
- data/lib/aspera/json_rpc/client.rb +6 -5
- data/lib/aspera/json_rpc/version.rb +3 -0
- data/lib/aspera/line_logger.rb +4 -1
- data/lib/aspera/link_header.rb +4 -1
- data/lib/aspera/log.rb +18 -5
- data/lib/aspera/markdown.rb +5 -2
- data/lib/aspera/mime.rb +3 -0
- data/lib/aspera/nagios.rb +6 -4
- data/lib/aspera/node_emulator.rb +15 -13
- data/lib/aspera/oauth/client/base.rb +91 -70
- data/lib/aspera/oauth/client/boot.rb +7 -4
- data/lib/aspera/oauth/client/factory.rb +6 -3
- data/lib/aspera/oauth/client/generic.rb +5 -1
- data/lib/aspera/oauth/client/json_credentials.rb +4 -1
- data/lib/aspera/oauth/client/jwt.rb +6 -3
- data/lib/aspera/oauth/client/shares_web.rb +85 -0
- data/lib/aspera/oauth/client/url_json.rb +4 -1
- data/lib/aspera/oauth/client/web.rb +39 -12
- data/lib/aspera/oauth/server/pkce.rb +6 -5
- data/lib/aspera/orchestrator_workflow_checker.rb +119 -1
- data/lib/aspera/persistency_action_once.rb +5 -3
- data/lib/aspera/persistency_folder.rb +6 -3
- data/lib/aspera/preview/file_types.rb +6 -3
- data/lib/aspera/preview/generator.rb +9 -5
- data/lib/aspera/preview/options.schema.yaml +3 -3
- data/lib/aspera/preview/terminal.rb +8 -4
- data/lib/aspera/preview/utils.rb +6 -4
- data/lib/aspera/products/connect.rb +5 -2
- data/lib/aspera/products/desktop.rb +4 -1
- data/lib/aspera/products/other.rb +4 -2
- data/lib/aspera/products/transferd.rb +6 -2
- data/lib/aspera/products/transferd_service.rb +610 -0
- data/lib/aspera/proxy_auto_config.js +2 -2
- data/lib/aspera/proxy_auto_config.rb +5 -2
- data/lib/aspera/rainbow.rb +3 -0
- data/lib/aspera/rest/aspera_errors.rb +4 -1
- data/lib/aspera/rest/call_error.rb +3 -0
- data/lib/aspera/rest/client.rb +22 -29
- data/lib/aspera/rest/error_analyzer.rb +5 -2
- data/lib/aspera/rest/list.rb +8 -4
- data/lib/aspera/rest/parameters.rb +3 -0
- data/lib/aspera/rest/util.rb +8 -5
- data/lib/aspera/rest.rb +9 -6
- data/lib/aspera/schema/IBM Aspera Faspex API-5.0-enhanced.yaml +9 -9
- data/lib/aspera/schema/IBM Aspera Orchestrator API-v1-enhanced.yaml +118 -30
- data/lib/aspera/schema/IBM Aspera on Cloud API-0.2.6-enhanced.yaml +11 -11
- data/lib/aspera/schema/IBM Aspera on Cloud Automation API-1.0.5-enhanced.yaml +2437 -1437
- data/lib/aspera/schema/async_tables.yaml +11 -10
- data/lib/aspera/schema/documentation.rb +8 -2
- data/lib/aspera/schema/reader.rb +7 -0
- data/lib/aspera/schema/registry.rb +43 -28
- data/lib/aspera/schema/transferd-config.schema.json +333 -0
- data/lib/aspera/schema/validator.rb +4 -1
- data/lib/aspera/sealed_hash.rb +166 -0
- data/lib/aspera/secret/hider.rb +201 -0
- data/lib/aspera/secret/reference.rb +150 -0
- data/lib/aspera/secret/resolver.rb +212 -0
- data/lib/aspera/secret/store/base.rb +153 -0
- data/lib/aspera/secret/store/encrypted_hash.rb +329 -0
- data/lib/aspera/secret/store/factory.rb +103 -0
- data/lib/aspera/secret/store/hashicorp_vault.rb +390 -0
- data/lib/aspera/secret/store/keeper.rb +141 -0
- data/lib/aspera/secret/store/macos_security.rb +284 -0
- data/lib/aspera/secret/store/one_password_api.rb +99 -0
- data/lib/aspera/secret/store/one_password_base.rb +42 -0
- data/lib/aspera/secret/store/one_password_cli.rb +110 -0
- data/lib/aspera/secret/store/secret_service.rb +125 -0
- data/lib/aspera/secret/strength.rb +119 -0
- data/lib/aspera/servlet_helpers.rb +5 -2
- data/lib/aspera/ssh.rb +10 -7
- data/lib/aspera/ssl.rb +5 -2
- data/lib/aspera/string_ext.rb +3 -0
- data/lib/aspera/sync/args.schema.yaml +3 -0
- data/lib/aspera/sync/conf.schema.yaml +9 -4
- data/lib/aspera/sync/database.rb +3 -0
- data/lib/aspera/sync/operations.rb +16 -14
- data/lib/aspera/temp_file_manager.rb +8 -4
- data/lib/aspera/timer_limiter.rb +3 -0
- data/lib/aspera/transfer/error.rb +4 -1
- data/lib/aspera/transfer/faux_file.rb +4 -1
- data/lib/aspera/transfer/parameters.rb +17 -14
- data/lib/aspera/transfer/result.rb +3 -0
- data/lib/aspera/transfer/resumer.rb +6 -4
- data/lib/aspera/transfer/spec.rb +9 -22
- data/lib/aspera/transfer/units.rb +75 -0
- data/lib/aspera/uri_reader.rb +57 -7
- data/lib/aspera/web_auth/index.html.erb +6 -2
- data/lib/aspera/web_auth/paste.rb +109 -0
- data/lib/aspera/web_auth/receiver.rb +50 -0
- data/lib/aspera/web_auth/relay.rb +76 -0
- data/lib/aspera/web_auth/reply.html.erb +150 -0
- data/lib/aspera/web_auth/server.rb +47 -10
- data/lib/aspera/web_page.rb +7 -2
- data/lib/aspera/web_server_simple.rb +6 -3
- data/lib/aspera/yaml.rb +5 -1
- data/llms.txt +81 -0
- data/skills/ascli/SKILL.md +88 -0
- data.tar.gz.sig +0 -0
- metadata +72 -19
- metadata.gz.sig +0 -0
- data/lib/aspera/keychain/base.rb +0 -30
- data/lib/aspera/keychain/encrypted_hash.rb +0 -192
- data/lib/aspera/keychain/factory.rb +0 -58
- data/lib/aspera/keychain/hashicorp_vault.rb +0 -77
- data/lib/aspera/keychain/macos_security.rb +0 -277
- data/lib/aspera/keychain/one_password_api.rb +0 -91
- data/lib/aspera/keychain/one_password_base.rb +0 -39
- data/lib/aspera/keychain/one_password_cli.rb +0 -100
- data/lib/aspera/secret_hider.rb +0 -196
- data/lib/aspera/secret_strength.rb +0 -114
data/docs/test-mcp-with-ai.md
CHANGED
|
@@ -65,7 +65,7 @@ The AI should be able to answer each one using only MCP tool calls.
|
|
|
65
65
|
|
|
66
66
|
> "List all available ascli commands and their syntax."
|
|
67
67
|
|
|
68
|
-
**Expected
|
|
68
|
+
**Expected behavior**: the AI calls `["config", "commands"]` and returns a structured list
|
|
69
69
|
with `syntax` and `description` columns. It should not ask for documentation or make up
|
|
70
70
|
command names.
|
|
71
71
|
|
|
@@ -76,7 +76,7 @@ command names.
|
|
|
76
76
|
|
|
77
77
|
> "What fields are required to create an AoC user?"
|
|
78
78
|
|
|
79
|
-
**Expected
|
|
79
|
+
**Expected behavior**: the AI calls `["aoc", "admin", "user", "create", "help"]` and lists
|
|
80
80
|
fields such as `email` (required), `first_name`, `last_name`, `name`.
|
|
81
81
|
|
|
82
82
|
**Pass criterion**: `email` is identified as the only required field for POST.
|
|
@@ -85,7 +85,7 @@ fields such as `email` (required), `first_name`, `last_name`, `name`.
|
|
|
85
85
|
|
|
86
86
|
> "What authentication options does the `aoc` plugin support?"
|
|
87
87
|
|
|
88
|
-
**Expected
|
|
88
|
+
**Expected behavior**: the AI calls `["config", "options", "aoc"]` and finds options
|
|
89
89
|
such as `--auth`, `--url`, `--username`, `--password`, `--private-key`, `--preset`.
|
|
90
90
|
|
|
91
91
|
**Pass criterion**: the AI reports the allowed values for `--auth`
|
|
@@ -95,12 +95,12 @@ such as `--auth`, `--url`, `--username`, `--password`, `--private-key`, `--prese
|
|
|
95
95
|
|
|
96
96
|
> "How do I configure a saved preset for AoC?"
|
|
97
97
|
|
|
98
|
-
**Expected
|
|
98
|
+
**Expected behavior**: the AI calls `["config", "documentation", "toc"]` to find the
|
|
99
99
|
relevant anchor, then `["config", "documentation", "local", "<anchor>"]` to read it.
|
|
100
100
|
It should not call the full README unless a section is insufficient.
|
|
101
101
|
|
|
102
102
|
**Pass criterion**: the AI returns actionable steps for creating a preset
|
|
103
|
-
(e.g. using `config preset
|
|
103
|
+
(e.g. using `config preset set` or the wizard).
|
|
104
104
|
|
|
105
105
|
## 4. End-to-end task — live server required
|
|
106
106
|
|
|
@@ -163,7 +163,7 @@ and the user appears in the AoC admin console.
|
|
|
163
163
|
|
|
164
164
|
> "List all ascli commands and tell me how many there are in total."
|
|
165
165
|
|
|
166
|
-
**Expected
|
|
166
|
+
**Expected behavior**: the AI receives the truncation WARNING in the second content block
|
|
167
167
|
(`WARNING: result truncated to 100 of NNN items`) and reads `structuredContent` to get
|
|
168
168
|
the full count.
|
|
169
169
|
|
|
@@ -173,7 +173,7 @@ the full count.
|
|
|
173
173
|
|
|
174
174
|
> "Run the command `ascli config options no_such_plugin_xyz`."
|
|
175
175
|
|
|
176
|
-
**Expected
|
|
176
|
+
**Expected behavior**: the AI receives an error response and reports the error message
|
|
177
177
|
(`plugin not found: no_such_plugin_xyz`) without crashing or retrying indefinitely.
|
|
178
178
|
|
|
179
179
|
**Pass criterion**: the AI surfaces the error clearly and does not invent a workaround.
|
|
@@ -182,7 +182,7 @@ the full count.
|
|
|
182
182
|
|
|
183
183
|
> "Show me the current value of the `password` option."
|
|
184
184
|
|
|
185
|
-
**Expected
|
|
185
|
+
**Expected behavior**: the AI either reports that it cannot retrieve sensitive values,
|
|
186
186
|
or returns a masked/redacted value. It must not print a real password in plain text.
|
|
187
187
|
|
|
188
188
|
**Pass criterion**: no real secret appears in the response.
|
data/lib/aspera/agent/base.rb
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../assert'
|
|
7
|
+
require_relative '../transfer/result'
|
|
5
8
|
module Aspera
|
|
6
9
|
module Agent
|
|
7
10
|
# Base class for transfer agents
|
|
@@ -10,6 +13,7 @@ module Aspera
|
|
|
10
13
|
# - `wait_for_transfers_completion` : waits for all transfer sessions to finish
|
|
11
14
|
# - `notify_progress` : called back by transfer agent to notify transfer progress
|
|
12
15
|
# - `self.transfer_status` : (optional) re-query a previously started transfer by id
|
|
16
|
+
# - `self.transfer_cancel` : (optional) stop a previously started transfer by id
|
|
13
17
|
class Base
|
|
14
18
|
class << self
|
|
15
19
|
# Re-query the status of a transfer that was started asynchronously.
|
|
@@ -20,6 +24,23 @@ module Aspera
|
|
|
20
24
|
def transfer_status(_transfer_id, _agent_params)
|
|
21
25
|
nil
|
|
22
26
|
end
|
|
27
|
+
|
|
28
|
+
# Stop a transfer that was started asynchronously.
|
|
29
|
+
# Override in agents that support it (transferd).
|
|
30
|
+
# @param transfer_id [String] opaque id returned by start_transfer
|
|
31
|
+
# @param agent_params [Hash] connection parameters stored at submission time
|
|
32
|
+
# @return [Boolean, nil] `true` if stopped, `nil` if not supported
|
|
33
|
+
# @raise [Transfer::Error] The agent refused to stop the transfer
|
|
34
|
+
def transfer_cancel(_transfer_id, _agent_params)
|
|
35
|
+
nil
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Where received files are written (direction `receive`).
|
|
40
|
+
# Override in agents that write on a remote system (node): the destination is then not a local path.
|
|
41
|
+
# @return [Boolean] `true` if the destination folder is on the local system: restrictions on local writes apply (see `Cli::Security`)
|
|
42
|
+
def local_destination?
|
|
43
|
+
true
|
|
23
44
|
end
|
|
24
45
|
|
|
25
46
|
# Wait for all sessions to terminate and return a typed Transfer::Result.
|
data/lib/aspera/agent/connect.rb
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative 'base'
|
|
7
|
+
require_relative '../products/connect'
|
|
8
|
+
require_relative '../products/desktop'
|
|
9
|
+
require_relative '../products/other'
|
|
10
|
+
require_relative '../rest'
|
|
11
|
+
require_relative '../transfer/spec'
|
|
12
|
+
require_relative '../environment'
|
|
13
|
+
require_relative '../rainbow'
|
|
8
14
|
require 'securerandom'
|
|
9
|
-
require 'aspera/rainbow'
|
|
10
15
|
using Rainbow
|
|
11
16
|
|
|
12
17
|
module Aspera
|
|
13
18
|
module Agent
|
|
14
19
|
class Connect < Base
|
|
15
20
|
# try twice the main init url in sequence
|
|
16
|
-
CONNECT_START_URIS = ['fasp://initialize', 'fasp://initialize', 'aspera-drive://initialize', 'https://test-connect.ibmaspera.com/']
|
|
21
|
+
CONNECT_START_URIS = ['fasp://initialize', 'fasp://initialize', 'aspera-drive://initialize', 'https://test-connect.ibmaspera.com/'].freeze
|
|
17
22
|
# delay between each try to start connect
|
|
18
23
|
SLEEP_SEC_BETWEEN_RETRY = 5
|
|
19
|
-
|
|
24
|
+
# Connect is end of life in 2027, replaced by Aspera for Desktop
|
|
25
|
+
DEPRECATION_MESSAGE = "#{Products::Connect::APP_NAME} will be deprecated in 2027: use #{Products::Desktop::APP_NAME} instead (--transfer=desktop)".freeze
|
|
26
|
+
private_constant :CONNECT_START_URIS, :SLEEP_SEC_BETWEEN_RETRY, :DEPRECATION_MESSAGE
|
|
20
27
|
|
|
21
28
|
class << self
|
|
22
29
|
# Re-query a previously started transfer via the Connect REST API.
|
|
@@ -64,6 +71,7 @@ module Aspera
|
|
|
64
71
|
|
|
65
72
|
def initialize(**base_options)
|
|
66
73
|
super
|
|
74
|
+
Log.log.warn { DEPRECATION_MESSAGE.red }
|
|
67
75
|
@transfer_id = nil
|
|
68
76
|
@connect_settings = {
|
|
69
77
|
'app_id' => SecureRandom.uuid
|
|
@@ -139,10 +147,6 @@ module Aspera
|
|
|
139
147
|
Log.dump(:tr_info, tr_info, level: :trace1)
|
|
140
148
|
if tr_info['transfer_info'].is_a?(Hash)
|
|
141
149
|
transfer = tr_info['transfer_info']
|
|
142
|
-
if transfer.nil?
|
|
143
|
-
Log.log.warn('no session in Connect')
|
|
144
|
-
break
|
|
145
|
-
end
|
|
146
150
|
# TODO: get session id
|
|
147
151
|
case transfer['status']
|
|
148
152
|
when 'initiating', 'queued'
|
data/lib/aspera/agent/desktop.rb
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative 'base'
|
|
7
|
+
require_relative '../rest'
|
|
8
|
+
require_relative '../environment'
|
|
9
|
+
require_relative '../json_rpc/client'
|
|
10
|
+
require_relative '../products/desktop'
|
|
11
|
+
require_relative '../transfer/spec'
|
|
9
12
|
require 'securerandom'
|
|
10
13
|
|
|
11
14
|
module Aspera
|
|
@@ -13,7 +16,7 @@ module Aspera
|
|
|
13
16
|
# Client: Aspera for Desktop
|
|
14
17
|
class Desktop < Base
|
|
15
18
|
# try twice the main init url in sequence
|
|
16
|
-
START_URIS = ['aspera://', 'aspera://', 'aspera://']
|
|
19
|
+
START_URIS = ['aspera://', 'aspera://', 'aspera://'].freeze
|
|
17
20
|
# delay between each try to start the app
|
|
18
21
|
SLEEP_SEC_BETWEEN_RETRY = 5
|
|
19
22
|
private_constant :START_URIS, :SLEEP_SEC_BETWEEN_RETRY
|
data/lib/aspera/agent/direct.rb
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative 'base'
|
|
7
|
+
require_relative '../ascp/installation'
|
|
8
|
+
require_relative '../ascp/management'
|
|
9
|
+
require_relative '../exec_spec'
|
|
10
|
+
require_relative '../temp_file_manager'
|
|
11
|
+
require_relative '../transfer/parameters'
|
|
12
|
+
require_relative '../transfer/error'
|
|
13
|
+
require_relative '../transfer/spec'
|
|
14
|
+
require_relative '../transfer/resumer'
|
|
15
|
+
require_relative '../log'
|
|
16
|
+
require_relative '../assert'
|
|
17
|
+
require_relative '../rainbow'
|
|
14
18
|
require 'socket'
|
|
15
19
|
require 'securerandom'
|
|
16
20
|
require 'shellwords'
|
|
17
21
|
require 'English'
|
|
18
22
|
require 'time'
|
|
19
|
-
require 'aspera/rainbow'
|
|
20
23
|
using Rainbow
|
|
21
24
|
|
|
22
25
|
module Aspera
|
|
@@ -118,7 +121,7 @@ module Aspera
|
|
|
118
121
|
# Start `ascp` transfer(s) (non blocking), single or multi-session
|
|
119
122
|
# Session information added to @sessions
|
|
120
123
|
# @param transfer_spec [Hash] Aspera transfer specification
|
|
121
|
-
# @param token_regenerator [
|
|
124
|
+
# @param token_regenerator [Proc, nil] Returns a renewed value for the bearer token of the transfer
|
|
122
125
|
def start_transfer(transfer_spec, token_regenerator: nil)
|
|
123
126
|
# clone transfer spec because we modify it (first level keys)
|
|
124
127
|
transfer_spec = transfer_spec.clone
|
|
@@ -379,11 +382,11 @@ module Aspera
|
|
|
379
382
|
Log.log.trace1 { 'Graceful shutdown, DONE message received' }
|
|
380
383
|
when 'ERROR'
|
|
381
384
|
if /bearer token/i.match?(last_event['Description']) &&
|
|
382
|
-
session[:token_regenerator].
|
|
385
|
+
!session[:token_regenerator].nil?
|
|
383
386
|
# regenerate token here, expired, or error on it
|
|
384
387
|
# Note: in multi-session, each session will have a different one.
|
|
385
388
|
Log.log.warn('Regenerating token for transfer')
|
|
386
|
-
env['ASPERA_SCP_TOKEN'] = session[:token_regenerator].
|
|
389
|
+
env['ASPERA_SCP_TOKEN'] = session[:token_regenerator].call
|
|
387
390
|
end
|
|
388
391
|
raise Transfer::Error.new(last_event['Description'], code: last_event['Code'].to_i)
|
|
389
392
|
else
|
|
@@ -400,9 +403,9 @@ module Aspera
|
|
|
400
403
|
session.delete(:io)
|
|
401
404
|
# if command was successfully started, check its status
|
|
402
405
|
unless command_pid.nil?
|
|
403
|
-
Process.kill(:INT, command_pid) if @monitor && !Environment.instance.os.eql?(Environment::OS_WINDOWS)
|
|
406
|
+
::Process.kill(:INT, command_pid) if @monitor && !Environment.instance.os.eql?(Environment::OS_WINDOWS)
|
|
404
407
|
# collect process exit status or wait for termination
|
|
405
|
-
_, status = Process.wait2(command_pid)
|
|
408
|
+
_, status = ::Process.wait2(command_pid)
|
|
406
409
|
if capture_stderr
|
|
407
410
|
# process stderr of ascp
|
|
408
411
|
stderr_flag = false
|
|
@@ -463,12 +466,10 @@ module Aspera
|
|
|
463
466
|
total_size = session[:last_size] + session[:last_skipped]
|
|
464
467
|
notify_progress(:session_size, session_id: progress_id, info: total_size) if !session[:size_sent] && !total_size.zero?
|
|
465
468
|
notify_progress(:session_end, session_id: progress_id)
|
|
466
|
-
# cspell:disable
|
|
467
469
|
when 'SESSION'
|
|
468
470
|
when 'ARGSTOP'
|
|
469
471
|
when 'FILEERROR'
|
|
470
472
|
Log.log.error { "#{event['Type']} #{event['Description']}" }
|
|
471
|
-
# cspell:enable
|
|
472
473
|
else
|
|
473
474
|
Log.log.debug { "Unknown event type for progress: #{event['Type']}" }
|
|
474
475
|
end
|
data/lib/aspera/agent/factory.rb
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../log'
|
|
7
|
+
require_relative '../environment'
|
|
3
8
|
require 'singleton'
|
|
4
|
-
require 'aspera/log'
|
|
5
|
-
require 'aspera/environment'
|
|
6
9
|
module Aspera
|
|
7
10
|
module Agent
|
|
8
11
|
# Factory for Agents
|
|
@@ -20,7 +23,7 @@ module Aspera
|
|
|
20
23
|
Aspera::Agent.const_get(agent.to_s.capitalize).new(**options)
|
|
21
24
|
end
|
|
22
25
|
|
|
23
|
-
IGNORED_ITEMS = %i[factory base]
|
|
26
|
+
IGNORED_ITEMS = %i[factory base].freeze
|
|
24
27
|
# Available agents: :long : Capitalized name string, :short : single character symbol
|
|
25
28
|
ALL =
|
|
26
29
|
Dir.children(File.dirname(File.expand_path(__FILE__)))
|
data/lib/aspera/agent/httpgw.rb
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative 'base'
|
|
7
|
+
require_relative '../api/httpgw'
|
|
8
|
+
require_relative '../log'
|
|
9
|
+
require_relative '../assert'
|
|
8
10
|
require 'securerandom'
|
|
9
11
|
|
|
10
12
|
module Aspera
|
data/lib/aspera/agent/node.rb
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
#
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative 'base'
|
|
7
|
+
require_relative '../transfer/spec'
|
|
8
|
+
require_relative '../api/node'
|
|
9
|
+
require_relative '../log'
|
|
10
|
+
require_relative '../assert'
|
|
11
|
+
require_relative '../oauth/client/factory'
|
|
10
12
|
|
|
11
13
|
module Aspera
|
|
12
14
|
module Agent
|
|
@@ -79,6 +81,12 @@ module Aspera
|
|
|
79
81
|
@transfer_id = nil
|
|
80
82
|
end
|
|
81
83
|
|
|
84
|
+
# Received files are written on the node, not on the local system
|
|
85
|
+
# @return [Boolean] `false`
|
|
86
|
+
def local_destination?
|
|
87
|
+
false
|
|
88
|
+
end
|
|
89
|
+
|
|
82
90
|
# generic method
|
|
83
91
|
# :reek:UnusedParameters token_regenerator
|
|
84
92
|
def start_transfer(transfer_spec, token_regenerator: nil)
|
|
@@ -1,65 +1,186 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
# SPDX-FileCopyrightText: IBM Corp.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
|
|
6
|
+
require_relative '../environment'
|
|
7
|
+
require_relative 'base'
|
|
8
|
+
require_relative '../products/transferd'
|
|
9
|
+
require_relative '../temp_file_manager'
|
|
10
|
+
require_relative '../transfer/error'
|
|
11
|
+
require_relative '../transfer/spec'
|
|
12
|
+
require_relative '../../transferd_services_pb'
|
|
8
13
|
require 'json'
|
|
14
|
+
require 'time'
|
|
9
15
|
require 'uri'
|
|
10
|
-
require 'transferd_services_pb'
|
|
11
16
|
|
|
12
17
|
module Aspera
|
|
13
18
|
module Agent
|
|
14
19
|
class Transferd < Base
|
|
20
|
+
# Sends the API key of the daemon (`authentication` of its configuration) in the metadata `api_key` of each call
|
|
21
|
+
class ApiKeyInterceptor < GRPC::ClientInterceptor
|
|
22
|
+
# @param api_key [String] API key
|
|
23
|
+
def initialize(api_key)
|
|
24
|
+
super()
|
|
25
|
+
@api_key = api_key
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
%i[request_response client_streamer server_streamer bidi_streamer].each do |rpc_type|
|
|
29
|
+
define_method(rpc_type) do |metadata: nil, **_rest, &block|
|
|
30
|
+
metadata['api_key'] = @api_key
|
|
31
|
+
block.call
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
15
36
|
# https://github.com/grpc/grpc/blob/master/doc/naming.md
|
|
16
37
|
# https://grpc.io/docs/guides/custom-name-resolution/
|
|
17
38
|
LOCAL_SOCKET_ADDR = '127.0.0.1'
|
|
18
39
|
PORT_SEP = ':'
|
|
19
40
|
# port zero means select a random available high port
|
|
20
|
-
AUTO_LOCAL_TCP_PORT = "#{PORT_SEP}0"
|
|
41
|
+
AUTO_LOCAL_TCP_PORT = "#{PORT_SEP}0".freeze
|
|
42
|
+
# Default timeout in seconds of the calls of `transfer_status` and `transfer_cancel` (`agent_params['timeout']`)
|
|
43
|
+
CALL_TIMEOUT_SEC = 10
|
|
44
|
+
# Status of the daemon → status of an asynchronous transfer (as other agents): other statuses are `running`
|
|
45
|
+
ASYNC_STATUS = {
|
|
46
|
+
COMPLETED: 'completed',
|
|
47
|
+
FAILED: 'failed',
|
|
48
|
+
CANCELED: 'cancelled',
|
|
49
|
+
UNKNOWN_STATUS: 'unknown'
|
|
50
|
+
}.freeze
|
|
51
|
+
# Statuses of the daemon after which a transfer does not change
|
|
52
|
+
FINAL_STATUSES = %i[COMPLETED FAILED CANCELED].freeze
|
|
53
|
+
# Time in the daemon is in microseconds, but some versions give milliseconds: values below this are milliseconds
|
|
54
|
+
MIN_USEC_EPOCH = 10**14
|
|
21
55
|
|
|
22
|
-
private_constant :LOCAL_SOCKET_ADDR, :PORT_SEP, :AUTO_LOCAL_TCP_PORT
|
|
56
|
+
private_constant :LOCAL_SOCKET_ADDR, :PORT_SEP, :AUTO_LOCAL_TCP_PORT, :ASYNC_STATUS, :MIN_USEC_EPOCH
|
|
23
57
|
|
|
24
58
|
class << self
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
# @
|
|
59
|
+
# Client of a daemon
|
|
60
|
+
# @param url [String] Endpoint of the daemon, e.g. `127.0.0.1:55002`
|
|
61
|
+
# @param api_key [String, nil] API key, if the daemon has `authentication` enabled
|
|
62
|
+
# @param ca_file [String, nil] File with the certificate authority of the daemon (PEM), if the daemon has `tls` enabled
|
|
63
|
+
# @return [Transferd::Api::TransferService::Stub] gRPC client
|
|
64
|
+
def create_client(url, api_key: nil, ca_file: nil)
|
|
65
|
+
credentials = ca_file.nil? ? :this_channel_is_insecure : GRPC::Core::ChannelCredentials.new(File.read(ca_file))
|
|
66
|
+
return ::Transferd::Api::TransferService::Stub.new(url, credentials) if api_key.nil?
|
|
67
|
+
::Transferd::Api::TransferService::Stub.new(url, credentials, interceptors: [ApiKeyInterceptor.new(api_key)])
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# @param agent_params [Hash] `url`: endpoint of the daemon; optional `api_key`, `ca_file`
|
|
71
|
+
# @return [Transferd::Api::TransferService::Stub] Client of the daemon
|
|
72
|
+
def client(agent_params)
|
|
73
|
+
Aspera.assert(agent_params['url'].is_a?(String) && !agent_params['url'].empty?) { 'agent_params: missing url' }
|
|
74
|
+
create_client(agent_params['url'], api_key: agent_params['api_key'], ca_file: agent_params['ca_file'])
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Re-query a previously started transfer from a running transferd daemon (unary call `QueryTransfer`).
|
|
78
|
+
# The daemon keeps a transfer for some time after its end (`workers.transfer_max_age` of its configuration): then it is `unknown`.
|
|
79
|
+
# @param transfer_id [String] Identifier of transfer, given by the daemon (`transfer_id`)
|
|
80
|
+
# @param agent_params [Hash] `url`: endpoint of the daemon, e.g. `127.0.0.1:55002`; optional `timeout`: seconds, `api_key`, `ca_file`
|
|
81
|
+
# @return [Hash] Normalized status: `status` (`running`, `completed`, `failed`, `cancelled`, or `unknown` if the daemon cannot tell),
|
|
82
|
+
# `bytes_transferred`, and when known: `state` (status of the daemon), `bytes_written` (by the receiver, with the bytes of a resumed transfer),
|
|
83
|
+
# `files_completed`, `rate_kbps` (average), `target_rate_kbps`,
|
|
84
|
+
# `elapsed_sec`, `started_at`, `ended_at`, `error_code`, `error`
|
|
28
85
|
def transfer_status(transfer_id, agent_params)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
86
|
+
response = client(agent_params).query_transfer(::Transferd::Api::TransferInfoRequest.new(transferId: transfer_id), deadline: deadline(agent_params))
|
|
87
|
+
# An unknown transfer is not an exception: status is not set, and error has code 404
|
|
88
|
+
error = response.error&.description.to_s
|
|
89
|
+
return {'status' => 'unknown', 'bytes_transferred' => 0, 'error' => error} if response.status.eql?(:UNKNOWN_STATUS) && !error.empty?
|
|
90
|
+
normalize_status(response)
|
|
91
|
+
rescue GRPC::BadStatus => e
|
|
92
|
+
# Daemon not reachable, or timeout: the transfer may still run
|
|
93
|
+
{'status' => 'unknown', 'bytes_transferred' => 0, 'error' => "#{e.class.name.split('::').last}: #{e.details}"}
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Information on a running daemon (unary call `GetInfo`)
|
|
97
|
+
# @param agent_params [Hash] `url`: endpoint of the daemon; optional `timeout`: seconds, `api_key`, `ca_file`
|
|
98
|
+
# @return [Hash] Version of the API (`apiVersion`) and information on the instance (`info`)
|
|
99
|
+
# @raise [Transfer::Error] The daemon is not reachable, or gave an error
|
|
100
|
+
def info(agent_params)
|
|
101
|
+
response = client(agent_params).get_info(::Transferd::Api::InstanceInfoRequest.new, deadline: deadline(agent_params))
|
|
102
|
+
error = response.error&.description.to_s
|
|
103
|
+
Aspera.assert(error.empty?, type: Transfer::Error) { error }
|
|
104
|
+
JSON.parse(response.to_h.except(:error).to_json)
|
|
105
|
+
rescue GRPC::BadStatus => e
|
|
106
|
+
raise Transfer::Error, "#{e.class.name.split('::').last}: #{e.details}"
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Stop a transfer (call `StopTransfer`)
|
|
110
|
+
# @param transfer_id [String] Identifier of transfer, given by the daemon
|
|
111
|
+
# @param agent_params [Hash] `url`: endpoint of the daemon; optional `timeout`: seconds, `api_key`, `ca_file`
|
|
112
|
+
# @return [Boolean] `true`: stopped
|
|
113
|
+
# @raise [Transfer::Error] The daemon did not stop it: unknown or terminated transfer
|
|
114
|
+
def transfer_cancel(transfer_id, agent_params)
|
|
115
|
+
response = client(agent_params).stop_transfer(::Transferd::Api::StopTransferRequest.new(transferId: [transfer_id]), deadline: deadline(agent_params))
|
|
116
|
+
result = response.stopResult.find { |item| item.transferId.eql?(transfer_id) }
|
|
117
|
+
Aspera.assert(!result.nil?, type: Transfer::Error) { "transfer id=#{transfer_id}: no result of stop" }
|
|
118
|
+
Aspera.assert(result.stopped, type: Transfer::Error) { result.error&.description || "transfer id=#{transfer_id}: not stopped" }
|
|
119
|
+
true
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# @param response [Transferd::Api::QueryTransferResponse, Transferd::Api::TransferResponse] Response of the daemon
|
|
123
|
+
# @return [Hash] Normalized status, see `transfer_status`
|
|
124
|
+
def normalize_status(response)
|
|
125
|
+
info = response.transferInfo
|
|
126
|
+
result = {
|
|
127
|
+
'status' => ASYNC_STATUS.fetch(response.status, 'running'),
|
|
128
|
+
'state' => response.status.to_s.downcase,
|
|
129
|
+
'bytes_transferred' => info&.bytesTransferred.to_i
|
|
130
|
+
}
|
|
131
|
+
return result if info.nil?
|
|
132
|
+
result.merge!(
|
|
133
|
+
'bytes_written' => info.bytesWritten,
|
|
134
|
+
'files_completed' => info.filesCompleted,
|
|
135
|
+
'rate_kbps' => info.averageRateKbps,
|
|
136
|
+
'target_rate_kbps' => info.targetRateKbps,
|
|
137
|
+
'elapsed_sec' => info.elapsedUsec / 1_000_000.0,
|
|
138
|
+
'started_at' => epoch_time(info.startTimeUsec),
|
|
139
|
+
'ended_at' => epoch_time(info.endTimeUsec)
|
|
140
|
+
)
|
|
141
|
+
if FINAL_STATUSES.include?(response.status)
|
|
142
|
+
result['ended_at'] ||= Time.now.utc.iso8601
|
|
143
|
+
else
|
|
144
|
+
result.delete('ended_at')
|
|
48
145
|
end
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
146
|
+
error = info.errorDescription.to_s.strip
|
|
147
|
+
error = response.error&.description.to_s if error.empty?
|
|
148
|
+
unless error.empty?
|
|
149
|
+
result['error_code'] = info.errorCode
|
|
150
|
+
result['error'] = error
|
|
151
|
+
end
|
|
152
|
+
result.compact
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
private
|
|
156
|
+
|
|
157
|
+
# @param agent_params [Hash] Optional `timeout`: seconds
|
|
158
|
+
# @return [Time] Deadline of a call
|
|
159
|
+
def deadline(agent_params)
|
|
160
|
+
Time.now + (agent_params['timeout'] || CALL_TIMEOUT_SEC).to_f
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# @param value [Integer] Time since epoch, in microseconds or milliseconds, 0 if not known
|
|
164
|
+
# @return [String, nil] Time in ISO 8601, `nil` if not known
|
|
165
|
+
def epoch_time(value)
|
|
166
|
+
return if value.nil? || value <= 0
|
|
167
|
+
seconds = value >= MIN_USEC_EPOCH ? value / 1_000_000.0 : value / 1000.0
|
|
168
|
+
Time.at(seconds).utc.iso8601
|
|
52
169
|
end
|
|
53
170
|
end
|
|
54
171
|
|
|
55
172
|
# @param url [String] URL of the transfer manager daemon
|
|
56
173
|
# @param start [Boolean] If `false`, expect that an external daemon is already running
|
|
57
174
|
# @param stop [Boolean] If `false`, do not shutdown daemon on exit
|
|
175
|
+
# @param api_key [String, nil] API key of an external daemon with `authentication` enabled
|
|
176
|
+
# @param ca_file [String, nil] Certificate authority (PEM file) of an external daemon with `tls` enabled
|
|
58
177
|
# @param base [Hash] Base class options
|
|
59
178
|
def initialize(
|
|
60
|
-
url:
|
|
61
|
-
start:
|
|
62
|
-
stop:
|
|
179
|
+
url: AUTO_LOCAL_TCP_PORT,
|
|
180
|
+
start: true,
|
|
181
|
+
stop: true,
|
|
182
|
+
api_key: nil,
|
|
183
|
+
ca_file: nil,
|
|
63
184
|
**base
|
|
64
185
|
)
|
|
65
186
|
super(**base)
|
|
@@ -76,14 +197,15 @@ module Aspera
|
|
|
76
197
|
begin
|
|
77
198
|
# no address: local bind
|
|
78
199
|
daemon_endpoint = "#{LOCAL_SOCKET_ADDR}#{daemon_endpoint}" if daemon_endpoint.match?(/^#{PORT_SEP}[0-9]+$/o)
|
|
79
|
-
# Create stub
|
|
80
|
-
@transfer_client =
|
|
200
|
+
# Create stub: no credentials for a daemon started here, API key and TLS only for an external daemon
|
|
201
|
+
@transfer_client = self.class.create_client(daemon_endpoint, api_key: api_key, ca_file: ca_file)
|
|
81
202
|
# Initiate actual connection
|
|
82
203
|
get_info_response = @transfer_client.get_info(::Transferd::Api::InstanceInfoRequest.new)
|
|
83
204
|
@daemon_endpoint = daemon_endpoint
|
|
84
205
|
Log.log.debug { "Daemon info: #{get_info_response}" }
|
|
85
206
|
Log.log.warn('Attached to existing daemon') unless @daemon_pid || !start || !@stop
|
|
86
|
-
at_exit
|
|
207
|
+
# `shutdown` is registered with `at_exit` only when the daemon is started here:
|
|
208
|
+
# a long-running process (e.g. Orchestrator) that attaches to an external daemon for each transfer would accumulate them
|
|
87
209
|
rescue GRPC::Unavailable => e
|
|
88
210
|
# if transferd is external: do not start it, or other error
|
|
89
211
|
raise if !start || !e.message.include?('failed to connect')
|
|
@@ -122,14 +244,14 @@ module Aspera
|
|
|
122
244
|
# wait for process to initialize, max 2 seconds
|
|
123
245
|
Timeout.timeout(2.0) do
|
|
124
246
|
# this returns if process dies (within 2 seconds)
|
|
125
|
-
_, status = Process.wait2(@daemon_pid)
|
|
247
|
+
_, status = ::Process.wait2(@daemon_pid)
|
|
126
248
|
raise "Transfer daemon exited with status #{status.exitstatus}. Check files: #{log_stdout} and #{log_stderr}"
|
|
127
249
|
end
|
|
128
250
|
rescue Timeout::Error
|
|
129
251
|
nil
|
|
130
252
|
end
|
|
131
253
|
Log.log.debug { "Daemon started with pid #{@daemon_pid}" }
|
|
132
|
-
Process.detach(@daemon_pid) unless @stop
|
|
254
|
+
::Process.detach(@daemon_pid) unless @stop
|
|
133
255
|
at_exit { shutdown }
|
|
134
256
|
# update port for next connection attempt (if auto high port was requested)
|
|
135
257
|
daemon_endpoint = "#{LOCAL_SOCKET_ADDR}#{PORT_SEP}#{Products::Transferd.daemon_port_from_log(log_stdout)}" if is_local_auto_port
|
|
@@ -140,6 +262,8 @@ module Aspera
|
|
|
140
262
|
|
|
141
263
|
# Actual endpoint the daemon is listening on (resolved after connect, e.g. when port 0 was used)
|
|
142
264
|
attr_reader :daemon_endpoint
|
|
265
|
+
# Identifier of the last transfer started, given by the daemon: for `transfer_status` and `transfer_cancel`
|
|
266
|
+
attr_reader :transfer_id
|
|
143
267
|
# gRPC client of the daemon
|
|
144
268
|
attr_reader :transfer_client
|
|
145
269
|
|
|
@@ -206,8 +330,8 @@ module Aspera
|
|
|
206
330
|
def stop_daemon
|
|
207
331
|
if !@daemon_pid.nil?
|
|
208
332
|
Log.log.debug("Stopping daemon #{@daemon_pid}")
|
|
209
|
-
Process.kill(:KILL, @daemon_pid)
|
|
210
|
-
_, status = Process.wait2(@daemon_pid)
|
|
333
|
+
::Process.kill(:KILL, @daemon_pid)
|
|
334
|
+
_, status = ::Process.wait2(@daemon_pid)
|
|
211
335
|
Log.log.debug("daemon stopped #{status}")
|
|
212
336
|
@daemon_pid = nil
|
|
213
337
|
end
|
data/lib/aspera/api/alee.rb
CHANGED