aspera-cli 4.27.5 → 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.
Files changed (249) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/BUGS.md +5 -10
  4. data/CHANGELOG.md +301 -4
  5. data/CODE_OF_CONDUCT.md +18 -0
  6. data/CONTRIBUTING.md +139 -58
  7. data/GOVERNANCE.md +30 -0
  8. data/LICENSE +201 -0
  9. data/README.md +103 -26
  10. data/SECURITY.md +70 -0
  11. data/bin/ascli +8 -5
  12. data/bin/asession +10 -7
  13. data/docs/README.md +2551 -772
  14. data/docs/test-mcp-with-ai.md +13 -11
  15. data/lib/aspera/agent/base.rb +23 -2
  16. data/lib/aspera/agent/connect.rb +16 -12
  17. data/lib/aspera/agent/desktop.rb +10 -7
  18. data/lib/aspera/agent/direct.rb +34 -22
  19. data/lib/aspera/agent/factory.rb +8 -4
  20. data/lib/aspera/agent/httpgw.rb +7 -5
  21. data/lib/aspera/agent/node.rb +15 -7
  22. data/lib/aspera/agent/transferd.rb +167 -43
  23. data/lib/aspera/api/alee.rb +4 -1
  24. data/lib/aspera/api/aoc.rb +14 -11
  25. data/lib/aspera/api/ats.rb +4 -2
  26. data/lib/aspera/api/cos_node.rb +8 -5
  27. data/lib/aspera/api/faspex.rb +16 -9
  28. data/lib/aspera/api/httpgw.rb +9 -6
  29. data/lib/aspera/api/node.rb +23 -19
  30. data/lib/aspera/ascmd.rb +8 -5
  31. data/lib/aspera/ascp/installation.rb +84 -42
  32. data/lib/aspera/ascp/log.schema.yaml +1084 -0
  33. data/lib/aspera/ascp/log_analyzer/advice.rb +97 -0
  34. data/lib/aspera/ascp/log_analyzer/diagnostics.rb +344 -0
  35. data/lib/aspera/ascp/log_analyzer/lines.rb +75 -0
  36. data/lib/aspera/ascp/log_analyzer/log_file.rb +593 -0
  37. data/lib/aspera/ascp/log_analyzer/records.rb +379 -0
  38. data/lib/aspera/ascp/log_analyzer/rules.rb +172 -0
  39. data/lib/aspera/ascp/log_analyzer/session.rb +782 -0
  40. data/lib/aspera/ascp/log_analyzer.rb +354 -0
  41. data/lib/aspera/ascp/management.rb +102 -48
  42. data/lib/aspera/ascp/session_errors.rb +217 -0
  43. data/lib/aspera/assert.rb +4 -0
  44. data/lib/aspera/cli/ascp_actions.rb +16 -37
  45. data/lib/aspera/cli/ascp_logs_actions.rb +176 -0
  46. data/lib/aspera/cli/async_transfer_store.rb +7 -4
  47. data/lib/aspera/cli/bootstrapper.rb +37 -34
  48. data/lib/aspera/cli/command_line.rb +24 -6
  49. data/lib/aspera/cli/command_registry.rb +49 -4
  50. data/lib/aspera/cli/command_spec.rb +34 -4
  51. data/lib/aspera/cli/completion/ascli.bash +53 -5
  52. data/lib/aspera/cli/completion/ascli.fish +27 -8
  53. data/lib/aspera/cli/completion/ascli.ps1 +63 -0
  54. data/lib/aspera/cli/completion/ascli.zsh +36 -4
  55. data/lib/aspera/cli/completion_actions.rb +594 -0
  56. data/lib/aspera/cli/context.rb +9 -4
  57. data/lib/aspera/cli/deprecation.rb +5 -2
  58. data/lib/aspera/cli/error.rb +45 -0
  59. data/lib/aspera/cli/extended_value.rb +83 -24
  60. data/lib/aspera/cli/formatter.rb +142 -73
  61. data/lib/aspera/cli/gem_checker.rb +9 -6
  62. data/lib/aspera/cli/hints.rb +22 -11
  63. data/lib/aspera/cli/http.rb +17 -13
  64. data/lib/aspera/cli/info.rb +17 -6
  65. data/lib/aspera/cli/mailer.rb +7 -4
  66. data/lib/aspera/cli/mcp/http_servlet.rb +155 -0
  67. data/lib/aspera/cli/mcp/secrets.rb +146 -0
  68. data/lib/aspera/cli/mcp/tool.rb +232 -0
  69. data/lib/aspera/cli/option_declarator.rb +10 -4
  70. data/lib/aspera/cli/option_registry.rb +6 -3
  71. data/lib/aspera/cli/option_types.rb +17 -2
  72. data/lib/aspera/cli/option_value.rb +72 -11
  73. data/lib/aspera/cli/options.schema.yaml +856 -81
  74. data/lib/aspera/cli/parser.rb +64 -31
  75. data/lib/aspera/cli/plugins/alee.rb +7 -4
  76. data/lib/aspera/cli/plugins/aoc.rb +250 -44
  77. data/lib/aspera/cli/plugins/ats.rb +9 -8
  78. data/lib/aspera/cli/plugins/base.rb +51 -25
  79. data/lib/aspera/cli/plugins/basic_auth.rb +5 -2
  80. data/lib/aspera/cli/plugins/config.rb +207 -141
  81. data/lib/aspera/cli/plugins/console.rb +9 -4
  82. data/lib/aspera/cli/plugins/cos.rb +8 -4
  83. data/lib/aspera/cli/plugins/factory.rb +22 -8
  84. data/lib/aspera/cli/plugins/faspex5.rb +37 -44
  85. data/lib/aspera/cli/plugins/faspio.rb +41 -8
  86. data/lib/aspera/cli/plugins/httpgw.rb +8 -4
  87. data/lib/aspera/cli/plugins/mcp.rb +186 -121
  88. data/lib/aspera/cli/plugins/node.rb +41 -34
  89. data/lib/aspera/cli/plugins/oauth.rb +5 -1
  90. data/lib/aspera/cli/plugins/orchestrator.rb +572 -59
  91. data/lib/aspera/cli/plugins/preview.rb +69 -44
  92. data/lib/aspera/cli/plugins/server.rb +66 -12
  93. data/lib/aspera/cli/plugins/shares.rb +288 -48
  94. data/lib/aspera/cli/plugins/transferd.rb +223 -0
  95. data/lib/aspera/cli/preset_actions.rb +155 -33
  96. data/lib/aspera/cli/preset_manager.rb +72 -16
  97. data/lib/aspera/cli/prompt.rb +7 -2
  98. data/lib/aspera/cli/result.rb +28 -11
  99. data/lib/aspera/cli/runner.rb +193 -80
  100. data/lib/aspera/cli/secret_finder.rb +4 -1
  101. data/lib/aspera/cli/security.rb +204 -0
  102. data/lib/aspera/cli/special_values.rb +4 -1
  103. data/lib/aspera/cli/sync_actions.rb +13 -10
  104. data/lib/aspera/cli/table_fitter.rb +119 -0
  105. data/lib/aspera/cli/terminal_formatter.rb +32 -40
  106. data/lib/aspera/cli/transfer_actions.rb +11 -8
  107. data/lib/aspera/cli/transfer_agent.rb +31 -19
  108. data/lib/aspera/cli/transfer_progress.rb +13 -45
  109. data/lib/aspera/cli/vault_actions.rb +45 -0
  110. data/lib/aspera/cli/vault_manager.rb +197 -50
  111. data/lib/aspera/cli/version.rb +4 -1
  112. data/lib/aspera/cli/web_secret.html.erb +61 -0
  113. data/lib/aspera/cli/web_secret.rb +222 -0
  114. data/lib/aspera/cli/wizard.rb +58 -45
  115. data/lib/aspera/command_line_builder.rb +35 -5
  116. data/lib/aspera/command_line_converter.rb +4 -1
  117. data/lib/aspera/coverage.rb +103 -33
  118. data/lib/aspera/data_repository.rb +42 -25
  119. data/lib/aspera/dot_container.rb +4 -1
  120. data/lib/aspera/duration.rb +45 -0
  121. data/lib/aspera/environment.rb +106 -33
  122. data/lib/aspera/exec_spec.rb +9 -5
  123. data/lib/aspera/faspex_gw.rb +105 -35
  124. data/lib/aspera/faspex_postproc.rb +193 -47
  125. data/lib/aspera/formatter_interface.rb +4 -2
  126. data/lib/aspera/graphql.rb +5 -1
  127. data/lib/aspera/hash_ext.rb +3 -0
  128. data/lib/aspera/id_generator.rb +6 -3
  129. data/lib/aspera/json_rpc/client.rb +55 -35
  130. data/lib/aspera/json_rpc/version.rb +4 -0
  131. data/lib/aspera/line_logger.rb +4 -1
  132. data/lib/aspera/link_header.rb +4 -1
  133. data/lib/aspera/log.rb +20 -10
  134. data/lib/aspera/markdown.rb +155 -115
  135. data/lib/aspera/mime.rb +9 -0
  136. data/lib/aspera/nagios.rb +9 -5
  137. data/lib/aspera/node_emulator.rb +111 -112
  138. data/lib/aspera/oauth/client/base.rb +163 -0
  139. data/lib/aspera/oauth/{boot.rb → client/boot.rb} +8 -4
  140. data/lib/aspera/oauth/{factory.rb → client/factory.rb} +13 -3
  141. data/lib/aspera/oauth/{generic.rb → client/generic.rb} +5 -1
  142. data/lib/aspera/oauth/{json_credentials.rb → client/json_credentials.rb} +4 -1
  143. data/lib/aspera/oauth/{jwt.rb → client/jwt.rb} +6 -3
  144. data/lib/aspera/oauth/client/shares_web.rb +85 -0
  145. data/lib/aspera/oauth/{url_json.rb → client/url_json.rb} +4 -1
  146. data/lib/aspera/oauth/client/web.rb +84 -0
  147. data/lib/aspera/oauth/server/authorize.html.erb +34 -0
  148. data/lib/aspera/oauth/server/pkce.rb +427 -0
  149. data/lib/aspera/orchestrator_workflow_checker.rb +679 -0
  150. data/lib/aspera/persistency_action_once.rb +5 -3
  151. data/lib/aspera/persistency_folder.rb +6 -3
  152. data/lib/aspera/preview/file_types.rb +6 -3
  153. data/lib/aspera/preview/generator.rb +9 -5
  154. data/lib/aspera/preview/options.schema.yaml +3 -3
  155. data/lib/aspera/preview/terminal.rb +11 -6
  156. data/lib/aspera/preview/utils.rb +6 -4
  157. data/lib/aspera/products/connect.rb +5 -2
  158. data/lib/aspera/products/desktop.rb +4 -1
  159. data/lib/aspera/products/other.rb +4 -2
  160. data/lib/aspera/products/transferd.rb +6 -2
  161. data/lib/aspera/products/transferd_service.rb +610 -0
  162. data/lib/aspera/proxy_auto_config.js +2 -2
  163. data/lib/aspera/proxy_auto_config.rb +5 -2
  164. data/lib/aspera/rainbow.rb +30 -1
  165. data/lib/aspera/rest/aspera_errors.rb +55 -60
  166. data/lib/aspera/rest/call_error.rb +3 -0
  167. data/lib/aspera/rest/client.rb +42 -42
  168. data/lib/aspera/rest/error_analyzer.rb +14 -2
  169. data/lib/aspera/rest/list.rb +14 -10
  170. data/lib/aspera/rest/parameters.rb +3 -0
  171. data/lib/aspera/rest/util.rb +13 -4
  172. data/lib/aspera/rest.rb +9 -7
  173. data/lib/aspera/schema/IBM Aspera Faspex API-5.0-enhanced.yaml +9 -11
  174. data/lib/aspera/schema/IBM Aspera Orchestrator API-v1-enhanced.yaml +4089 -0
  175. data/lib/aspera/schema/IBM Aspera faspio Gateway API-1.0.0-enhanced.yaml +1097 -0
  176. data/lib/aspera/schema/IBM Aspera on Cloud API-0.2.6-enhanced.yaml +11 -11
  177. data/lib/aspera/schema/IBM Aspera on Cloud Automation API-1.0.5-enhanced.yaml +2437 -1437
  178. data/lib/aspera/schema/IBM_Aspera_Shares.yaml +819 -7
  179. data/lib/aspera/schema/async_tables.yaml +11 -10
  180. data/lib/aspera/schema/documentation.rb +56 -78
  181. data/lib/aspera/schema/reader.rb +46 -11
  182. data/lib/aspera/schema/registry.rb +45 -24
  183. data/lib/aspera/schema/transferd-config.schema.json +333 -0
  184. data/lib/aspera/schema/validator.rb +4 -1
  185. data/lib/aspera/sealed_hash.rb +166 -0
  186. data/lib/aspera/secret/hider.rb +201 -0
  187. data/lib/aspera/secret/reference.rb +150 -0
  188. data/lib/aspera/secret/resolver.rb +212 -0
  189. data/lib/aspera/secret/store/base.rb +153 -0
  190. data/lib/aspera/secret/store/encrypted_hash.rb +329 -0
  191. data/lib/aspera/secret/store/factory.rb +103 -0
  192. data/lib/aspera/secret/store/hashicorp_vault.rb +390 -0
  193. data/lib/aspera/secret/store/keeper.rb +141 -0
  194. data/lib/aspera/secret/store/macos_security.rb +284 -0
  195. data/lib/aspera/secret/store/one_password_api.rb +99 -0
  196. data/lib/aspera/secret/store/one_password_base.rb +42 -0
  197. data/lib/aspera/secret/store/one_password_cli.rb +110 -0
  198. data/lib/aspera/secret/store/secret_service.rb +125 -0
  199. data/lib/aspera/secret/strength.rb +119 -0
  200. data/lib/aspera/servlet_helpers.rb +114 -0
  201. data/lib/aspera/ssh.rb +10 -7
  202. data/lib/aspera/ssl.rb +5 -2
  203. data/lib/aspera/string_ext.rb +3 -0
  204. data/lib/aspera/sync/args.schema.yaml +6 -1
  205. data/lib/aspera/sync/conf.schema.yaml +25 -10
  206. data/lib/aspera/sync/database.rb +3 -0
  207. data/lib/aspera/sync/operations.rb +34 -12
  208. data/lib/aspera/temp_file_manager.rb +85 -22
  209. data/lib/aspera/timer_limiter.rb +3 -0
  210. data/lib/aspera/transfer/error.rb +4 -1
  211. data/lib/aspera/transfer/faux_file.rb +4 -1
  212. data/lib/aspera/transfer/parameters.rb +22 -14
  213. data/lib/aspera/transfer/result.rb +3 -0
  214. data/lib/aspera/transfer/resumer.rb +6 -4
  215. data/lib/aspera/transfer/spec.rb +45 -18
  216. data/lib/aspera/transfer/spec.schema.yaml +8 -5
  217. data/lib/aspera/transfer/units.rb +75 -0
  218. data/lib/aspera/uri_reader.rb +57 -7
  219. data/lib/aspera/web_auth/index.html.erb +20 -0
  220. data/lib/aspera/web_auth/paste.rb +109 -0
  221. data/lib/aspera/web_auth/receiver.rb +50 -0
  222. data/lib/aspera/web_auth/relay.rb +76 -0
  223. data/lib/aspera/web_auth/reply.html.erb +150 -0
  224. data/lib/aspera/web_auth/server.rb +59 -14
  225. data/lib/aspera/web_page.html.erb +262 -0
  226. data/lib/aspera/web_page.rb +66 -0
  227. data/lib/aspera/web_server_simple.rb +82 -13
  228. data/lib/aspera/yaml.rb +5 -1
  229. data/llms.txt +81 -0
  230. data/skills/ascli/SKILL.md +88 -0
  231. data.tar.gz.sig +0 -0
  232. metadata +116 -48
  233. metadata.gz.sig +0 -0
  234. data/lib/aspera/cli/mcp_tool.rb +0 -189
  235. data/lib/aspera/keychain/base.rb +0 -25
  236. data/lib/aspera/keychain/encrypted_hash.rb +0 -188
  237. data/lib/aspera/keychain/factory.rb +0 -59
  238. data/lib/aspera/keychain/hashicorp_vault.rb +0 -74
  239. data/lib/aspera/keychain/macos_security.rb +0 -171
  240. data/lib/aspera/keychain/one_password_api.rb +0 -86
  241. data/lib/aspera/keychain/one_password_base.rb +0 -34
  242. data/lib/aspera/keychain/one_password_cli.rb +0 -98
  243. data/lib/aspera/oauth/base.rb +0 -141
  244. data/lib/aspera/oauth/web.rb +0 -57
  245. data/lib/aspera/oauth.rb +0 -9
  246. data/lib/aspera/schema/IBM Aspera Orchestrator API-v1.yaml +0 -1784
  247. data/lib/aspera/schema/IBM Aspera faspio Gateway API-1.0.0.yaml +0 -249
  248. data/lib/aspera/secret_hider.rb +0 -117
  249. data/lib/aspera/web_auth/index.html +0 -147
@@ -0,0 +1,204 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: IBM Corp.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ require_relative '../assert'
7
+ require_relative 'error'
8
+ require 'singleton'
9
+
10
+ module Aspera
11
+ module Cli
12
+ # Security level: restricts the features that access local resources (files, environment, network) or execute code.
13
+ # On the command line, the default level is `low`: the user can do anything that the account is allowed to do.
14
+ # It can be raised, for example in MCP server mode, where commands come from a client.
15
+ #
16
+ # @!method self.instance
17
+ # Returns the singleton instance of Security
18
+ # @return [Security] the singleton instance
19
+ class Security
20
+ include Singleton
21
+
22
+ # Security levels, from least to most restrictive
23
+ LEVELS = %i[low medium high].freeze
24
+ # Extended-value handlers restricted by security level, with the levels that allow them
25
+ EXTENDED_VALUE_LEVELS = {
26
+ ruby: %i[low],
27
+ uri: %i[low],
28
+ env: %i[low],
29
+ file: %i[low medium]
30
+ }.freeze
31
+ # Levels that allow processing a secret (e.g. by an extended value): the result could reveal it, as only declared values are hidden
32
+ SECRET_PROCESSING_LEVELS = %i[low].freeze
33
+ private_constant :EXTENDED_VALUE_LEVELS, :SECRET_PROCESSING_LEVELS
34
+
35
+ def initialize
36
+ reset
37
+ end
38
+
39
+ # Back to default: level `low`, no allowed path, not locked
40
+ # @return [nil]
41
+ def reset
42
+ @level = nil
43
+ @default_level = LEVELS.first
44
+ @allowed_paths = []
45
+ @writable_paths = []
46
+ @locked = nil
47
+ end
48
+
49
+ # @return [Symbol] Level set by option `security`, else default level
50
+ def level = @level || @default_level
51
+
52
+ # Set by option `security`.
53
+ # When locked, the value can only be set again to the current one.
54
+ # @param value [Hash] `level`, `allowed_paths` and `writable_paths`, see schema `SecurityOptions`
55
+ # @return [nil]
56
+ def options=(value)
57
+ Aspera.assert_type(value, Hash, type: BadArgument) { 'security' }
58
+ # When locked, each command starts with the empty value of a Hash option: not a change
59
+ return if @locked && value.empty?
60
+ value = value.transform_keys(&:to_sym)
61
+ new_level = value[:level]&.to_sym
62
+ Aspera.assert_values(new_level, LEVELS, type: BadArgument) { 'security.level' } unless new_level.nil?
63
+ new_paths = existing_real_paths(value[:allowed_paths], 'allowed_paths')
64
+ new_writable_paths = existing_real_paths(value[:writable_paths], 'writable_paths')
65
+ if @locked
66
+ Aspera.assert((new_level || @default_level).eql?(level) && new_paths.eql?(@allowed_paths) && new_writable_paths.eql?(@writable_paths), type: BadArgument) do
67
+ "security cannot be changed #{@locked}"
68
+ end
69
+ return
70
+ end
71
+ @level = new_level
72
+ @allowed_paths = new_paths
73
+ @writable_paths = new_writable_paths
74
+ nil
75
+ end
76
+
77
+ # Prevent further changes, e.g. by commands of an MCP client
78
+ # @param reason [String] For error messages, e.g. `in MCP server mode`
79
+ # @param default [Symbol, nil] Level if not set by option
80
+ # @return [nil]
81
+ def lock(reason, default: nil)
82
+ Aspera.assert_values(default, LEVELS) unless default.nil?
83
+ @default_level = default unless default.nil?
84
+ @locked = reason
85
+ nil
86
+ end
87
+
88
+ # @param max_level [Symbol, nil] `security:` attribute of an option or command: most restrictive level that allows it, `nil` for any level
89
+ # @return [Boolean] `true` if the feature is available at current level
90
+ def allowed?(max_level)
91
+ max_level.nil? || LEVELS.index(level) <= LEVELS.index(max_level)
92
+ end
93
+
94
+ # Features that execute code (own or downloaded), or load code, declare `security: :low`.
95
+ # @param max_level [Symbol, nil] `security:` attribute of an option or command
96
+ # @param what [String] Feature, e.g. `option notify_template`
97
+ # @raise [BadArgument] If the feature is refused at current level
98
+ def check_level(max_level, what)
99
+ return if allowed?(max_level)
100
+ raise BadArgument, "#{what}: disabled by security level #{level}: use level #{max_level} (#{where_to_set})"
101
+ end
102
+
103
+ # A value stored to be used later (e.g. in a preset) is evaluated when used, maybe at another level (e.g. `low` on the command line).
104
+ # So it must not use an extended value that is refused at current level, e.g. `@val:@ruby:...`.
105
+ # @param value [Object] Value to store (`Hash`, `Array`, `String`)
106
+ # @param what [String] What stores the value, e.g. `preset option ts`
107
+ # @raise [BadArgument] If the value contains an extended value refused at current level
108
+ def check_stored_value(value, what)
109
+ case value
110
+ when Hash then value.each { |k, v| [k, v].each { |item| check_stored_value(item, what) } }
111
+ when Array then value.each { |v| check_stored_value(v, what) }
112
+ when String
113
+ EXTENDED_VALUE_LEVELS.each do |handler, levels|
114
+ next if levels.include?(level) || !value.include?("@#{handler}:")
115
+ raise BadArgument, "#{what}: cannot store @#{handler}: extended value, disabled by security level #{level} (#{where_to_set})"
116
+ end
117
+ end
118
+ nil
119
+ end
120
+
121
+ # @param handler [Symbol] Extended-value handler
122
+ # @raise [BadArgument] If the handler is refused at current level, with the level that allows it and where to set it
123
+ def check_extended_value(handler)
124
+ allowed = EXTENDED_VALUE_LEVELS[handler]
125
+ return if allowed.nil? || allowed.include?(level)
126
+ # the least permissive level that allows it
127
+ needed = handler.eql?(:file) ? "level #{allowed.last} with the file in security.allowed_paths" : "level #{allowed.last}"
128
+ raise BadArgument, "@#{handler}: extended value is disabled by security level #{level}: use #{needed} (#{where_to_set}), or give the value itself"
129
+ end
130
+
131
+ # A secret (e.g. read by `@vault:`, `@secret:`, `@preset:`) is hidden in results only as declared: the result of processing it
132
+ # could reveal it (e.g. split by `@list:`, in an error message of `@json:`, short value in a text by `@extend:`, converted as name of parameter).
133
+ # @param what [String] What processes the value, e.g. `@list`
134
+ # @param hint [String] What to do instead
135
+ # @yieldreturn [Boolean] `true` if the value contains a secret, evaluated only if the level refuses it
136
+ # @raise [BadArgument] If the value contains a secret and processing it is refused at current level
137
+ def check_secret_processing(what, hint: 'give the secret as the whole value')
138
+ return if SECRET_PROCESSING_LEVELS.include?(level) || !yield
139
+ raise BadArgument, "#{what}: cannot process a secret at security level #{level}, as the result could reveal it: #{hint}, or use level low (#{where_to_set})"
140
+ end
141
+
142
+ # At level `medium`, the real path is checked, so that neither `..` nor a symbolic link leads outside of allowed paths.
143
+ # A missing file gets the same error as a file outside allowed paths: no information on other files.
144
+ # @param path [String] Path of a file to read
145
+ # @return [String] Path to read
146
+ # @raise [BadArgument] If reading the file is refused at current level
147
+ def readable_path(path)
148
+ path = File.expand_path(path)
149
+ case level
150
+ when :low then path
151
+ when :medium
152
+ real_path = File.realpath(path) rescue nil
153
+ Aspera.assert(!real_path.nil? && @allowed_paths.any? { |allowed| real_path.eql?(allowed) || real_path.start_with?(File.join(allowed, '')) }, type: BadArgument) do
154
+ "no such file in security.allowed_paths: #{path}"
155
+ end
156
+ real_path
157
+ else raise BadArgument, "reading files is disabled by security level #{level}"
158
+ end
159
+ end
160
+
161
+ # Writing a file where the client chooses (e.g. downloaded file) could replace a file that is used later (e.g. plugin, shell startup file).
162
+ # At level `medium` and `high`, files can be written only in `writable_paths` (none by default): the real path of the folder is checked,
163
+ # so that neither `..` nor a symbolic link leads outside of them.
164
+ # @param path [String] Local path of a file or folder to write, that may not exist yet
165
+ # (not called for a transfer agent that writes on a remote system, see `Agent::Base#local_destination?`)
166
+ # @return [String] Path to write: unchanged at level `low` (no restriction), else the real path
167
+ # @raise [BadArgument] If writing is refused at current level
168
+ def writable_path(path)
169
+ return path if level.eql?(:low)
170
+ path = File.expand_path(path)
171
+ # The first existing parent gives the real path, the missing part contains no link
172
+ existing = path
173
+ missing = []
174
+ until File.exist?(existing) || File.dirname(existing).eql?(existing)
175
+ missing.unshift(File.basename(existing))
176
+ existing = File.dirname(existing)
177
+ end
178
+ real_path = File.join(File.realpath(existing), *missing)
179
+ Aspera.assert(@writable_paths.any? { |allowed| real_path.eql?(allowed) || real_path.start_with?(File.join(allowed, '')) }, type: BadArgument) do
180
+ "writing is refused by security level #{level}: not in security.writable_paths: #{path} (#{where_to_set})"
181
+ end
182
+ real_path
183
+ end
184
+
185
+ private
186
+
187
+ # @param paths [Array<String>, nil] Paths given to option `security`
188
+ # @param key [String] Name of key, for error messages
189
+ # @return [Array<String>] Real paths
190
+ def existing_real_paths(paths, key)
191
+ Array(paths).map do |path|
192
+ path = File.expand_path(path)
193
+ Aspera.assert(File.exist?(path), type: BadArgument) { "security.#{key}: no such file or folder: #{path}" }
194
+ File.realpath(path)
195
+ end
196
+ end
197
+
198
+ # @return [String] Where to set the level, for error messages
199
+ def where_to_set
200
+ @locked.nil? ? 'option security' : "option security when starting, as it cannot be changed #{@locked}"
201
+ end
202
+ end
203
+ end
204
+ end
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # SPDX-FileCopyrightText: IBM Corp.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
3
6
  module Aspera
4
7
  module Cli
5
8
  # base class for plugins modules
6
9
  module SpecialValues
7
10
  # special values
8
- # `INIT` to unitialize with all current IDs
11
+ # `INIT` to initialize with all current IDs
9
12
  INIT = 'INIT'
10
13
  # `ALL` means "all ids"
11
14
  ALL = 'ALL'
@@ -1,8 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'aspera/sync/operations'
4
- require 'aspera/assert'
5
- require 'aspera/environment'
3
+ # SPDX-FileCopyrightText: IBM Corp.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ require_relative '../sync/operations'
7
+ require_relative '../assert'
8
+ require_relative '../environment'
6
9
  require 'pathname'
7
10
 
8
11
  module Aspera
@@ -16,7 +19,7 @@ module Aspera
16
19
  %w[Syncd Error Confl Pconf] +
17
20
  (23..24).map { |i| "P(#{i})" }).freeze
18
21
  # Positional arguments shared by sync transfer commands (push/pull/bidi) and sync admin commands.
19
- PATH_AND_INFO_ARGS = [{name: :path}, {name: :sync_info, type: Hash, mandatory: false, default: {}}].freeze
22
+ PATH_AND_INFO_ARGS = [{name: :path, complete: :folder}, {name: :sync_info, type: Hash, mandatory: false, default: {}}].freeze
20
23
  # When a plugin class includes SyncActions, register the :sql option
21
24
  # in that class's DSL registry so Base#initialize auto-declares it,
22
25
  # and add the class-level DSL methods of ClassMethods.
@@ -34,7 +37,7 @@ module Aspera
34
37
  def sync_admin_commands(parent)
35
38
  commands_under(parent, description: 'Manage sync database (admin operations)') do
36
39
  command(
37
- :find, description: 'Find sync database files', arguments: [{name: :path}],
40
+ :find, description: 'Find sync database files', arguments: [{name: :path, complete: :folder}],
38
41
  action: lambda do |path:, **|
39
42
  dbs = Sync::Operations.list_db_files(path)
40
43
  Result::ObjectList.new(dbs.keys.map { |n| {name: n, path: dbs[n]} })
@@ -47,14 +50,14 @@ module Aspera
47
50
  command(
48
51
  :meta, description: 'Show sync session metadata', arguments: PATH_AND_INFO_ARGS,
49
52
  action: lambda do |path:, sync_info: {}, **|
50
- require 'aspera/sync/database'
53
+ require_relative '../sync/database'
51
54
  Result::SingleObject.new(db_from_args(path: path, sync_info: sync_info).meta(options.get_option(:sql)))
52
55
  end
53
56
  )
54
57
  command(
55
58
  :counters, description: 'Show sync counters', arguments: PATH_AND_INFO_ARGS,
56
59
  action: lambda do |path:, sync_info: {}, **|
57
- require 'aspera/sync/database'
60
+ require_relative '../sync/database'
58
61
  Result::SingleObject.new(db_from_args(path: path, sync_info: sync_info).counters(options.get_option(:sql)))
59
62
  end
60
63
  )
@@ -62,14 +65,14 @@ module Aspera
62
65
  command(
63
66
  :overview, description: 'Show sync database overview', arguments: PATH_AND_INFO_ARGS,
64
67
  action: lambda do |path:, sync_info: {}, **|
65
- require 'aspera/sync/database'
68
+ require_relative '../sync/database'
66
69
  Result::ObjectList.new(db_from_args(path: path, sync_info: sync_info).overview, fields: %w[table name type])
67
70
  end
68
71
  )
69
72
  command(
70
73
  :query, description: 'Execute a raw SQL query', arguments: PATH_AND_INFO_ARGS,
71
74
  action: lambda do |path:, sync_info: {}, **|
72
- require 'aspera/sync/database'
75
+ require_relative '../sync/database'
73
76
  Result.auto(db_from_args(path: path, sync_info: sync_info).execute(options.get_option(:sql, mandatory: true)))
74
77
  end
75
78
  )
@@ -154,7 +157,7 @@ module Aspera
154
157
  end
155
158
 
156
159
  def action_sync_admin_file_info(path:, sync_info: {}, **)
157
- require 'aspera/sync/database'
160
+ require_relative '../sync/database'
158
161
  result = db_from_args(path: path, sync_info: sync_info).file_info(options.get_option(:sql))
159
162
  result.each do |r|
160
163
  r['sstate'] = SyncActions::STATE_STR[r['state']] if r['state']
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: IBM Corp.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ require 'terminal-table'
7
+ require 'unicode/display_width'
8
+
9
+ module Aspera
10
+ module Cli
11
+ # Build a terminal table that fits in a given width, by wrapping cells.
12
+ # Columns with text (containing spaces, e.g. `description`) are wrapped first, the widest first.
13
+ # If not enough, other columns (names, identifiers) are wrapped too.
14
+ # If the table cannot fit, columns are narrowed to their minimum width.
15
+ module TableFitter
16
+ # Minimum width of a wrapped column with text
17
+ MIN_TEXT_WIDTH = 20
18
+ # Minimum width of other wrapped columns
19
+ MIN_WIDTH = 10
20
+ # ANSI style (zero width)
21
+ STYLE = /\e\[[0-9;]*m/
22
+ # Styles that reset all styles
23
+ RESETS = ["\e[0m", "\e[m"].freeze
24
+ # ANSI style or character
25
+ TOKEN = /#{STYLE}|\X/
26
+ # Long words are preferably broken after one of these characters
27
+ BREAK_AFTER = %r{[-_./,=]}
28
+ private_constant :MIN_TEXT_WIDTH, :MIN_WIDTH, :STYLE, :RESETS, :TOKEN, :BREAK_AFTER
29
+
30
+ class << self
31
+ # @param headings [Array] Column names
32
+ # @param rows [Array<Array<String>>] Rows of cells
33
+ # @param style [Hash] `Terminal::Table` style
34
+ # @param width [Integer, nil] Maximum width of the table, or `nil` for natural width (not a `style` parameter)
35
+ # @return [Terminal::Table]
36
+ def table(headings:, rows:, style:, width:)
37
+ headings, rows = fit(headings, rows, width - overhead(headings.length, style)) unless width.nil?
38
+ Terminal::Table.new(headings: headings, rows: rows, style: style)
39
+ end
40
+
41
+ private
42
+
43
+ # @return [Integer] Width taken by borders and padding for a table with that number of columns
44
+ def overhead(column_count, style)
45
+ Terminal::Table.new(headings: [''] * column_count, style: style).to_s.lines.map { |line| display_width(line.chomp) }.max
46
+ end
47
+
48
+ # @param available [Integer] Width available for the content of all columns
49
+ # @return [Array] Headings and rows, wrapped to fit in available width, or as narrow as possible
50
+ def fit(headings, rows, available)
51
+ lines = [headings, *rows].map { |row| row.map(&:to_s) }
52
+ columns = lines.transpose
53
+ natural = columns.map { |cells| cells.flat_map { |cell| cell.split("\n") }.map { |line| display_width(line) }.max || 0 }
54
+ return [headings, rows] if natural.sum <= available
55
+ text = columns.map { |cells| cells.any? { |cell| cell.match?(/[ \t]/) } }
56
+ # Minimum width of a column, not narrower than its heading
57
+ floor = ->(i, min) { min.clamp(display_width(columns[i].first), natural[i]) }
58
+ # First wrap only columns with text, if not enough wrap all columns
59
+ text_only = natural.each_index.map { |i| text[i] ? floor.call(i, MIN_TEXT_WIDTH) : natural[i] }
60
+ all = natural.each_index.map { |i| floor.call(i, text[i] ? MIN_TEXT_WIDTH : MIN_WIDTH) }
61
+ minimum = text_only.sum <= available ? text_only : all
62
+ # Columns wider than `limit` are narrowed to it, but not below their minimum (`limit` is `-1` if the table cannot fit)
63
+ widths_for = ->(limit) { natural.zip(minimum).map { |nat, min| limit.clamp(min, nat) } }
64
+ limit = (0..natural.max).bsearch { |l| widths_for.call(l).sum > available } - 1
65
+ widths = widths_for.call(limit)
66
+ wrapped = lines.map { |row| row.each_with_index.map { |cell, i| wrap(cell, widths[i]) } }
67
+ [wrapped.first, wrapped.drop(1)]
68
+ end
69
+
70
+ # @return [String] Text with lines longer than width wrapped on spaces, and long words broken
71
+ def wrap(text, width)
72
+ text.split("\n").map do |line|
73
+ next line if display_width(line) <= width
74
+ wrapped = line.split.flat_map { |word| break_word(word, width) }.each_with_object([]) do |word, result|
75
+ if !result.empty? && display_width(result.last) + 1 + display_width(word) <= width
76
+ result[-1] = "#{result.last} #{word}"
77
+ else
78
+ result.push(word)
79
+ end
80
+ end
81
+ restyle(wrapped).join("\n")
82
+ end.join("\n")
83
+ end
84
+
85
+ # @return [Array<String>] Word split in pieces not wider than width, preferably after a punctuation
86
+ def break_word(word, width)
87
+ pieces = []
88
+ while display_width(word) > width
89
+ piece = +''
90
+ word.scan(TOKEN) do |token|
91
+ break if display_width(piece + token) > width && display_width(piece).positive?
92
+ piece << token
93
+ end
94
+ cut = piece.rindex(BREAK_AFTER)
95
+ piece = piece[0..cut] if cut && display_width(piece[0..cut]) > width / 2
96
+ pieces.push(piece)
97
+ word = word[piece.length..]
98
+ end
99
+ pieces.push(word)
100
+ end
101
+
102
+ # @return [Array<String>] Lines with ANSI styles closed at end of line, and open again on next line
103
+ def restyle(lines)
104
+ active = []
105
+ lines.map do |line|
106
+ result = active.join + line
107
+ line.scan(STYLE) { |style| RESETS.include?(style) ? active.clear : active.push(style) }
108
+ active.empty? ? result : "#{result}#{RESETS.first}"
109
+ end
110
+ end
111
+
112
+ # @return [Integer] Number of terminal columns used to display the string, ignoring ANSI escape sequences
113
+ def display_width(string)
114
+ Unicode::DisplayWidth.of(Terminal::Table::Util.ansi_escape(string))
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -1,17 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'aspera/environment'
4
- require 'aspera/formatter_interface'
5
- require 'aspera/markdown'
6
- require 'aspera/assert'
7
- require 'aspera/rainbow'
3
+ # SPDX-FileCopyrightText: IBM Corp.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ require_relative '../environment'
7
+ require_relative '../formatter_interface'
8
+ require_relative '../markdown'
9
+ require_relative '../assert'
10
+ require_relative '../rainbow'
8
11
  using Rainbow
9
12
 
10
13
  module Aspera
11
14
  module Cli
12
15
  # Terminal formatter with ANSI colors and Unicode support
13
16
  # @see FormatterInterface
14
- # @see MarkdownFormatter (in build/lib/doc_helper.rb)
17
+ # @see MarkdownFormatter (in build/lib/markdown_formatter.rb)
15
18
  module TerminalFormatter
16
19
  include FormatterInterface
17
20
 
@@ -20,52 +23,41 @@ module Aspera
20
23
  'HINT:'.bg(:green).white.blink
21
24
  end
22
25
 
23
- # Format boolean with colored symbol (+/- or Y/ )
26
+ # Format boolean with colored check mark, or Y and space without Unicode
24
27
  def tick(yes)
25
- result =
26
- if Environment.terminal_supports_unicode?
27
- yes ? "\u2713" : "\u2717"
28
- else
29
- yes ? 'Y' : ' '
30
- end
28
+ result = Environment.char(yes ? '✓' : '✗')
31
29
  return result.green if yes
32
- return result.red
30
+ result.red
33
31
  end
34
32
 
35
33
  # Format special values with colors (dim for empty, reverse for others)
36
34
  def special_format(what)
37
35
  result = "<#{what}>"
38
- return %w[null empty].any? { |s| what.include?(s) } ? result.faint : result.inverse
39
- end
40
-
41
- # Prepare table row for terminal display (word wrap arrays)
42
- def check_row(row)
43
- row.each_key do |k|
44
- row[k] = row[k].map { |i| WordWrap.ww(i.to_s, 120).chomp }.join("\n") if row[k].is_a?(Array)
45
- end
36
+ %w[null empty].any? { |s| what.include?(s) } ? result.faint : result.inverse
46
37
  end
47
38
 
48
- # Convert Markdown to terminal format (**bold** -> blue, `code` -> bold)
49
- # @param match [MatchData, String]
50
- def markdown_text(match)
51
- if match.is_a?(String)
52
- match = Markdown::FORMATS.match(match)
53
- Aspera.assert(match, 'markdown text does not match any known format')
54
- end
55
- Aspera.assert_type(match, MatchData)
56
- if match[:entity]
57
- Aspera.assert_values(match[:entity], %w[bsol])
58
- '\\'
59
- elsif match[:bold]
60
- match[:bold].to_s.blue
61
- elsif match[:code]
62
- match[:code].to_s.bold
63
- else
64
- Aspera.error_unexpected_value(match.to_s)
39
+ # Convert Markdown inline markup to terminal format (**bold** -> blue, `code` -> bold)
40
+ # @param text [String] text with Markdown inline markup
41
+ # @return [String] text with terminal formatting
42
+ def markdown_text(text)
43
+ text.to_s.gsub(Markdown::INLINE_MARKUP_RE) do
44
+ match = Regexp.last_match
45
+ if match[:entity]
46
+ case match[:entity]
47
+ when 'bsol' then '\\'
48
+ else Aspera.error_unexpected_value(match[:entity]) { 'HTML entity' }
49
+ end
50
+ elsif match[:bold]
51
+ match[:bold].to_s.blue
52
+ elsif match[:code]
53
+ match[:code].to_s.bold
54
+ else
55
+ Aspera.error_unexpected_value(match.to_s)
56
+ end
65
57
  end
66
58
  end
67
59
 
68
- module_function :hint, :tick, :special_format, :check_row, :markdown_text
60
+ module_function :hint, :tick, :special_format, :markdown_text
69
61
  end
70
62
  end
71
63
  end
@@ -1,15 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'aspera/cli/async_transfer_store'
4
- require 'aspera/agent/factory'
5
- require 'aspera/log'
6
- require 'aspera/assert'
3
+ # SPDX-FileCopyrightText: IBM Corp.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ require_relative 'async_transfer_store'
7
+ require_relative '../agent/factory'
8
+ require_relative '../log'
9
+ require_relative '../assert'
7
10
 
8
11
  module Aspera
9
12
  module Cli
10
13
  # Mixin for Config plugin: async transfer management actions.
11
- # Exposes three sub-commands under `config transfer`:
12
- # status --id=<job_id> Re-query a running/completed transfer
14
+ # Exposes three sub-commands under `config agents jobs` (`config transfer` is a deprecated alias):
15
+ # status <job_id> Re-query a running/completed transfer
13
16
  # list List all persisted async transfer entries
14
17
  # cleanup Remove completed/failed/cancelled entries
15
18
  #
@@ -22,7 +25,7 @@ module Aspera
22
25
  module TransferActions
23
26
  # Re-query the status of a single async transfer job.
24
27
  # @param job_id [String] UUID returned at submission time
25
- def action_transfer_status(job_id:, **)
28
+ def action_agents_jobs_status(job_id:, **)
26
29
  store = async_transfer_store
27
30
  entry = store.read(job_id)
28
31
  Aspera.assert(!entry.nil?, type: Cli::BadArgument) { "Unknown job_id: #{job_id}" }
@@ -43,7 +46,7 @@ module Aspera
43
46
  private_constant :TERMINAL_STATUSES
44
47
 
45
48
  # Delete completed, failed, and cancelled entries from the store.
46
- def action_transfer_cleanup(**)
49
+ def action_agents_jobs_cleanup(**)
47
50
  store = async_transfer_store
48
51
  deleted = store.list
49
52
  .select { |e| TERMINAL_STATUSES.include?(e['status']) }
@@ -1,14 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'aspera/agent/factory'
4
- require 'aspera/schema/registry'
5
- require 'aspera/cli/option_declarator'
6
- require 'aspera/transfer/result'
7
- require 'aspera/transfer/spec'
8
- require 'aspera/cli/info'
9
- require 'aspera/cli/async_transfer_store'
10
- require 'aspera/log'
11
- require 'aspera/assert'
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'
12
17
  require 'securerandom'
13
18
 
14
19
  module Aspera
@@ -45,7 +50,7 @@ module Aspera
45
50
  extend OptionDeclarator
46
51
 
47
52
  option :ts, description: 'Override transfer spec values', schema: Schema::Registry::TRANSFER_SPEC, on_set: :user_transfer_spec=
48
- option :to_folder, description: 'Destination folder for transferred files'
53
+ option :to_folder, description: 'Destination folder for transferred files', complete: :destination_folder
49
54
  option :sources, description: "How list of transferred files is provided (#{FILE_LIST_OPTIONS.join(',')})", default: FILE_LIST_FROM_ARGS
50
55
  option :src_type, description: 'Type of file list', allowed: %i[list pair], default: :list
51
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
@@ -223,8 +228,8 @@ module Aspera
223
228
 
224
229
  # Start a transfer and wait for completion, plugins shall use this method
225
230
  # @param transfer_spec [Hash] transfer specification
226
- # @param rest_token [Rest::Client, nil] if oauth token regeneration supported
227
- def start(transfer_spec, rest_token: nil)
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)
228
233
  # check parameters
229
234
  Aspera.assert_type(transfer_spec, Hash) { 'transfer_spec' }
230
235
  raise "Wrong remote host: #{CP4I_REMOTE_HOST_LB}" if transfer_spec['remote_host'].eql?(CP4I_REMOTE_HOST_LB)
@@ -251,14 +256,21 @@ module Aspera
251
256
  @user_transfer_spec['paths'] = transfer_spec['paths'] || ts_source_paths
252
257
  # updated transfer spec with command line
253
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']
254
262
  # resolve pseudo-parameter: target_rate -> target_rate_kbps (overrides target_rate_kbps if both are present)
255
- transfer_spec['target_rate_kbps'] = Transfer::Spec.rate_string_to_kbps(transfer_spec.delete('target_rate')) if transfer_spec.key?('target_rate')
263
+ Transfer::Spec.resolve_target_rate(transfer_spec)
256
264
  # recursively remove values that are nil (user wants to delete)
257
265
  transfer_spec.deep_do { |hash, key, value, _unused| hash.delete(key) if value.nil? }
258
266
  # if TS from app has content_protection (e.g. F5), that means content is protected: ask password if not provided
259
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
+ # Renews the bearer token of the transfer: only possible with OAuth
271
+ token_regenerator = -> { oauth_api.oauth.renewed_authorization } if oauth_api&.auth_params&.fetch(:type, nil).eql?(:oauth2)
260
272
  # create transfer agent
261
- agent_instance.start_transfer(transfer_spec, token_regenerator: rest_token)
273
+ agent_instance.start_transfer(transfer_spec, token_regenerator: token_regenerator)
262
274
  # --- async mode ---
263
275
  if transfer_options['asynchronous']
264
276
  agent_type = (transfer_options['agent'] || 'direct').to_s
@@ -281,12 +293,12 @@ module Aspera
281
293
  # (e.g. MCP server mode). The ref is stored in AsyncTransferStore's memory map,
282
294
  # never on disk.
283
295
  async_store.register_agent_ref(job_id, agent_instance) if %w[direct httpgw].include?(agent_type)
284
- # transfer_id: in-process agents use job_id; daemon agents expose @transfer_id
296
+ # transfer_id: in-process agents use job_id; transferd has a reader; other daemon agents keep @transfer_id
285
297
  transfer_id =
286
- if %w[direct httpgw].include?(agent_type)
287
- job_id
288
- else
289
- agent_instance.instance_variable_get(:@transfer_id).to_s
298
+ case agent_type
299
+ when 'direct', 'httpgw' then job_id
300
+ when 'transferd' then agent_instance.transfer_id.to_s
301
+ else agent_instance.instance_variable_get(:@transfer_id).to_s
290
302
  end
291
303
  async_store.write(job_id, {
292
304
  'job_id' => job_id,