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
@@ -4,9 +4,10 @@
4
4
  # SPDX-License-Identifier: Apache-2.0
5
5
 
6
6
  require_relative '../../assert'
7
+ require_relative '../../log'
8
+ require_relative '../../bundle_registry'
7
9
  require_relative '../error'
8
10
  require_relative '../security'
9
- require_relative '../../environment'
10
11
  require_relative '../../string_ext'
11
12
  require 'singleton'
12
13
 
@@ -14,25 +15,77 @@ module Aspera
14
15
  module Cli
15
16
  # Instantiate plugin from well-known locations
16
17
  module Plugins
18
+ # Plugins that provide commands, from the plugin registry: single files (class `Aspera::Cli::Plugins::<Name>`)
19
+ # and bundles with `commands: true` (class `Aspera::Plugins::<Name>::Commands` in `commands.rb`).
17
20
  # @!method self.instance
18
21
  # Returns the singleton instance of Factory
19
22
  # @return [Factory] the singleton instance
20
23
  class Factory
21
24
  include Singleton
22
25
 
23
- attr_reader :lookup_folders
26
+ # @return [BundleRegistry] Registry of plugins, shared with the domain library
27
+ attr_reader :registry
24
28
 
25
- def initialize
26
- @lookup_folders = []
27
- # Security level (see `Security`) of each folder: a plugin is code
28
- @folder_security = {}
29
- # information on plugins
30
- @plugins = {}
29
+ # @param registry [BundleRegistry] Registry of plugins, its security level checks are those of `Security`
30
+ def initialize(registry: BundleRegistry.instance)
31
+ @registry = registry
32
+ @registry.security_checks(allowed: Security.instance.method(:allowed?), check: Security.instance.method(:check_level))
31
33
  end
32
34
 
33
- # @return [Array<Symbol>] Sorted list of registered plugins
35
+ # @return [Array<String>] Folders where plugins are looked up, the first one with priority
36
+ def lookup_folders = @registry.folders
37
+
38
+ # @return [Array<Symbol>] Sorted list of plugins that provide commands and can be loaded: available, with their gems installed.
39
+ # Callers load the class of each one: `unavailable_plugins` gives the others, with the reason.
34
40
  def plugin_list
35
- @plugins.keys.sort
41
+ @registry.names.select { |name| @registry[name].commands? && @registry.load_error(name).nil? }
42
+ end
43
+
44
+ # @return [Hash{Symbol => String}] Reason why a plugin that provides commands, or whose manifest is invalid, is not in `plugin_list`, by name
45
+ def unavailable_plugins
46
+ listed_plugins.to_h { |name| [name, @registry.load_error(name)] }.compact
47
+ end
48
+
49
+ # @return [Array<Symbol>] Sorted names of the plugins to list: those that provide commands, and those that cannot be loaded (their manifest may be invalid)
50
+ def listed_plugins
51
+ @registry.names.select { |name| @registry[name].commands? || !status_reason(name).nil? }
52
+ end
53
+
54
+ # @param name [Symbol] Name of a registered plugin
55
+ # @return [String] `available`, or why the plugin cannot be loaded: unavailable, or a gem is missing
56
+ def status(name)
57
+ status_reason(name) || 'available'
58
+ end
59
+
60
+ # Description of a registered plugin, for introspection (data only: no code of the plugin is loaded).
61
+ # @param name [Symbol] Name of a registered plugin
62
+ # @return [Hash] `plugin`, `title`, `source` (`gem` or the folder), `form`, `path`, `security`, `status`, `commands`, then for a bundle:
63
+ # `agents`, `schemas`, `mounts`, `services`, `extension_points`, `depends`, `gems`, `missing_gems`
64
+ # @raise [NoSuchElement] If no plugin has this name
65
+ def describe(name)
66
+ plugin = @registry[name]
67
+ Aspera.assert(!plugin.nil?, type: NoSuchElement) { "plugin not found: #{name}" }
68
+ result = {
69
+ plugin: name,
70
+ title: plugin.title,
71
+ source: source_of(plugin),
72
+ form: plugin.form,
73
+ path: plugin.path,
74
+ security: plugin.security || 'any',
75
+ status: status(name),
76
+ commands: plugin.commands?
77
+ }
78
+ return result unless plugin.bundle?
79
+ result.merge(
80
+ agents: plugin.extensions.select { |extension| extension.point.eql?(:agent) }.map { |extension| extension.fields['name'] },
81
+ schemas: plugin.schemas.map(&:key),
82
+ mounts: plugin.mounts.map(&:target),
83
+ services: plugin.services.map(&:name),
84
+ extension_points: plugin.extension_points.keys,
85
+ depends: plugin.depends,
86
+ gems: plugin.gems,
87
+ missing_gems: @registry.missing_gems(name)
88
+ )
36
89
  end
37
90
 
38
91
  # add a folder to the list of folders to look for plugins
@@ -41,45 +94,40 @@ module Aspera
41
94
  # @param security [Symbol, nil] Most restrictive security level at which plugins of this folder are used, `nil` for all levels (folder of the gem).
42
95
  # A folder that a user or a client can write is `:low`: a file written there would be loaded as code.
43
96
  def add_lookup_folder(folder, security: nil)
44
- folder = File.expand_path(folder)
45
- @folder_security[folder] = security
46
- @lookup_folders.unshift(folder) unless @lookup_folders.include?(folder)
97
+ @registry.add_source(folder, security: security, ignore: IGNORE_PLUGINS, last: File.identical?(folder, GEM_SINGLE_FILES_FOLDER))
47
98
  end
48
99
 
49
100
  # find plugins in defined paths
50
101
  def add_plugins_from_lookup_folders
51
- @lookup_folders.each do |folder|
52
- next unless File.directory?(folder)
53
- # Plugins registered at start (level low) stay, but files that appear later are not
54
- next unless Security.instance.allowed?(@folder_security[folder])
55
- # TODO: add gem root to load path ? and require short folder ?
56
- # $LOAD_PATH.push(folder) if i[:add_path]
57
- Dir.children(folder).each do |source|
58
- next unless source.end_with?(Environment::RB_EXT)
59
- path = File.join(folder, source)
60
- plugin_symbol = File.basename(path, Environment::RB_EXT).to_sym
61
- next if IGNORE_PLUGINS.include?(plugin_symbol)
62
- req = path.sub(/#{Environment::RB_EXT}$/o, '')
63
- next if @plugins.key?(plugin_symbol)
64
- @plugins[plugin_symbol] = {source: path, require_stanza: req, security: @folder_security[folder]}
65
- end
66
- end
67
- end
68
-
69
- # @return [String] path to source file of plugin
70
- def plugin_source(plugin_name_sym)
71
- Aspera.assert(@plugins.key?(plugin_name_sym), type: NoSuchElement) { "plugin not found: #{plugin_name_sym}" }
72
- @plugins[plugin_name_sym][:source]
102
+ @registry.scan
73
103
  end
74
104
 
75
- # @return [Class] class object for plugin
105
+ # @return [Class] class object for plugin, with its plugin name set and the modules mounted on it by bundles included
76
106
  def plugin_class(plugin_name_sym)
77
- Aspera.assert(@plugins.key?(plugin_name_sym), type: NoSuchElement) { "plugin not found: #{plugin_name_sym}" }
78
- # A plugin registered at start can be replaced by a file written since: it is code
79
- Security.instance.check_level(@plugins[plugin_name_sym][:security], "plugin #{plugin_name_sym}")
80
- require @plugins[plugin_name_sym][:require_stanza]
81
- # Module.nesting[1] is Aspera::Cli::Plugins
82
- return Object.const_get("#{Module.nesting[1]}::#{plugin_name_sym.to_s.snake_to_capital}")
107
+ plugin = command_plugin(plugin_name_sym)
108
+ klass =
109
+ case plugin.form
110
+ when :single
111
+ @registry.require_code(plugin_name_sym)
112
+ # Module.nesting[1] is Aspera::Cli::Plugins
113
+ Object.const_get("#{Module.nesting[1]}::#{plugin_name_sym.to_s.snake_to_capital}")
114
+ when :bundle
115
+ @registry.load_constant(plugin_name_sym, COMMANDS_FILE, COMMANDS_CLASS)
116
+ else Aspera.error_unexpected_value(plugin.form)
117
+ end
118
+ klass.plugin_name = plugin_name_sym.to_s
119
+ klass.include_mounts(@registry)
120
+ klass
121
+ rescue BundleRegistry::Unavailable => e
122
+ raise Cli::Error, e.message
123
+ rescue NameError, LoadError, SyntaxError => e
124
+ # Broken code of a plugin of the gem is a bug of ascli: reported as such, with its location
125
+ raise if !plugin.nil? && source_of(plugin).eql?('gem')
126
+ # Else only the error of the plugin itself: not a bug of the gem code that it calls (DSL of `Base`, `use_options`, mounts), which is reported as such
127
+ raise unless plugin_error?(plugin, e)
128
+ # Broken code of an external plugin (no `commands.rb`, wrong constant, syntax error): same error as an unavailable plugin
129
+ Log.log.debug { "plugin #{plugin_name_sym}: #{e.class}: #{e.message}" }
130
+ raise Cli::Error, "plugin #{plugin_name_sym} cannot be loaded: #{e.class}: #{e.message}"
83
131
  end
84
132
 
85
133
  # Create specified plugin
@@ -90,8 +138,56 @@ module Aspera
90
138
  plugin_class(plugin_name_sym).new(**args)
91
139
  end
92
140
 
141
+ private
142
+
143
+ # @param plugin [BundleRegistry::Plugin, nil] External plugin that is loaded
144
+ # @param error [NameError, LoadError, SyntaxError] Error raised while it is loaded
145
+ # @return [Boolean] `true` if the error comes from the plugin itself: a `LoadError` (no file) or `SyntaxError` of its files,
146
+ # or a `NameError` raised from a file of the plugin, or by the lookup of its class (wrong constant)
147
+ def plugin_error?(plugin, error)
148
+ return true if error.is_a?(LoadError) || error.is_a?(SyntaxError)
149
+ # `const_get` (and `const_missing` on JRuby) may or may not be a location, according to the Ruby version and tools (coverage)
150
+ # `base_label` is the method name alone: `label` is qualified (`Class#method`) only from Ruby 3.4
151
+ location = error.backtrace_locations&.find { |loc| !%w[const_get const_missing].include?(loc.base_label) }
152
+ return false if plugin.nil? || location.nil?
153
+ # The class is searched by name (a wrong constant): the first location is the lookup of the loader
154
+ return true if error.instance_of?(NameError) && %w[load_constant plugin_class].include?(location.base_label) && [__FILE__, BundleRegistry.instance_method(:load_constant).source_location.first].include?(location.path)
155
+ path = File.realpath(plugin.path)
156
+ file = File.expand_path(location.absolute_path || location.path)
157
+ file.eql?(path) || file.start_with?(File.join(path, ''))
158
+ end
159
+
160
+ # @param name [Symbol] name of a registered plugin
161
+ # @return [String, nil] Why the plugin cannot be loaded, short form: unavailable reason, or missing gems; `nil` if it can
162
+ def status_reason(name)
163
+ reason = @registry.unavailable_reason(name)
164
+ return reason unless reason.nil?
165
+ missing = @registry.missing_gems(name)
166
+ missing.empty? ? nil : "missing gem #{missing.join(', ')}"
167
+ end
168
+
169
+ # @param plugin [BundleRegistry::Plugin] Registered plugin
170
+ # @return [String] `gem` if in the gem, else the folder where it was found
171
+ def source_of(plugin)
172
+ folder = File.dirname(plugin.path)
173
+ [BundleRegistry::GEM_FOLDER, GEM_SINGLE_FILES_FOLDER].any? { |gem_folder| File.identical?(folder, gem_folder) } ? 'gem' : folder
174
+ end
175
+
176
+ # @param plugin_name_sym [Symbol] name of plugin
177
+ # @return [BundleRegistry::Plugin] Registered plugin that provides commands
178
+ def command_plugin(plugin_name_sym)
179
+ plugin = @registry[plugin_name_sym]
180
+ Aspera.assert(plugin&.commands?, type: NoSuchElement) { "plugin not found: #{plugin_name_sym}" }
181
+ plugin
182
+ end
183
+
93
184
  IGNORE_PLUGINS = %i[factory base basic_auth oauth].freeze
94
- private_constant :IGNORE_PLUGINS
185
+ # Folder of the single files of the gem: `config`, `mcp`
186
+ GEM_SINGLE_FILES_FOLDER = File.dirname(File.expand_path(__FILE__))
187
+ # Commands of a bundle
188
+ COMMANDS_FILE = 'commands.rb'
189
+ COMMANDS_CLASS = 'Commands'
190
+ private_constant :IGNORE_PLUGINS, :GEM_SINGLE_FILES_FOLDER, :COMMANDS_FILE, :COMMANDS_CLASS
95
191
  end
96
192
  end
97
193
  end
@@ -64,19 +64,18 @@ module Aspera
64
64
  (e.g. `ascli plugin command --option=value`).
65
65
  INST
66
66
 
67
- # Default instructions shown to the AI client when none are provided by the user.
68
- DEFAULT_INSTRUCTIONS = <<~INST.strip
67
+ # Instructions shown to the AI client when none are provided by the user (see `default_instructions`): start
68
+ INSTRUCTIONS_START = <<~INST.strip
69
69
  This is the Aspera CLI (ascli) MCP server (IBM Aspera file transfer and management).
70
70
  It exposes a single tool, execute_ascli_command, which runs any ascli command in-process.
71
71
  Its description gives the syntax and the discovery sequence: follow it before any
72
72
  command whose syntax you have not verified in this session.
73
73
 
74
74
  #{COMMAND_DISPLAY_INSTRUCTIONS}
75
+ INST
75
76
 
76
- Plugins: aoc (Aspera on Cloud), faspex5 (Faspex 5), node (Node API), server (FASP/SSH
77
- server), config (local configuration), console, orchestrator, ats, preview, shares,
78
- cos, httpgw, faspio, alee.
79
-
77
+ # Instructions after the list of plugins, before the sections of the bundles
78
+ CREDENTIALS_INSTRUCTIONS = <<~INST.strip
80
79
  CREDENTIALS
81
80
  Use saved presets by default: call ["config", "preset", "overview"] first, then pass
82
81
  --preset=<name>, or nothing if a default preset exists for the plugin.
@@ -86,51 +85,57 @@ module Aspera
86
85
  For a secret the user did not give (password, passphrase), pass "@secret:<name>" as value:
87
86
  the user enters it on a web page, you never see it. Prefer it to asking in the conversation.
88
87
  On error, report it as-is and stop.
88
+ INST
89
89
 
90
- TRANSFERS
91
- Pass verbatim any flag the user requests (--transfer.agent=<agent>, --to-folder, …).
92
- Agents: direct (default, in-process ascp), desktop (IBM Aspera Desktop Client,
93
- graphical), node, transferd, httpgw, connect.
94
- Transfers are asynchronous: the command returns a job_id immediately — never retry it.
95
- monitor → ["config", "transfer", "status", "<job_id>"]
96
- list → ["config", "transfer", "list"]
97
- cleanup → ["config", "transfer", "cleanup"]
98
-
99
- ORCHESTRATOR WORKFLOW DEVELOPMENT
100
- Before writing or modifying an Orchestrator workflow, read the development guide (large: read
101
- sections, not the whole document). Start with the sections "quick-start" and "authoring-checklist":
102
- ["orchestrator", "workflows", "development", "guide", "section", "authoring-checklist"]
103
- then the sections you need (file format, graph, inputs of steps, execution, recipes, known issues):
104
- "workflow-file", "graph-xml", "inputs-of-a-step", "execution", "recipes", "known-issues".
105
- Command "toc" lists the anchors of the sections of a document, up to a default level, or the level
106
- given after it:
107
- ["orchestrator", "workflows", "development", "guide", "toc"]
108
- For the template attributes (allowed values), inputs and outputs of an action plugin, and the
109
- template settings they depend on, read its specification (fields: section "plugin-specifications"
110
- of the development guide); the list of plugins is given by ["orchestrator", "plugins", "spec", "toc"]:
111
- ["orchestrator", "plugins", "spec", "show", "<PluginClass>"]
112
- For the functional description and the setup of a plugin (for example the API client of Faspex),
113
- read its section of the Plugin Manual (large: read one section only). The anchor of the section is
114
- field "manual_anchor" of the specification of the plugin (also in the list of plugins):
115
- ["orchestrator", "workflows", "development", "manual", "section", "<manual_anchor>"]
116
- Before importing a workflow file, check it (graph, templates, inputs of steps) and fix all errors:
117
- ["orchestrator", "workflows", "check_import", "<file>"]
118
-
119
- AOC AUTOMATION WORKFLOW DEVELOPMENT
120
- Before writing or modifying an Aspera on Cloud Automation workflow, read the development guide
121
- (large: read sections, not the whole document). Start with the section of each trigger and action
122
- used (for example "Send a package" is action type package_transfer, section "package-transfer"),
123
- then "payload-rules-enforced-by-the-api" and "finding-the-identifiers":
124
- ["aoc", "automation", "guide", "section", "package-transfer"]
125
- Other sections: "triggers", "actions", "substitution-variables", "importing-a-workflow",
126
- "design-recipes-and-patterns", "common-pitfalls-and-resolutions". List the anchors with:
127
- ["aoc", "automation", "guide", "toc"]
128
-
90
+ # Instructions after the sections of the bundles
91
+ INSTRUCTIONS_END = <<~INST.strip
129
92
  GENERAL GUIDANCE
130
93
  For the general rules of use of ascli by an AI (written for a shell: each command line maps to args):
131
94
  ["config", "skill"]
132
95
  INST
133
96
 
97
+ # Description of the plugins of the framework in the list of plugins (a bundle has its title)
98
+ FRAMEWORK_PLUGINS = {config: 'local configuration'}.freeze
99
+ # In the section of a bundle (manifest `mcp`): list of the names of the entries of an extension point (and the title of their bundle), e.g. `%{agent}`
100
+ POINT_PLACEHOLDER = /%\{([a-z][a-z0-9_]*)\}/
101
+
102
+ class << self
103
+ # Instructions shown to the AI client when none are provided by the user:
104
+ # generic text, list of the plugins (with the title of their bundle), and the section of each bundle that has one (manifest `mcp`)
105
+ # @param factory [Factory] Plugins and their bundles
106
+ # @return [String] Instructions
107
+ def default_instructions(factory = Factory.instance)
108
+ registry = factory.registry
109
+ plugins = factory.plugin_list.reject { |name| name.eql?(:mcp) }.sort.map do |name|
110
+ described(name, registry[name].title || FRAMEWORK_PLUGINS[name])
111
+ end
112
+ sections = registry.names.filter_map do |name|
113
+ next unless registry.unavailable_reason(name).nil?
114
+ registry[name].mcp&.strip&.gsub(POINT_PLACEHOLDER) { bundles_of_point(registry, Regexp.last_match(1).to_sym) }
115
+ end
116
+ [INSTRUCTIONS_START, "Plugins: #{plugins.join(', ')}.", CREDENTIALS_INSTRUCTIONS, *sections, INSTRUCTIONS_END].join("\n\n")
117
+ end
118
+
119
+ private
120
+
121
+ # @param name [Symbol] Name of a plugin or bundle
122
+ # @param description [String, nil] Its description
123
+ # @return [String] The name, followed by the description in parentheses if any
124
+ def described(name, description)
125
+ description.nil? ? name.to_s : "#{name} (#{description})"
126
+ end
127
+
128
+ # @param registry [BundleRegistry] Registry of the bundles
129
+ # @param point [Symbol] Name of an extension point
130
+ # @return [String] Names of the entries of the extension point (field `name`, e.g. the value of `--transfer.agent` for agents), with the title of their bundle
131
+ def bundles_of_point(registry, point)
132
+ registry.extensions(point).map do |entry|
133
+ Aspera.assert(entry.fields.key?('name')) { "extension #{point} of #{entry.bundle}: no field name" }
134
+ described(entry.fields['name'], registry[entry.bundle].title)
135
+ end.join(', ')
136
+ end
137
+ end
138
+
134
139
  # Keys forwarded to MCP::Server constructor (symbolized)
135
140
  SERVER_KEYS = %i[instructions description].freeze
136
141
  # Keys forwarded to MCP::Configuration
@@ -144,7 +149,7 @@ module Aspera
144
149
  # Keys consumed locally (not forwarded to MCP gem)
145
150
  TOOL_KEYS = %i[max_text_bytes extra_args].freeze
146
151
  # Extended-value handlers disabled in MCP server mode whatever the security level:
147
- # @stdin: is the JSON-RPC stream (stdio).
152
+ # @stdin: is the JSON-RPC stream (stdio), and so is the argument `-` of a command that reads the standard input as a file: `@stdin:stream` (`Argument#stdin`).
148
153
  # Other unsafe handlers depend on the security level, see Security.
149
154
  # @secret: is entered on a web page instead of the terminal, see Mcp::Secrets.
150
155
  DISABLED_EXTENDED_VALUE_HANDLERS = %i[stdin].freeze
@@ -158,20 +163,21 @@ module Aspera
158
163
  def action_server(mcp_options: nil, **)
159
164
  require_relative '../mcp/tool'
160
165
  require_relative '../extended_value'
166
+ # Keys and values checked by the schema of the argument
161
167
  mcp_options = (mcp_options || {}).transform_keys(&:to_sym)
162
- unknown = mcp_options.keys - SERVER_KEYS - CONFIG_KEYS - STDIO_KEYS - HTTP_KEYS - HTTP_SERVER_KEYS - TOOL_KEYS - %i[transport]
163
- Aspera.assert(unknown.empty?, type: Cli::BadArgument) { "Unknown MCP option(s): #{unknown.join(', ')}" }
164
168
  Cli::Mcp::Tool.max_text_bytes = mcp_options.delete(:max_text_bytes)
165
169
  Cli::Mcp::Tool.extra_args = mcp_options.delete(:extra_args)
170
+ # Commands of the client use the main folder of the server (set by option `home`, env or default), and its configuration file (option `config_file`)
171
+ Cli::Mcp::Tool.main_folder = context.main_folder
172
+ Cli::Mcp::Tool.config_file = context.presets.config_file
173
+ # and its vault, options `vault` and `vault_password` (the stores of `@vault:`), not chosen by the client
174
+ Cli::Mcp::Tool.vault = options.get_option(:vault, mandatory: false)
175
+ Cli::Mcp::Tool.vault_password = options.get_option(:vault_password, mandatory: false)
166
176
  transport = mcp_options.delete(:transport) || 'stdio'
167
- raise Cli::BadArgument, "Unknown transport: #{transport}. Use 'stdio' or 'http'" \
168
- unless %w[stdio http].include?(transport.to_s)
169
177
  # Options of the other transport would be ignored
170
178
  ignored = mcp_options.keys & (transport.to_s.eql?('stdio') ? HTTP_KEYS + HTTP_SERVER_KEYS : STDIO_KEYS)
171
179
  Aspera.assert(ignored.empty?, type: Cli::BadArgument) { "MCP option(s) not used with transport #{transport}: #{ignored.join(', ')}" }
172
- DISABLED_EXTENDED_VALUE_HANDLERS.each do |handler|
173
- ExtendedValue.instance.on(handler) { |_| raise Cli::BadArgument, "@#{handler}: extended value is disabled in MCP server mode" }
174
- end
180
+ DISABLED_EXTENDED_VALUE_HANDLERS.each { |handler| ExtendedValue.instance.disable(handler, 'in MCP server mode') }
175
181
  ExtendedValue.instance.on(:secret) { |prompt| Cli::Mcp::Secrets.value(prompt) }
176
182
  # Applies to commands of the client, and to presets, which the client can modify
177
183
  Security.instance.lock('in MCP server mode', default: DEFAULT_SECURITY_LEVEL)
@@ -189,7 +195,7 @@ module Aspera
189
195
  tool = Cli::Mcp::Tool
190
196
  config_opts = mcp_options.slice(*CONFIG_KEYS)
191
197
  server_opts = mcp_options.slice(*SERVER_KEYS)
192
- server_opts[:instructions] ||= DEFAULT_INSTRUCTIONS
198
+ server_opts[:instructions] ||= self.class.default_instructions
193
199
  server_opts[:description] ||= "#{Info::GEM_NAME} MCP server (IBM Aspera file transfer and management)"
194
200
  configuration = config_opts.empty? ? nil : MCP::Configuration.new(**config_opts)
195
201
  MCP::Server.new(
@@ -216,6 +222,7 @@ module Aspera
216
222
  MCP::Server::Transports::StdioTransport.new(server, **stdio_opts).open
217
223
  when :http
218
224
  start_http_transport(server, mcp_options)
225
+ else Aspera.error_unexpected_value(transport) { 'MCP transport' }
219
226
  end
220
227
  end
221
228
 
@@ -12,7 +12,7 @@ module Aspera
12
12
  # Options of OAuth web authentication (authorization code): client and redirect URI.
13
13
  # For a plugin that uses only this flow: `use_options OauthWebOptions` (without the options of `Oauth`)
14
14
  module OauthWebOptions
15
- extend OptionDeclarator
15
+ extend Option::Declarator
16
16
  option :client_id, description: 'OAuth client identifier'
17
17
  option :client_secret, description: 'OAuth client secret'
18
18
  option :redirect_uri, description: 'OAuth (Web) redirect URI for web authentication'
@@ -20,14 +20,29 @@ module Aspera
20
20
 
21
21
  # Options of OAuth JWT authentication: private key
22
22
  module OauthJwtOptions
23
- extend OptionDeclarator
23
+ extend Option::Declarator
24
24
  option :private_key, description: 'OAuth (JWT) RSA private key PEM value (prefix file path with @file:)'
25
25
  option :passphrase, description: 'OAuth (JWT) RSA private key passphrase'
26
26
  end
27
27
 
28
- # base class for applications supporting OAuth 2.0 authentication
29
- class Oauth < BasicAuth
28
+ # Module for plugins of applications supporting OAuth 2.0 authentication: `include Cli::Plugins::Oauth` in a plugin class.
29
+ # Includes `BasicAuth`. Its `included` hook gives the options of the module, `OauthWebOptions`, `OauthJwtOptions` and `BasicAuth` to the plugin class.
30
+ module Oauth
31
+ extend Option::Declarator
32
+ include BasicAuth
33
+
30
34
  class << self
35
+ # @param base [Class] Plugin class that includes the module
36
+ def included(base)
37
+ super
38
+ # A module that includes `Oauth` has no options to declare
39
+ return unless base.is_a?(Class)
40
+ base.use_options(self)
41
+ base.use_options(OauthWebOptions)
42
+ base.use_options(OauthJwtOptions)
43
+ base.use_options(BasicAuth)
44
+ end
45
+
31
46
  # Get command line `options` specified by `AUTH_OPTIONS`
32
47
  # @param options [Cli::Parser] Object to get command line options.
33
48
  # @return [Hash{Symbol => Object}] Options
@@ -49,8 +64,6 @@ module Aspera
49
64
  # Options used for authentication (url, auth, client_id, etc...)
50
65
  AUTH_OPTIONS = %i[url auth client_id client_secret redirect_uri private_key passphrase username password].freeze
51
66
  option :auth, description: 'OAuth type of authentication', allowed: AUTH_TYPES, default: :jwt
52
- use_options OauthWebOptions
53
- use_options OauthJwtOptions
54
67
  end
55
68
  end
56
69
  end
@@ -18,8 +18,6 @@ module Aspera
18
18
  # once or several times, and each result is displayed according to `show`.
19
19
  # The command is not executed by `Runner#run_with_result` (MCP server): only by `Runner#run`, which displays the result.
20
20
  class Poll < Result
21
- # Parameters of option `poll`, see schema `PollOptions`
22
- PARAMETERS = %i[interval max timeout until show errors].freeze
23
21
  # Values of parameter `show`
24
22
  SHOW_MODES = %i[change each last].freeze
25
23
  # Values of parameter `errors`
@@ -40,7 +38,7 @@ module Aspera
40
38
  def isatty = tty?
41
39
  def winsize = @terminal.winsize
42
40
  end
43
- private_constant :PARAMETERS, :SHOW_MODES, :ERROR_MODES, :DEFAULT_INTERVAL, :Capture
41
+ private_constant :SHOW_MODES, :ERROR_MODES, :DEFAULT_INTERVAL, :Capture
44
42
 
45
43
  class << self
46
44
  # Truth of a JMESPath value: `false`, `null`, empty string, empty list and empty object are false
@@ -68,29 +66,23 @@ module Aspera
68
66
  end
69
67
  end
70
68
 
71
- # Parameters are checked before the first run.
69
+ # Parameters are checked before the first run: keys, types and values by the schema of the option, the rest here.
72
70
  # @param parameters [Hash] Value of option `poll`, see schema `PollOptions`
73
71
  # @param format [Symbol] Output format (`--format`)
74
72
  # @raise [Cli::BadArgument] if a parameter is invalid
75
73
  def initialize(parameters, format: nil)
76
74
  super()
77
- Aspera.assert_type(parameters, Hash, type: BadArgument) { 'poll' }
78
- parameters = parameters.transform_keys(&:to_sym)
79
- unknown = parameters.keys - PARAMETERS
80
- raise BadArgument, "poll: unknown parameter: #{unknown.join(', ')}, expecting: #{PARAMETERS.join(', ')}" unless unknown.empty?
75
+ # A `null` value removes the entry (as for all options): the parameter is absent, its default applies
76
+ parameters = parameters.transform_keys(&:to_sym).compact
81
77
  # Nagios plugins exit after the first result
82
78
  raise BadArgument, 'poll: not with format nagios' if format.eql?(:nagios)
83
79
  @interval = seconds(parameters.fetch(:interval, DEFAULT_INTERVAL), :interval)
84
80
  @max = parameters[:max]
85
- Aspera.assert(@max.nil? || (@max.is_a?(Integer) && @max.positive?), type: BadArgument) { "poll.max: expecting a positive integer, not #{@max.inspect}" }
86
81
  @timeout = parameters[:timeout].nil? ? nil : seconds(parameters[:timeout], :timeout)
87
82
  @until = parameters[:until]
88
- Aspera.assert_type(@until, String, NilClass, type: BadArgument) { 'poll.until' }
89
83
  Formatter.check_jmespath(@until, 'poll.until') unless @until.nil?
90
- @show = parameters.fetch(:show, SHOW_MODES.first).to_s.to_sym
91
- Aspera.assert_values(@show, SHOW_MODES, type: BadArgument) { 'poll.show' }
92
- @errors = parameters.fetch(:errors, ERROR_MODES.first).to_s.to_sym
93
- Aspera.assert_values(@errors, ERROR_MODES, type: BadArgument) { 'poll.errors' }
84
+ @show = parameters.fetch(:show, SHOW_MODES.first).to_sym
85
+ @errors = parameters.fetch(:errors, ERROR_MODES.first).to_sym
94
86
  # Set by the dispatcher: executes the command, and returns its result
95
87
  @action = nil
96
88
  end
@@ -121,8 +113,11 @@ module Aspera
121
113
  begin
122
114
  result = @action.call
123
115
  rescue StandardError => e
124
- raise if @errors.eql?(:fail)
125
- error = e
116
+ case @errors
117
+ when :fail then raise
118
+ when :retry then error = e
119
+ else Aspera.error_unexpected_value(@errors) { 'poll.errors' }
120
+ end
126
121
  status(formatter, "poll: run #{run}#{"/#{@max}" unless @max.nil?} #{timestamp} error: #{e.message}")
127
122
  end
128
123
  if error.nil?
@@ -133,6 +128,7 @@ module Aspera
133
128
  when :each then display(formatter, run, output)
134
129
  when :change then display(formatter, run, output) unless output.eql?(previous)
135
130
  when :last then last = [run, output]
131
+ else Aspera.error_unexpected_value(@show) { 'poll.show' }
136
132
  end
137
133
  previous = output
138
134
  end
@@ -162,10 +158,8 @@ module Aspera
162
158
  # @param name [Symbol] Parameter name, for errors
163
159
  # @return [Integer] Seconds
164
160
  def seconds(value, name)
165
- Aspera.assert_type(value, Numeric, String, type: BadArgument) { "poll.#{name}" }
166
- value = Units::Duration.new(value).to_unit('s')
167
- Aspera.assert(!value.negative?, type: BadArgument) { "poll.#{name}: must not be negative" }
168
- value
161
+ # The schema checks that a number is not negative, `Duration` refuses a negative text
162
+ Units::Duration.new(value).to_unit('s')
169
163
  rescue ParameterError => e
170
164
  raise BadArgument, "poll.#{name}: #{e.message}"
171
165
  end
@@ -44,13 +44,20 @@ module Aspera
44
44
  def action_preset_lookup(criteria:, **)
45
45
  Aspera.assert((criteria.keys - LOOKUP_KEYS).empty? && (LOOKUP_KEYS - criteria.keys).empty?, type: BadArgument) { "Expected keys: #{LOOKUP_KEYS.join(', ')}" }
46
46
  result = presets.lookup_preset(url: criteria['url'], username: criteria['username'])
47
- Aspera.assert(!result.nil?, type: Error) { 'no such config found' }
47
+ Aspera.assert(!result.nil?, type: EntityNotFound) { 'no such config found' }
48
48
  Result::SingleObject.new(result)
49
49
  end
50
50
 
51
51
  def action_preset_secure(config_name: nil, **)
52
52
  cp = presets.config_presets
53
- preset_names = config_name.nil? ? cp.keys : [config_name]
53
+ preset_names =
54
+ if config_name.nil?
55
+ cp.keys
56
+ else
57
+ config_name = preset_name(config_name)
58
+ raise Cli::BadArgument, "no such preset: #{config_name}" unless cp.key?(config_name)
59
+ [config_name]
60
+ end
54
61
  preset_names.each do |preset_name|
55
62
  preset = cp[preset_name]
56
63
  next unless preset.is_a?(Hash)
@@ -142,7 +149,8 @@ module Aspera
142
149
  value = ExtendedValue.instance.evaluate(value.to_s, context: 'preset')
143
150
  # A secret has no key name in a text result: declared, so that it is hidden
144
151
  Secret::Hider.instance.add_secret_values(value) if Secret::Hider.instance.secret?(param_name, value)
145
- return Result::Text.new(value)
152
+ # The value of an extended value can be of another type, e.g. `null` for `@none:`, a list for `@json:`
153
+ return Result.auto(value)
146
154
  end
147
155
  Result::SingleObject.new(value)
148
156
  end