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.
Files changed (264) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +4 -4
  3. data/CHANGELOG.md +119 -0
  4. data/CONTRIBUTING.md +8 -1
  5. data/README.md +2 -0
  6. data/TODO.md +4 -5
  7. data/bin/asession +2 -2
  8. data/docs/README.md +616 -86
  9. data/docs/test-mcp-with-ai.md +4 -0
  10. data/lib/aspera/agent/base.rb +62 -6
  11. data/lib/aspera/agent/factory.rb +127 -20
  12. data/lib/aspera/ascp/data_repository.rb +71 -0
  13. data/lib/aspera/ascp/installation.rb +16 -11
  14. data/lib/aspera/ascp/log_analyzer/lines.rb +4 -4
  15. data/lib/aspera/ascp/log_analyzer/log_file.rb +5 -3
  16. data/lib/aspera/ascp/log_analyzer/records.rb +11 -6
  17. data/lib/aspera/ascp/log_analyzer.rb +43 -18
  18. data/lib/aspera/ascp/log_locations.rb +2 -2
  19. data/lib/aspera/assert.rb +8 -0
  20. data/lib/aspera/bundle_registry.rb +528 -0
  21. data/lib/aspera/cli/argument.rb +110 -0
  22. data/lib/aspera/cli/bool_value.rb +41 -0
  23. data/lib/aspera/cli/bootstrapper.rb +31 -24
  24. data/lib/aspera/cli/command/mount.rb +53 -0
  25. data/lib/aspera/cli/command/registry.rb +434 -0
  26. data/lib/aspera/cli/command.rb +95 -0
  27. data/lib/aspera/cli/command_line.rb +91 -91
  28. data/lib/aspera/cli/complete.rb +22 -0
  29. data/lib/aspera/cli/completion_actions.rb +28 -26
  30. data/lib/aspera/cli/context.rb +29 -6
  31. data/lib/aspera/cli/error.rb +39 -0
  32. data/lib/aspera/cli/extended_value.rb +25 -4
  33. data/lib/aspera/cli/formatter.rb +8 -8
  34. data/lib/aspera/cli/hints.rb +17 -52
  35. data/lib/aspera/cli/http.rb +17 -12
  36. data/lib/aspera/cli/mailer.rb +7 -24
  37. data/lib/aspera/cli/mcp/tool.rb +10 -2
  38. data/lib/aspera/cli/option/declarator.rb +80 -0
  39. data/lib/aspera/cli/option/registry.rb +74 -0
  40. data/lib/aspera/cli/option/source.rb +38 -0
  41. data/lib/aspera/cli/option/type.rb +37 -0
  42. data/lib/aspera/cli/option/value.rb +376 -0
  43. data/lib/aspera/cli/option.rb +78 -0
  44. data/lib/aspera/cli/options.schema.yaml +28 -783
  45. data/lib/aspera/cli/parser.rb +73 -41
  46. data/lib/aspera/cli/plugins/base.rb +122 -42
  47. data/lib/aspera/cli/plugins/basic_auth.rb +13 -2
  48. data/lib/aspera/cli/plugins/config.rb +101 -167
  49. data/lib/aspera/cli/plugins/factory.rb +139 -43
  50. data/lib/aspera/cli/plugins/mcp.rb +61 -54
  51. data/lib/aspera/cli/plugins/oauth.rb +19 -6
  52. data/lib/aspera/cli/poll.rb +14 -20
  53. data/lib/aspera/cli/preset_actions.rb +11 -3
  54. data/lib/aspera/cli/preset_manager.rb +16 -6
  55. data/lib/aspera/cli/result.rb +2 -2
  56. data/lib/aspera/cli/runner.rb +71 -99
  57. data/lib/aspera/cli/secret_finder.rb +1 -1
  58. data/lib/aspera/cli/security.rb +102 -4
  59. data/lib/aspera/{preview/terminal.rb → cli/terminal_image.rb} +93 -94
  60. data/lib/aspera/cli/vault_manager.rb +3 -3
  61. data/lib/aspera/cli/version.rb +1 -1
  62. data/lib/aspera/cli/wizard.rb +9 -3
  63. data/lib/aspera/coverage.rb +1 -2
  64. data/lib/aspera/line_logger.rb +35 -6
  65. data/lib/aspera/log.rb +3 -2
  66. data/lib/aspera/oauth/client/base.rb +19 -1
  67. data/lib/aspera/oauth/client/factory.rb +1 -7
  68. data/lib/aspera/plugin.schema.yaml +178 -0
  69. data/lib/aspera/plugins/alee/api.rb +25 -0
  70. data/lib/aspera/{cli/plugins/alee.rb → plugins/alee/commands.rb} +10 -8
  71. data/lib/aspera/plugins/alee/plugin.yaml +3 -0
  72. data/lib/aspera/plugins/aoc/admin_resources.rb +148 -0
  73. data/lib/aspera/plugins/aoc/api.rb +783 -0
  74. data/lib/aspera/{cli/plugins/aoc.rb → plugins/aoc/commands.rb} +404 -330
  75. data/lib/aspera/plugins/aoc/graphql.rb +45 -0
  76. data/lib/aspera/plugins/aoc/plugin.yaml +31 -0
  77. data/lib/aspera/{schema → plugins/aoc/schemas}/IBM Aspera on Cloud API-0.2.6-enhanced.yaml +15042 -7076
  78. data/lib/aspera/plugins/aoc/schemas/options.yaml +47 -0
  79. data/lib/aspera/plugins/ats/api.rb +51 -0
  80. data/lib/aspera/{cli/plugins/ats.rb → plugins/ats/commands.rb} +33 -33
  81. data/lib/aspera/plugins/ats/plugin.yaml +6 -0
  82. data/lib/aspera/plugins/connect/agent.rb +199 -0
  83. data/lib/aspera/plugins/connect/plugin.yaml +11 -0
  84. data/lib/aspera/plugins/connect/schemas/agent_options.yaml +6 -0
  85. data/lib/aspera/{cli/plugins/console.rb → plugins/console/commands.rb} +41 -33
  86. data/lib/aspera/plugins/console/plugin.yaml +8 -0
  87. data/lib/aspera/plugins/cos/api.rb +114 -0
  88. data/lib/aspera/{cli/plugins/cos.rb → plugins/cos/commands.rb} +19 -16
  89. data/lib/aspera/plugins/cos/plugin.yaml +9 -0
  90. data/lib/aspera/plugins/cos/schemas/options.yaml +30 -0
  91. data/lib/aspera/plugins/desktop/agent.rb +165 -0
  92. data/lib/aspera/plugins/desktop/plugin.yaml +11 -0
  93. data/lib/aspera/plugins/desktop/schemas/agent_options.yaml +6 -0
  94. data/lib/aspera/plugins/direct/agent.rb +518 -0
  95. data/lib/aspera/plugins/direct/plugin.yaml +11 -0
  96. data/lib/aspera/plugins/direct/schemas/agent_options.yaml +86 -0
  97. data/lib/aspera/plugins/faspex4/gateway_options.rb +18 -0
  98. data/lib/aspera/plugins/faspex4/gw_servlet.rb +122 -0
  99. data/lib/aspera/plugins/faspex4/plugin.yaml +7 -0
  100. data/lib/aspera/plugins/faspex4/schemas/options.yaml +57 -0
  101. data/lib/aspera/plugins/faspex5/api.rb +269 -0
  102. data/lib/aspera/{cli/plugins/faspex5.rb → plugins/faspex5/commands.rb} +152 -114
  103. data/lib/aspera/plugins/faspex5/faspex4_post_proc_servlet.rb +241 -0
  104. data/lib/aspera/plugins/faspex5/plugin.yaml +14 -0
  105. data/lib/aspera/{schema → plugins/faspex5/schemas}/IBM Aspera Faspex API-5.0-enhanced.yaml +279 -76
  106. data/lib/aspera/plugins/faspex5/schemas/options.yaml +87 -0
  107. data/lib/aspera/{cli/plugins/faspio.rb → plugins/faspio/commands.rb} +11 -7
  108. data/lib/aspera/plugins/faspio/plugin.yaml +8 -0
  109. data/lib/aspera/{schema → plugins/faspio/schemas}/IBM Aspera faspio Gateway API-1.0.0-enhanced.yaml +4 -2
  110. data/lib/aspera/plugins/httpgw/agent.rb +126 -0
  111. data/lib/aspera/plugins/httpgw/api.rb +411 -0
  112. data/lib/aspera/{cli/plugins/httpgw.rb → plugins/httpgw/commands.rb} +9 -9
  113. data/lib/aspera/plugins/httpgw/plugin.yaml +12 -0
  114. data/lib/aspera/plugins/httpgw/schemas/agent_options.yaml +24 -0
  115. data/lib/aspera/plugins/node/agent.rb +184 -0
  116. data/lib/aspera/plugins/node/api.rb +699 -0
  117. data/lib/aspera/{cli/plugins/node.rb → plugins/node/commands.rb} +166 -141
  118. data/lib/aspera/plugins/node/emulator.rb +774 -0
  119. data/lib/aspera/plugins/node/plugin.yaml +20 -0
  120. data/lib/aspera/plugins/node/schemas/agent_options.yaml +20 -0
  121. data/lib/aspera/plugins/node/schemas/options.yaml +190 -0
  122. data/lib/aspera/{cli/plugins/orchestrator.rb → plugins/orchestrator/commands.rb} +139 -110
  123. data/lib/aspera/plugins/orchestrator/plugin.yaml +34 -0
  124. data/lib/aspera/{schema → plugins/orchestrator/schemas}/IBM Aspera Orchestrator API-v1-enhanced.yaml +486 -16
  125. data/lib/aspera/plugins/orchestrator/schemas/options.yaml +143 -0
  126. data/lib/aspera/plugins/orchestrator/workflow_checker.rb +692 -0
  127. data/lib/aspera/{cli/plugins/preview.rb → plugins/preview/commands.rb} +53 -51
  128. data/lib/aspera/plugins/preview/file_types.rb +121 -0
  129. data/lib/aspera/plugins/preview/generator.rb +350 -0
  130. data/lib/aspera/plugins/preview/plugin.yaml +12 -0
  131. data/lib/aspera/{preview/options.schema.yaml → plugins/preview/schemas/options.yaml} +1 -1
  132. data/lib/aspera/plugins/preview/utils.rb +213 -0
  133. data/lib/aspera/plugins/server/ascmd.rb +374 -0
  134. data/lib/aspera/{cli/plugins/server.rb → plugins/server/commands.rb} +48 -32
  135. data/lib/aspera/plugins/server/plugin.yaml +9 -0
  136. data/lib/aspera/plugins/server/schemas/options.yaml +30 -0
  137. data/lib/aspera/{cli/plugins/shares.rb → plugins/shares/commands.rb} +29 -21
  138. data/lib/aspera/plugins/shares/plugin.yaml +10 -0
  139. data/lib/aspera/plugins/shares/shares_web.rb +97 -0
  140. data/lib/aspera/plugins/transferd/agent.rb +258 -0
  141. data/lib/aspera/plugins/transferd/api.rb +180 -0
  142. data/lib/aspera/plugins/transferd/client.rb +67 -0
  143. data/lib/aspera/{cli/plugins/transferd.rb → plugins/transferd/commands.rb} +43 -42
  144. data/lib/aspera/plugins/transferd/config_commands.rb +38 -0
  145. data/lib/aspera/plugins/transferd/plugin.yaml +27 -0
  146. data/lib/aspera/plugins/transferd/product.rb +146 -0
  147. data/lib/aspera/plugins/transferd/schemas/agent_options.yaml +31 -0
  148. data/lib/aspera/plugins/transferd/schemas/options.yaml +80 -0
  149. data/lib/aspera/plugins/transferd/service.rb +617 -0
  150. data/lib/aspera/plugins/xfer/ascp_actions.rb +131 -0
  151. data/lib/aspera/plugins/xfer/ascp_logs_actions.rb +198 -0
  152. data/lib/aspera/plugins/xfer/async_transfer_store.rb +131 -0
  153. data/lib/aspera/plugins/xfer/config_commands.rb +119 -0
  154. data/lib/aspera/plugins/xfer/helper.rb +19 -0
  155. data/lib/aspera/plugins/xfer/plugin.yaml +42 -0
  156. data/lib/aspera/plugins/xfer/schemas/agent_extension.schema.yaml +26 -0
  157. data/lib/aspera/plugins/xfer/schemas/options.yaml +125 -0
  158. data/lib/aspera/plugins/xfer/sync_actions.rb +253 -0
  159. data/lib/aspera/plugins/xfer/transfer_actions.rb +176 -0
  160. data/lib/aspera/plugins/xfer/transfer_agent.rb +505 -0
  161. data/lib/aspera/products/cli_v3.rb +34 -0
  162. data/lib/aspera/products/connect.rb +1 -1
  163. data/lib/aspera/products/drive.rb +29 -0
  164. data/lib/aspera/products/hsts.rb +34 -0
  165. data/lib/aspera/products/transferd.rb +25 -3
  166. data/lib/aspera/products.rb +54 -0
  167. data/lib/aspera/prompt.rb +184 -0
  168. data/lib/aspera/proxy_auto_config.rb +3 -3
  169. data/lib/aspera/rest/aspera_errors.rb +4 -38
  170. data/lib/aspera/rest/error_analyzer.rb +6 -2
  171. data/lib/aspera/rest/list.rb +4 -5
  172. data/lib/aspera/schema/reader.rb +15 -0
  173. data/lib/aspera/schema/registry.rb +239 -45
  174. data/lib/aspera/schema/validator.rb +63 -17
  175. data/lib/aspera/sealed_hash.rb +4 -0
  176. data/lib/aspera/secret/hider.rb +159 -24
  177. data/lib/aspera/secret/reference.rb +8 -0
  178. data/lib/aspera/secret/resolver.rb +8 -4
  179. data/lib/aspera/secret/store/base.rb +10 -9
  180. data/lib/aspera/secret/store/encrypted_hash.rb +6 -6
  181. data/lib/aspera/secret/store/hashicorp_vault.rb +3 -3
  182. data/lib/aspera/secret/store/keeper.rb +2 -2
  183. data/lib/aspera/secret/store/macos_security.rb +2 -3
  184. data/lib/aspera/secret/store/one_password_api.rb +2 -2
  185. data/lib/aspera/secret/store/one_password_cli.rb +3 -3
  186. data/lib/aspera/secret/store/secret_service.rb +2 -2
  187. data/lib/aspera/ssl.rb +3 -3
  188. data/lib/aspera/standard_input.rb +20 -0
  189. data/lib/aspera/{schema → sync}/async_tables.yaml +1 -1
  190. data/lib/aspera/sync/database.rb +7 -0
  191. data/lib/aspera/sync/log_parser.rb +138 -0
  192. data/lib/aspera/sync/operations.rb +59 -34
  193. data/lib/aspera/transfer/command_line_builder.rb +248 -0
  194. data/lib/aspera/transfer/command_line_converter.rb +37 -0
  195. data/lib/aspera/transfer/faux_file.rb +2 -2
  196. data/lib/aspera/transfer/parameters.rb +9 -10
  197. data/lib/aspera/transfer/spec.rb +28 -1
  198. data/lib/aspera/transfer/spec.schema.yaml +30 -5
  199. data/lib/aspera/units/decimal.rb +1 -1
  200. data/lib/aspera/units/timestamp.rb +84 -0
  201. data/lib/aspera/uri_reader.rb +2 -2
  202. data/lib/aspera/web_auth/paste.rb +2 -2
  203. data/lib/aspera/web_server_simple.rb +10 -4
  204. data.tar.gz.sig +0 -0
  205. metadata +137 -80
  206. metadata.gz.sig +0 -0
  207. data/lib/aspera/agent/connect.rb +0 -188
  208. data/lib/aspera/agent/desktop.rb +0 -154
  209. data/lib/aspera/agent/direct.rb +0 -496
  210. data/lib/aspera/agent/httpgw.rb +0 -100
  211. data/lib/aspera/agent/node.rb +0 -166
  212. data/lib/aspera/agent/transferd.rb +0 -341
  213. data/lib/aspera/api/alee.rb +0 -19
  214. data/lib/aspera/api/aoc.rb +0 -776
  215. data/lib/aspera/api/ats.rb +0 -49
  216. data/lib/aspera/api/cos_node.rb +0 -107
  217. data/lib/aspera/api/faspex.rb +0 -258
  218. data/lib/aspera/api/httpgw.rb +0 -409
  219. data/lib/aspera/api/node.rb +0 -684
  220. data/lib/aspera/ascmd.rb +0 -248
  221. data/lib/aspera/cli/ascp_actions.rb +0 -113
  222. data/lib/aspera/cli/ascp_logs_actions.rb +0 -188
  223. data/lib/aspera/cli/async_transfer_store.rb +0 -129
  224. data/lib/aspera/cli/command_registry.rb +0 -371
  225. data/lib/aspera/cli/command_spec.rb +0 -273
  226. data/lib/aspera/cli/option_declarator.rb +0 -74
  227. data/lib/aspera/cli/option_registry.rb +0 -72
  228. data/lib/aspera/cli/option_types.rb +0 -120
  229. data/lib/aspera/cli/option_value.rb +0 -345
  230. data/lib/aspera/cli/prompt.rb +0 -186
  231. data/lib/aspera/cli/sync_actions.rb +0 -181
  232. data/lib/aspera/cli/transfer_actions.rb +0 -98
  233. data/lib/aspera/cli/transfer_agent.rb +0 -348
  234. data/lib/aspera/command_line_builder.rb +0 -244
  235. data/lib/aspera/command_line_converter.rb +0 -35
  236. data/lib/aspera/data_repository.rb +0 -69
  237. data/lib/aspera/faspex_gw.rb +0 -172
  238. data/lib/aspera/faspex_postproc.rb +0 -237
  239. data/lib/aspera/graphql.rb +0 -41
  240. data/lib/aspera/node_emulator.rb +0 -758
  241. data/lib/aspera/oauth/client/shares_web.rb +0 -94
  242. data/lib/aspera/orchestrator_workflow_checker.rb +0 -688
  243. data/lib/aspera/preview/file_types.rb +0 -119
  244. data/lib/aspera/preview/generator.rb +0 -345
  245. data/lib/aspera/preview/utils.rb +0 -211
  246. data/lib/aspera/products/other.rb +0 -92
  247. data/lib/aspera/products/transferd_service.rb +0 -610
  248. /data/lib/aspera/{data → ascp/data}/1 +0 -0
  249. /data/lib/aspera/{data → ascp/data}/2 +0 -0
  250. /data/lib/aspera/{data → ascp/data}/3 +0 -0
  251. /data/lib/aspera/{data → ascp/data}/4 +0 -0
  252. /data/lib/aspera/{data → ascp/data}/5 +0 -0
  253. /data/lib/aspera/{data → ascp/data}/6 +0 -0
  254. /data/lib/aspera/{api → plugins/aoc}/queries/bss_subscription_account.graphql +0 -0
  255. /data/lib/aspera/{api → plugins/aoc}/queries/bss_subscription_usage.graphql +0 -0
  256. /data/lib/aspera/{schema → plugins/aoc/schemas}/IBM Aspera on Cloud Automation API-1.0.5-enhanced.yaml +0 -0
  257. /data/lib/aspera/{schema → plugins/console/schemas}/IBM Aspera Console-enhanced.yaml +0 -0
  258. /data/lib/aspera/{schema → plugins/node/schemas}/IBM Aspera Node API-4.4.6.yaml +0 -0
  259. /data/lib/aspera/{preview → plugins/preview}/image_error.png +0 -0
  260. /data/lib/aspera/{preview → plugins/preview}/video_error.png +0 -0
  261. /data/lib/aspera/{schema → plugins/shares/schemas}/IBM_Aspera_Shares.yaml +0 -0
  262. /data/lib/{transferd_pb.rb → aspera/plugins/transferd/grpc/transferd_pb.rb} +0 -0
  263. /data/lib/{transferd_services_pb.rb → aspera/plugins/transferd/grpc/transferd_services_pb.rb} +0 -0
  264. /data/lib/aspera/{schema → plugins/transferd/schemas}/transferd-config.schema.json +0 -0
@@ -0,0 +1,122 @@
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 '../../hash_ext'
9
+ require_relative '../../secret/strength'
10
+ require_relative '../../servlet_helpers'
11
+ require_relative '../../web_server_simple'
12
+ require 'webrick'
13
+ require 'json'
14
+
15
+ module Aspera
16
+ module Plugins
17
+ module Faspex4
18
+ # Simulate the Faspex 4 /send API; the package is created by the product that starts the gateway (Aspera on Cloud, Faspex 5), see `serve`
19
+ #
20
+ # Security notes:
21
+ # - Packages are created as the user of the application, to any recipient, and the caller receives an upload transfer spec.
22
+ # - Clients authenticate with HTTP Basic, as on Faspex 4, when `username` and `password` are set:
23
+ # they are required when the server listens on an address that is not loopback (checked by `serve`).
24
+ # - Requests that a web page could send are refused (see ServletHelpers#check_request): the body shall be `application/json`.
25
+ class GWServlet < WEBrick::HTTPServlet::AbstractServlet
26
+ include ServletHelpers
27
+
28
+ ALLOWED_PARAMETERS = %i[username password password_min_bits].freeze
29
+ REALM = 'Faspex 4 Gateway'
30
+ private_constant :REALM
31
+
32
+ class << self
33
+ # Check parameters and set defaults
34
+ # Called at startup, so that errors are reported before the first request
35
+ # @param parameters [Hash] Parameters of the servlet
36
+ # @return [Hash] Parameters with defaults
37
+ def normalize_parameters(parameters)
38
+ Aspera.assert_type(parameters, Hash)
39
+ parameters = parameters.symbolize_keys
40
+ not_allowed = parameters.keys - ALLOWED_PARAMETERS
41
+ Aspera.assert(not_allowed.empty?, type: ParameterError) { "unsupported parameters: #{not_allowed.join(', ')}" }
42
+ Aspera.assert(parameters[:username].nil? == parameters[:password].nil?, type: ParameterError) { 'Parameters username and password must be set together' }
43
+ parameters[:password_min_bits] ||= Secret::Strength::DEFAULT_MIN_BITS
44
+ Secret::Strength.assert_strong(parameters[:password], name: 'password', min_bits: parameters[:password_min_bits]) unless parameters[:password].nil?
45
+ parameters
46
+ end
47
+
48
+ # Start the gateway, until signal INT or TERM
49
+ # @param parameters [Hash] Parameters of the server (see `WebServerSimple.url`) and of the servlet (see `normalize_parameters`)
50
+ # @param type [Exception] Exception raised when the server is not protected
51
+ # @yieldreturn [#call] Creates the package in the application, see `initialize`: called once parameters are checked
52
+ def serve(parameters, type: ParameterError)
53
+ servlet_parameters = normalize_parameters(WebServerSimple.servlet_parameters(parameters))
54
+ # Packages can be sent to anyone by anyone who can reach the server
55
+ WebServerSimple.serve(parameters, self, protected: !servlet_parameters[:username].nil?, what: 'username and password', type: type) { [servlet_parameters, yield] }
56
+ end
57
+ end
58
+
59
+ # @param server [WEBrick::HTTPServer] Server
60
+ # @param parameters [Hash] Parameters from `normalize_parameters`
61
+ # @param package_sender [#call] Creates the package in the application: receives the parameters of the Faspex 4 package creation (with `delivery`),
62
+ # returns the transfer spec to upload the package files
63
+ def initialize(server, parameters, package_sender)
64
+ Aspera.assert(package_sender.respond_to?(:call), type: ParameterError) { 'package_sender shall be callable' }
65
+ super(server)
66
+ @expected_auth = "#{parameters[:username]}:#{parameters[:password]}" unless parameters[:username].nil?
67
+ @package_sender = package_sender
68
+ end
69
+
70
+ def do_POST(request, response)
71
+ # Refuse requests of web pages
72
+ check_request(request, json: true)
73
+ return json_error(response, 401, 'Invalid or missing credentials', headers: {'WWW-Authenticate' => %Q(Basic realm="#{REALM}")}) unless authorized?(request)
74
+ return json_error(response, 400, 'Unsupported endpoint') unless request.path.eql?('/aspera/faspex/send')
75
+ faspex_pkg_parameters = package_parameters(request.body)
76
+ Log.dump(:faspex_pkg_parameters, faspex_pkg_parameters)
77
+ # the transfer spec is placed in a Faspex package creation response
78
+ faspex_package_create_result = {
79
+ 'links' => {'status' => 'unused'},
80
+ 'xfer_sessions' => [@package_sender.call(faspex_pkg_parameters)]
81
+ }
82
+ Log.dump(:faspex_package_create_result, faspex_package_create_result)
83
+ json_response(response, 200, faspex_package_create_result)
84
+ rescue WEBrick::HTTPStatus::Error => e
85
+ Log.log.warn { "Rejected request: #{e.message}" }
86
+ json_error(response, e.code, e.message)
87
+ rescue StandardError => e
88
+ # The stack trace is logged only: it is not for the caller
89
+ Log.log.error(e.message)
90
+ Log.log.debug { e.backtrace.join("\n") }
91
+ json_error(response, 500, e.message)
92
+ end
93
+
94
+ private
95
+
96
+ # @param request [WEBrick::HTTPRequest]
97
+ # @return [Boolean] `true` if the request has the expected Basic credentials, or if none are expected
98
+ def authorized?(request)
99
+ @expected_auth.nil? || basic_authorized?(request, @expected_auth)
100
+ end
101
+
102
+ # @param body [String, nil] Body of the request
103
+ # @return [Hash] Parameters of Faspex 4 package creation, with `delivery` and its `recipients`
104
+ # @raise [WEBrick::HTTPStatus::BadRequest] if the body is not a valid package creation request
105
+ def package_parameters(body)
106
+ raise WEBrick::HTTPStatus::BadRequest, 'Empty request' if body.nil?
107
+ parameters =
108
+ begin
109
+ JSON.parse(body)
110
+ rescue JSON::ParserError
111
+ nil
112
+ end
113
+ raise WEBrick::HTTPStatus::BadRequest, 'Request body shall be a JSON object' unless parameters.is_a?(Hash)
114
+ raise WEBrick::HTTPStatus::BadRequest, 'Missing object: delivery' unless parameters['delivery'].is_a?(Hash)
115
+ recipients = parameters['delivery']['recipients']
116
+ raise WEBrick::HTTPStatus::BadRequest, 'delivery.recipients shall be a non-empty list of names' unless recipients.is_a?(Array) && !recipients.empty? && recipients.all?(String)
117
+ parameters
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,7 @@
1
+ name: faspex4
2
+ title: IBM Aspera Faspex 4 gateway
3
+ # Emulation of the Faspex 4 API: the gateway started by the commands `gateway` of aoc and faspex5, which create the package with their own API
4
+ schemas:
5
+ - key: faspex4_opts
6
+ file: schemas/options.yaml
7
+ owned: true
@@ -0,0 +1,57 @@
1
+ openapi: 3.1.0
2
+ info:
3
+ title: Options of bundle faspex4
4
+ version: 1.0.0
5
+ description: Schema definitions of the options of bundle `faspex4`
6
+ license:
7
+ name: Apache-2.0
8
+ identifier: Apache-2.0
9
+ paths: {}
10
+ components:
11
+ schemas:
12
+ Faspex4GatewayOptions:
13
+ description: >-
14
+ Configuration for the Faspex 4 gateway emulator (`faspex5 gateway`, `aoc gateway`).
15
+ The command starts a local HTTP server that accepts Faspex 4 API calls and translates them
16
+ to Faspex 5 / AoC API calls.
17
+ Clients authenticate with HTTP Basic, as on Faspex 4, when `username` and `password` are set.
18
+ By default the server binds to loopback; use a routable address only when clients must reach
19
+ the host from outside: then `username` and `password` are required.
20
+ allOf:
21
+ # Schema of the framework, copied when this file is read: see `Schema::Registry`
22
+ - $ref: "opts:#/components/schemas/WebServerOptions"
23
+ - type: object
24
+ # List properties solely to allow them under additionalProperties: false.
25
+ # Types and descriptions are already defined in WebServerOptions.
26
+ additionalProperties: false
27
+ properties:
28
+ url: {}
29
+ cert: {}
30
+ key: {}
31
+ chain: {}
32
+ username:
33
+ type: string
34
+ description: >-
35
+ Username expected from clients in HTTP Basic authentication.
36
+ Set together with `password`.
37
+ When not set, requests are accepted without authentication.
38
+ Mandatory when `url` is not a loopback address (`localhost`, `127.0.0.0/8`, `::1`).
39
+ examples:
40
+ - fx4_user
41
+ password:
42
+ type: string
43
+ description: >-
44
+ Password expected from clients in HTTP Basic authentication, for the above `username`.
45
+ Generate it with `openssl rand -hex 32`: a weak password is refused (see `password_min_bits`).
46
+ examples:
47
+ - "<PASSWORD>"
48
+ password_min_bits:
49
+ type: integer
50
+ minimum: 0
51
+ default: 80
52
+ description: >-
53
+ Minimum estimated strength of `password`, in bits (log2 of the number of guesses to find it).
54
+ The strength is estimated with gem `zxcvbn` if installed, else with a built-in estimate
55
+ that detects repeats, sequences, keyboard rows, words and years.
56
+ `0` disables the check.
57
+ A random password of 32 bytes (`openssl rand -hex 32`) is far above the default.
@@ -0,0 +1,269 @@
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 '../../rest'
8
+ require_relative '../../oauth/client/base'
9
+ require_relative '../../oauth/client/jwt'
10
+ require_relative '../../oauth/client/web'
11
+ require_relative '../../rest/list'
12
+ require 'digest'
13
+
14
+ module Aspera
15
+ module Plugins
16
+ module Faspex5
17
+ # OAuth for Faspex public link
18
+ class FaspexPubLink < OAuth::Base
19
+ class << self
20
+ attr_accessor :additional_info
21
+ end
22
+ # @param context [String] The `context` query parameter in public link
23
+ # @param redirect_uri [String] URI of web UI login
24
+ # @param path_authorize [String] Path to provide passcode
25
+ # @param base_params [Hash] Parameters for base class
26
+ def initialize(
27
+ context:,
28
+ redirect_uri:,
29
+ path_authorize: 'authorize_public_link',
30
+ **base_params
31
+ )
32
+ # a unique identifier could also be the passcode inside
33
+ super(**base_params, cache_ids: [Digest::SHA256.hexdigest(context)[0..23]])
34
+ @context = context
35
+ @redirect_uri = redirect_uri
36
+ @path_authorize = path_authorize
37
+ end
38
+
39
+ def create_token
40
+ # Exchange context (passcode) for code
41
+ http = api.call(
42
+ operation: 'GET',
43
+ subpath: @path_authorize,
44
+ query: {
45
+ response_type: :code,
46
+ state: @context,
47
+ client_id: params[:client_id],
48
+ redirect_uri: @redirect_uri
49
+ },
50
+ exception: false,
51
+ ret: :resp
52
+ )
53
+ # code / state located in redirected URL query
54
+ info = Rest.query_to_h(URI.parse(http['Location']).query)
55
+ # The code is a credential: hidden wherever it appears, also in this dump
56
+ Secret::Hider.instance.add_secret_values(info['code'])
57
+ Log.dump(:info, info)
58
+ raise AuthenticationError, info['action_message'] if info['action_message']
59
+ Aspera.assert(info['code'], 'Missing code in answer')
60
+ # Exchange code for token
61
+ create_token_base(
62
+ grant_type: 'authorization_code',
63
+ code: info['code'],
64
+ redirect_uri: @redirect_uri
65
+ )
66
+ end
67
+ end
68
+ OAuth::Factory.instance.register_token_creator(FaspexPubLink)
69
+ # Aspera Faspex 5 API Client
70
+ class Api < Rest::Client
71
+ include Rest::List
72
+
73
+ # endpoint for authentication API
74
+ PATH_AUTH = 'auth'
75
+ PATH_API_V5 = 'api/v5'
76
+ PATH_HEALTH = 'configuration/ping'
77
+ RECIPIENT_TYPES = %w[user workgroup external_user distribution_list shared_inbox].freeze
78
+ PACKAGE_TERMINATED = %w[completed failed].freeze
79
+ # list of supported mailbox types (to list packages)
80
+ SENT_MAILBOX_TYPES = %w[outbox outbox_history].freeze
81
+ API_LIST_MAILBOX_TYPES = (%w[inbox inbox_history inbox_all inbox_all_history pending pending_history all] + SENT_MAILBOX_TYPES).freeze
82
+ # PACKAGE_SEND_FROM_REMOTE_SOURCE = 'remote_source'
83
+ # Faspex API v5: get transfer spec for connect
84
+ TRANSFER_CONNECT = 'connect'
85
+ ADMIN_RESOURCES = %i[
86
+ accounts
87
+ distribution_lists
88
+ contacts
89
+ jobs
90
+ workgroups
91
+ shared_inboxes
92
+ nodes
93
+ oauth_clients
94
+ registrations
95
+ saml_configs
96
+ metadata_profiles
97
+ email_notifications
98
+ alternate_addresses
99
+ webhooks
100
+ file_processing
101
+ ].freeze
102
+ # states for jobs not in final state
103
+ JOB_RUNNING = %w[queued working].freeze
104
+ PATH_STANDARD_ROOT = '/aspera/faspex'
105
+ PATH_API_DETECT = "#{PATH_API_V5}/#{PATH_HEALTH}".freeze
106
+ HEADER_X_NEXT_ITER_TOKEN = 'X-Aspera-Next-Iteration-Token'
107
+ HEADER_FASPEX_VERSION = 'X-IBM-Aspera'
108
+ EMAIL_NOTIF_LIST = %w[
109
+ welcome_email
110
+ forgot_password
111
+ package_received
112
+ package_received_cc
113
+ package_sent_cc
114
+ package_downloaded
115
+ package_downloaded_cc
116
+ workgroup_package
117
+ upload_result
118
+ upload_result_cc
119
+ relay_started_cc
120
+ relay_finished_cc
121
+ relay_error_cc
122
+ shared_inbox_invitation
123
+ shared_inbox_submit
124
+ personal_invitation
125
+ personal_submit
126
+ account_approved
127
+ account_denied
128
+ package_file_processing_failed_sender
129
+ package_file_processing_failed_recipient
130
+ relay_failed_admin
131
+ relay_failed
132
+ admin_sync_failed
133
+ sync_failed
134
+ account_exist
135
+ mfa_code
136
+ ].freeze
137
+ class << self
138
+ # @return [Boolean] true if the URL is a public link
139
+ def public_link?(url)
140
+ url.include?('?context=')
141
+ end
142
+
143
+ # Depending on box, the package files are either: `received` or `sent`
144
+ # @return [:sent, :received] the type of mailbox
145
+ def box_type(box)
146
+ SENT_MAILBOX_TYPES.include?(box) || box == 'ALL' ? :sent : :received
147
+ end
148
+ end
149
+ # @return [Hash, nil] public link context decoded from URL (keys: resource, type, id, passcode, package_id, email), or nil if not a public link
150
+ attr_reader :pub_link_context
151
+
152
+ # @param url [String] Faspex URL, can be a public link
153
+ # @param auth [Symbol] Authentication method: :boot (token in header), :web (open browser), :jwt (client_id + private key), :public_link (context in URL)
154
+ # @param root [String] Root path for API
155
+ # @param password [String, nil] For :boot auth, the token copied directly from browser in developer mode
156
+ # @param client_id [String, nil] For :web and :jwt auth, the client_id of web UI application
157
+ # @param client_secret [String, nil] For :web auth, the client_secret of the API client, required if it has HTTP basic auth enabled (not needed for :jwt)
158
+ # @param redirect_uri [String, nil] For :web auth, the redirect_uri of web UI application (must be the same as in application configuration)
159
+ # @param username [String, nil] For :jwt auth, the username of the user to impersonate
160
+ # @param private_key [String, nil] For :jwt auth, the private key to sign JWT token
161
+ # @param passphrase [String, nil] For :jwt auth, the passphrase of the private key
162
+ def initialize(
163
+ url:,
164
+ auth:,
165
+ root: PATH_API_V5,
166
+ password: nil,
167
+ client_id: nil,
168
+ client_secret: nil,
169
+ redirect_uri: nil,
170
+ username: nil,
171
+ private_key: nil,
172
+ passphrase: nil
173
+ )
174
+ auth = :public_link if self.class.public_link?(url)
175
+ # @type [Hash, nil]
176
+ @pub_link_context = nil
177
+ super(**
178
+ case auth
179
+ when :public_link
180
+ # The passcode in the context of the link is a secret, and so is the context (base64 JSON), which reveals it once decoded:
181
+ # declared before any log (URL, `state` of the authorization), as in the URL and decoded
182
+ Secret::Hider.instance.add_secrets_in(url)
183
+ # Get URL of final redirect of provided public link
184
+ final_url = Rest::Client.new(base_url: url, redirect_max: 3).call(operation: 'GET', ret: :resp).uri.to_s
185
+ # Its context, if the link redirects to another one
186
+ Secret::Hider.instance.add_secrets_in(final_url)
187
+ Log.dump(:final_url, final_url, level: :trace1)
188
+ # Get context from query
189
+ encoded_context = Rest.query_to_h(URI.parse(final_url).query)['context']
190
+ Aspera.assert(!encoded_context.nil?, type: ParameterError) { 'Bad faspex5 public link, missing context in query' }
191
+ # public link information (contains passcode and allowed usage)
192
+ @pub_link_context = JSON.parse(Base64.decode64(encoded_context))
193
+ Log.dump(:pub_link_context, @pub_link_context, level: :trace1)
194
+ # Get the base url, i.e. .../aspera/faspex
195
+ base_url = final_url.gsub(%r{/public/.*}, '').gsub(/\?.*/, '')
196
+ # Get web UI client_id and redirect_uri
197
+ # TODO: change this for something more reliable
198
+ config = JSON.parse(Rest::Client.new(base_url: "#{base_url}/config.js", redirect_max: 3).call(operation: 'GET').sub(/^[^=]+=/, '').gsub(/([a-z_]+):/, '"\1":').delete("\n ").tr("'", '"')).symbolize_keys
199
+ Log.dump(:config_js, config)
200
+ {
201
+ base_url: "#{base_url}/#{root}",
202
+ auth: {
203
+ type: :oauth2,
204
+ base_url: "#{base_url}/#{PATH_AUTH}",
205
+ grant_method: :faspex_pub_link,
206
+ context: encoded_context,
207
+ params: {
208
+ client_id: config[:client_id]
209
+ },
210
+ redirect_uri: config[:redirect_uri]
211
+ }
212
+ }
213
+ # old: headers: {'Passcode' => @pub_link_context['passcode']}
214
+ when :boot
215
+ Aspera.assert(password, 'Missing password', type: ParameterError)
216
+ # the password here is the token copied directly from browser in developer mode
217
+ {
218
+ base_url: "#{url}/#{root}",
219
+ headers: {'Authorization' => password}
220
+ }
221
+ when :web
222
+ Aspera.assert(client_id, 'Missing client_id', type: ParameterError)
223
+ Aspera.assert(redirect_uri, 'Missing redirect_uri', type: ParameterError)
224
+ # opens a browser and ask user to auth using web
225
+ {
226
+ base_url: "#{url}/#{root}",
227
+ auth: {
228
+ type: :oauth2,
229
+ base_url: "#{url}/#{PATH_AUTH}",
230
+ grant_method: :web,
231
+ # Faspex 5.0.16+ checks the code verifier, earlier versions ignore it
232
+ pkce: true,
233
+ params: {
234
+ client_id: client_id,
235
+ # required when the API client has HTTP basic auth enabled, else ignored by Faspex
236
+ client_secret: client_secret
237
+ }.compact,
238
+ redirect_uri: redirect_uri
239
+ }
240
+ }
241
+ when :jwt
242
+ Aspera.assert(client_id, 'Missing client_id', type: ParameterError)
243
+ Aspera.assert(private_key, 'Missing private_key', type: ParameterError)
244
+ {
245
+ base_url: "#{url}/#{root}",
246
+ auth: {
247
+ type: :oauth2,
248
+ base_url: "#{url}/#{PATH_AUTH}",
249
+ grant_method: :jwt,
250
+ params: {
251
+ client_id: client_id
252
+ },
253
+ payload: {
254
+ iss: client_id, # issuer
255
+ aud: client_id, # audience (this field is not clear...)
256
+ sub: "user:#{username}" # subject is a user
257
+ },
258
+ private_key_obj: OpenSSL::PKey::RSA.new(private_key, passphrase),
259
+ headers: {typ: 'JWT'}
260
+ }
261
+ }
262
+ else Aspera.error_unexpected_value(auth, type: ParameterError) { 'auth' }
263
+ end
264
+ )
265
+ end
266
+ end
267
+ end
268
+ end
269
+ end