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
@@ -1,74 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: IBM Corp.
4
- # SPDX-License-Identifier: Apache-2.0
5
-
6
- require_relative 'command_spec'
7
-
8
- module Aspera
9
- module Cli
10
- # Mixin providing declarative CLI option definitions (`option :name, ...`)
11
- # and batch declaration onto a Parser instance (`declare_options(parser)`).
12
- module OptionDeclarator
13
- # Registry of OptionSpec objects defined on this class/module.
14
- # @return [Hash{Symbol => OptionSpec}]
15
- def option_specs
16
- @option_specs ||= {}
17
- end
18
-
19
- # Declare an option in this class's registry.
20
- #
21
- # @param name [Symbol] Option name
22
- # @param description [String, nil] User-facing description; if nil, derived from schema: title/description
23
- # @param short [String, nil] Single-character short form (without leading '-')
24
- # @param allowed [Object, nil] Allowed values (see OptionValue)
25
- # @param default [Object, nil] Default value
26
- # @param on_set [Symbol, Proc, #call, nil] `on_set` callback (see OptionSpec)
27
- # @param shorthand [String, nil] For a `Hash` option: a `String` value is stored as `{shorthand => value}`
28
- # @param deprecation [Hash, nil] Deprecation `{last:, message:}` forwarded to options.declare (see `Deprecation`)
29
- # @param schema [String, nil] Schema reference (e.g. "opts:components.schemas.Foo");
30
- # when description: is nil, the schema title or first description line is used
31
- # @param complete [Symbol, nil] Values proposed by shell completion, one of `Complete::KINDS`
32
- # @param security [Symbol, nil] Most restrictive security level at which the option is available (see `Security`)
33
- def option(name, description: nil,
34
- short: nil, allowed: nil, default: nil,
35
- on_set: nil, shorthand: nil, deprecation: nil, schema: nil, complete: nil, security: nil)
36
- register_option_spec(
37
- OptionSpec.new(
38
- name: name,
39
- description: description,
40
- short: short,
41
- allowed: allowed,
42
- default: default,
43
- on_set: on_set,
44
- shorthand: shorthand,
45
- deprecation: deprecation,
46
- schema: schema,
47
- complete: complete,
48
- security: security
49
- )
50
- )
51
- end
52
-
53
- # Store an OptionSpec in this class's registry.
54
- # @param spec [OptionSpec]
55
- # @raise [ArgumentError] on duplicate option name
56
- def register_option_spec(spec)
57
- raise ArgumentError, "Duplicate option: #{spec.name.inspect}" if option_specs.key?(spec.name)
58
- option_specs[spec.name] = spec
59
- end
60
-
61
- # Declare all options registered on this class onto a Parser instance.
62
- # Skips options already declared on the parser.
63
- #
64
- # @param parser [Aspera::Cli::Parser]
65
- # @param target [Object, nil] default target object for Symbol and Proc `on_set` callbacks (defaults to self)
66
- # @return [void]
67
- def declare_options(parser, target: self)
68
- option_specs.each_value do |spec|
69
- spec.declare_on(parser, target: target) unless parser.option_declared?(spec.name)
70
- end
71
- end
72
- end
73
- end
74
- end
@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: IBM Corp.
4
- # SPDX-License-Identifier: Apache-2.0
5
-
6
- require_relative 'option_value'
7
- require_relative 'error'
8
- require_relative '../assert'
9
-
10
- module Aspera
11
- module Cli
12
- # Declared options, and their lookup by name: long, short, or unique abbreviation.
13
- class OptionRegistry
14
- # @return [Hash{Symbol => OptionValue}] declared options, in declaration order
15
- attr_reader :options
16
- # @return [String] help section of options declared next
17
- attr_accessor :group
18
-
19
- def initialize
20
- @options = {}
21
- # Short option char -> option, e.g. {'h' => help option}
22
- @short_options = {}
23
- @group = 'global'
24
- end
25
-
26
- # Register a new option
27
- # @param option [OptionValue] option to register
28
- # @param short [String, nil] short option char
29
- # @return [OptionValue] the option
30
- def add(option, short: nil)
31
- Aspera.assert(!@options.key?(option.option)) { "#{option.option} already declared" }
32
- option.group = @group
33
- option.short = short
34
- @options[option.option] = option
35
- @short_options[short] = option unless short.nil?
36
- option
37
- end
38
-
39
- # @param option_symbol [Symbol] option name
40
- # @return [Boolean] `true` if option is declared
41
- def declared?(option_symbol) = @options.key?(option_symbol)
42
-
43
- # @param option_symbol [Symbol] option name
44
- # @return [OptionValue] declared option
45
- # @raise [BadArgument] if option is not declared
46
- def fetch(option_symbol)
47
- Aspera.assert(@options.key?(option_symbol), type: BadArgument) { "Unknown option: #{option_symbol}" }
48
- @options[option_symbol]
49
- end
50
-
51
- # @param char [String] short option char
52
- # @return [OptionValue, nil] declared option, or `nil`
53
- def by_short(char) = @short_options[char]
54
-
55
- # Find long option by exact name, or by unique abbreviation.
56
- # @param name [String] option name with underscores
57
- # @param allow_abbreviation [Boolean] accept a unique prefix of a declared option
58
- # @return [OptionValue, nil] declared option, or `nil` if none matches (yet)
59
- # @raise [BadArgument] if abbreviation is ambiguous
60
- def by_long(name, allow_abbreviation: true)
61
- option = @options[name.to_sym]
62
- return option if !option.nil? || !allow_abbreviation
63
- candidates = @options.keys.select { |k| k.to_s.start_with?(name) }
64
- return if candidates.empty?
65
- Aspera.assert(candidates.length.eql?(1), type: BadArgument) do
66
- Parser.multi_choice_assert_msg("Ambiguous option: #{Parser.option_name_to_line(name)}", candidates.map { |c| Parser.option_name_to_line(c) })
67
- end
68
- @options[candidates.first]
69
- end
70
- end
71
- end
72
- end
@@ -1,120 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: IBM Corp.
4
- # SPDX-License-Identifier: Apache-2.0
5
-
6
- require_relative 'error'
7
- require_relative '../assert'
8
-
9
- module Aspera
10
- module Cli
11
- # Exception raised when schema is asked (`help`)
12
- class SchemaRequest < Error
13
- # Value of option or argument that requests its schema
14
- KEYWORD = 'help'
15
-
16
- # @return [String, nil] path to schema file
17
- attr_reader :path
18
-
19
- # @param type [Symbol] :argument or :option
20
- # @param name [String] name of the option/argument
21
- # @param schema_path [String, nil] path to schema file, or `nil` if not available
22
- def initialize(type, name, schema_path)
23
- super("#{type}: #{name}")
24
- @path = schema_path
25
- end
26
- end
27
-
28
- # Values accepted for boolean options: `true`, `false`, `yes`, `no`
29
- module BoolValue
30
- # Symbol for `true`
31
- YES_SYM = :yes
32
- # Symbol for `false`
33
- NO_SYM = :no
34
- # Values meaning `false`
35
- FALSE_VALUES = [NO_SYM, false].freeze
36
- # Values meaning `true`
37
- TRUE_VALUES = [YES_SYM, true].freeze
38
- private_constant :FALSE_VALUES, :TRUE_VALUES
39
- # Boolean values
40
- # @return [Array<true, false, :yes, :no>]
41
- ALL = (TRUE_VALUES + FALSE_VALUES).freeze
42
- # `false` and `true`
43
- TYPES = [FalseClass, TrueClass].freeze
44
- # `:no` and `:yes`
45
- SYMBOLS = [NO_SYM, YES_SYM].freeze
46
- # @return [Boolean] `true` if value is a value for `true` in `ALL`
47
- def true?(enum)
48
- Aspera.assert_values(enum, ALL) { 'boolean' }
49
- TRUE_VALUES.include?(enum)
50
- end
51
-
52
- # @return [Boolean] `true` if value is a value for `true` or `false` in ALL
53
- def symbol?(sym)
54
- ALL.include?(sym)
55
- end
56
- module_function :true?, :symbol?
57
- end
58
-
59
- # Type specifiers for the `allowed:` parameter of option declarations.
60
- # Public API: STRING_ARRAY, SYMBOL_ARRAY, INTEGER, FLOAT, BOOLEAN, NONE.
61
- # Internal (do not pass as `allowed:`):
62
- # ENUM - derived internally when `allowed:` is an Array<Symbol> (enum list)
63
- # STRING - the implicit default; equivalent to omitting `allowed:` entirely
64
- module Type
65
- # Option value is a String or Array of Strings (cumulative)
66
- STRING_ARRAY = [Array, String].freeze
67
- # Option value is a Symbol from a constrained list; use as prefix: SYMBOL_ARRAY + [:val1, :val2]
68
- SYMBOL_ARRAY = [Array, Symbol].freeze
69
- # Option value is coerced to Integer
70
- INTEGER = [Integer].freeze
71
- # Option value is coerced to Float
72
- FLOAT = [Float].freeze
73
- # Option value is a Boolean
74
- BOOLEAN = BoolValue::TYPES
75
- # Option has no value — it is a flag switch (e.g. `-N`, `--help`)
76
- NONE = [].freeze
77
- # Internal: derived when allowed: is an Array<Symbol>; do not pass directly
78
- ENUM = [Symbol].freeze
79
- # Internal: implicit default (String); equivalent to omitting allowed: entirely
80
- STRING = [String].freeze
81
- end
82
-
83
- # Values proposed by shell completion for an option, an argument or a schema key (`complete:`, `x-cli-complete`),
84
- # when they are not a list of allowed values:
85
- # - `file`: local file or folder
86
- # - `folder`: local folder
87
- # - `destination_folder`: local folder, unless the command sends files (the destination is then remote)
88
- # - `preset`: name of option preset
89
- # - `preset_parameter`: parameter of the option preset given as first argument of the command
90
- # - `transfer_job`: identifier of an asynchronous transfer job
91
- module Complete
92
- KINDS = %i[file folder destination_folder preset preset_parameter transfer_job].freeze
93
- end
94
-
95
- # Sources of option values.
96
- # A value is ignored if the option was already set from a source with higher priority.
97
- module OptionSource
98
- # Source -> priority (higher wins)
99
- PRIORITY = {
100
- default: 0,
101
- # Default preset for plugin (added with `override: false`)
102
- plugin_preset: 1,
103
- preset: 2,
104
- env: 3,
105
- cmdline: 4,
106
- # Set by code, or asked to user: same as command line
107
- code: 4,
108
- interactive: 4
109
- }.freeze
110
-
111
- class << self
112
- # @param source [Symbol] one of `PRIORITY` keys
113
- # @return [Integer] priority of source
114
- def priority(source)
115
- PRIORITY.fetch(source) { Aspera.error_unexpected_value(source) { 'option source' } }
116
- end
117
- end
118
- end
119
- end
120
- end
@@ -1,345 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: IBM Corp.
4
- # SPDX-License-Identifier: Apache-2.0
5
-
6
- require_relative 'option_types'
7
- require_relative 'extended_value'
8
- require_relative 'security'
9
- require_relative 'deprecation'
10
- require_relative '../secret/hider'
11
- require_relative '../schema/registry'
12
- require_relative '../schema/validator'
13
- require_relative '../log'
14
- require_relative '../assert'
15
-
16
- module Aspera
17
- module Cli
18
- # Declared option: type, value, and where the value is stored.
19
- class OptionValue
20
- # [Symbol] Name of option
21
- attr_reader :option
22
- # [Array<Class>, nil] List of allowed types, `nil` for no validation
23
- attr_reader :types
24
- # [Symbol] How values are converted: :flag, :boolean, :integer, :float, :enum, :enum_list, :string_list, :other
25
- attr_reader :kind
26
- # [Symbol, nil] `OptionSource` of current value, `nil` if never set
27
- attr_reader :source
28
- attr_reader :sensitive, :schema, :deprecation
29
- # [Symbol, nil] Most restrictive security level at which the option is available, `nil`: all levels, see `Security`
30
- attr_reader :security
31
- # [String, nil] For a `Hash` option: key of a `String` value
32
- attr_reader :shorthand
33
- # [Symbol, nil] Values proposed by shell completion, one of `Complete::KINDS`
34
- attr_reader :complete
35
- # [Array] List of allowed values (Symbols and specific values)
36
- attr_accessor :values
37
- # [String] Help section group name (set by OptionRegistry)
38
- attr_accessor :group
39
- # [String, nil] Short option char (set by OptionRegistry)
40
- attr_accessor :short
41
- # [Proc, nil] Block to call for flag options
42
- attr_accessor :block
43
-
44
- # @param option [Symbol] Name of option
45
- # @param description [String, nil] Description for help; if nil, derived from schema
46
- # @param allowed [nil,Class,Array<Class>,Array<Symbol>] Allowed values
47
- # @param on_set [#call, nil] Called with the new value each time the value is set
48
- # @param shorthand [String, nil] For a `Hash` option: a `String` value is stored as `{shorthand => value}`
49
- # @param convert [#call, nil] For a `Hash` option: called with a new `Hash` value, returns the value to store, before merge (e.g. conversion of a deprecated form)
50
- # @param deprecation [Hash, Deprecation, nil] Deprecation: `{last:, message:}`, see `Deprecation`
51
- # @param schema [String] Declaration of schema
52
- # @param complete [Symbol, nil] Values proposed by shell completion, one of `Complete::KINDS`
53
- # @param security [Symbol, nil] Most restrictive security level at which the option is available (e.g. `:low`: executes code), see `Security`
54
- # `allowed`:
55
- # - `nil` No validation, so just a string
56
- # - `Class` The single allowed Class
57
- # - `Array<Class>` Multiple allowed classes
58
- # - `Array<Symbol>` List of allowed values
59
- def initialize(option:, description: nil, allowed: Type::STRING, on_set: nil, shorthand: nil, convert: nil, deprecation: nil, schema: nil, complete: nil, security: nil)
60
- Log.log.trace1 { "option: #{option}, allowed: #{allowed}" }
61
- @option = option
62
- @description = description
63
- @group = nil
64
- @short = nil
65
- @block = nil
66
- # by default passwords and secrets are sensitive, else specify when declaring the option
67
- @sensitive = Secret::Hider.instance.secret?(@option, '')
68
- @deprecation = Deprecation.create(deprecation)
69
- @schema = schema
70
- @shorthand = shorthand
71
- Aspera.assert(convert.nil? || convert.respond_to?(:call)) { "#{@option}: convert must respond to call" }
72
- @convert = convert
73
- Aspera.assert_values(complete, Complete::KINDS + [nil]) { "#{@option}: complete" }
74
- @complete = complete
75
- Aspera.assert_values(security, Security::LEVELS + [nil]) { "#{@option}: security" }
76
- @security = security
77
- @source = nil
78
- @value = nil
79
- Aspera.assert(on_set.nil? || on_set.respond_to?(:call)) { "#{@option}: on_set callback must respond to call" }
80
- @on_set = on_set
81
- @types = nil
82
- @values = nil
83
- @kind = :other
84
- allowed = infer_allowed_from_schema(schema, allowed) if schema
85
- apply_allowed(allowed) unless allowed.nil?
86
- end
87
-
88
- # @return [String] description of the option: explicit one, or first line of schema description
89
- def description
90
- return @description unless @description.nil?
91
- return if @schema.nil?
92
- schema_node = Schema::Registry.instance.reader(@schema).current
93
- first_line = (schema_node['title'] || schema_node['description'].to_s).lines.first.to_s.strip
94
- first_line.end_with?('.') ? first_line[0..-2] : first_line
95
- end
96
-
97
- # @return [String, nil] allowed values, or expected types when not plain `String`, e.g. `Hash|String`
98
- def allowed_info
99
- return @values.join('|') if @values&.any?
100
- types = @types&.reject { |t| t.eql?(NilClass) }
101
- return if types.nil? || types.empty? || types.eql?(Type::STRING)
102
- types.map(&:name).join('|')
103
- end
104
-
105
- # @return [Boolean] `true` if option takes no value
106
- def flag? = @kind.eql?(:flag)
107
-
108
- # @param value [Object] value given to option
109
- # @return [Boolean] `true` if value asks for the schema of option
110
- def schema_request?(value) = value.eql?(SchemaRequest::KEYWORD) && @types&.include?(Hash)
111
-
112
- # Reset stored value to nil
113
- # @return [nil]
114
- def clear
115
- store(nil, nil)
116
- end
117
-
118
- # Get current option value
119
- # @param log [Boolean] whether to log the value retrieval
120
- # @return [Object] current value
121
- def value(log: true)
122
- Log.log.trace1 { "#{@option} -> (#{@value.class})#{Secret::Hider.instance.hidden_copy(@value)}" } if log
123
- @value
124
- end
125
-
126
- # Assign value to option.
127
- # Value can be a `String`, then evaluated with `ExtendedValue`, or directly a value.
128
- # `Hash` and `Array` values are merged with current value.
129
- # @param value [String, Object] Value to assign to option
130
- # @param source [Symbol] `OptionSource` of value
131
- # @param warn_deprecation [Boolean] Emit deprecation warning (false for internal transfers)
132
- # @param merge [Boolean] Merge `Hash` and `Array` with current value (false: value is already complete)
133
- # @return [nil]
134
- # @raise [SchemaRequest] if value is `help` and schema is known
135
- def assign_value(value, source:, warn_deprecation: true, merge: true)
136
- # Value from a source with lower priority than current value: only fills containers
137
- lower = !@source.nil? && OptionSource.priority(source) < OptionSource.priority(@source)
138
- if lower && ![Hash, Array].include?(@types&.first)
139
- Log.log.debug { "#{source}: #{@option}: ignored, already set from #{@source}" }
140
- return
141
- end
142
- Aspera.assert(!@deprecation, type: :warn) { "Option #{@option} is #{@deprecation}" } if warn_deprecation
143
- # Values set by the program itself are not restricted: those from command line, preset, environment are
144
- Security.instance.check_level(@security, "option #{@option}") if restricted_source?(source)
145
- if schema_request?(value)
146
- return if lower
147
- raise SchemaRequest.new(:option, @option, @schema) unless @schema.nil?
148
- # Schema depends on command: kept as-is, raised by Parser#get_option(schema:)
149
- store(value, source)
150
- return
151
- end
152
- new_value = coerce(ExtendedValue.instance.evaluate(value, context: "option: #{@option}", allowed: @types))
153
- check_sub_options_security(new_value) if restricted_source?(source)
154
- new_value = {@shorthand => new_value} if @shorthand && new_value.is_a?(String)
155
- declare_secrets(new_value)
156
- Log.log.trace1 { "#{source}: #{@option} <- (#{new_value.class})#{Secret::Hider.instance.hidden_copy(new_value)}" }
157
- Aspera.assert_type(new_value, *@types, type: BadArgument) { "Option #{@option}" } if @types
158
- new_value = @convert.call(new_value) if @convert && new_value.is_a?(Hash)
159
- if merge && (new_value.is_a?(Hash) || new_value.is_a?(Array))
160
- current_value = @value
161
- # An `Array` default value is replaced, not appended to
162
- mergeable = current_value.is_a?(new_value.is_a?(Hash) ? Hash : Array) && !current_value.empty? &&
163
- !(new_value.is_a?(Array) && [source, @source].include?(:default))
164
- if lower
165
- # Current value has priority: merge new value under it, unless explicitly emptied
166
- return unless mergeable
167
- new_value, current_value = current_value, new_value
168
- source = @source
169
- end
170
- new_value = new_value.is_a?(Hash) ? current_value.deep_merge(new_value) : current_value + new_value if mergeable
171
- end
172
- validate_schema(new_value) unless %i[code default].include?(source)
173
- store(new_value, source)
174
- nil
175
- end
176
-
177
- # Check that the option, and the sub-options present in a `Hash` value (`x-security` in schema), are available at current security level.
178
- # Used for a value that is not assigned yet, e.g. to store in a preset.
179
- # @param value [Object] Value of the option
180
- # @raise [BadArgument] If refused at current level
181
- def check_security(value)
182
- Security.instance.check_level(@security, "option #{@option}")
183
- check_sub_options_security(value)
184
- end
185
-
186
- private
187
-
188
- # Values set by the program, or by the environment of the process (under control of the one who starts it), are not restricted:
189
- # those from command line, presets (that a client can modify) and interactive input are.
190
- # @param source [Symbol] `OptionSource`
191
- # @return [Boolean] `true` if a value from this source is checked against security level
192
- def restricted_source?(source)
193
- !%i[default code env].include?(source)
194
- end
195
-
196
- # @param value [Object] Value of the option
197
- # @raise [BadArgument] If a sub-option with `x-security` in the schema is present and refused at current level
198
- def check_sub_options_security(value)
199
- return unless @schema && value.is_a?(Hash)
200
- Schema::Registry.instance.reader(@schema).each_property do |property, _name, full_name, _required|
201
- level = property['x-security']
202
- next if level.nil?
203
- # Value of the sub-option, if given (a `nil` value clears it)
204
- given = full_name.split('.').reduce(value) { |node, key| node.is_a?(Hash) ? node.find { |k, _| k.to_s.eql?(key) }&.last : nil }
205
- Security.instance.check_level(level.to_sym, "option #{@option}.#{full_name}") unless given.nil?
206
- end
207
- end
208
-
209
- # Validate a structured value against the schema of the option.
210
- # Value may be partial: completed by other sources or defaults, so `required` is not enforced.
211
- # @param value [Object] value to validate
212
- # @raise [BadArgument] if value does not match schema
213
- def validate_schema(value)
214
- return unless @schema && (value.is_a?(Hash) || value.is_a?(Array))
215
- errors = Schema::Validator.instance.errors(value, @schema, partial: true)
216
- raise BadArgument, "Option #{@option}: #{errors.join('; ')} (use --#{@option.to_s.tr('_', '-')}=#{SchemaRequest::KEYWORD} for schema)" unless errors.empty?
217
- end
218
-
219
- # Derive the `allowed:` value from the schema when not explicitly provided.
220
- # Returns `allowed` unchanged when the schema provides no usable type information.
221
- # @param schema [String] schema identifier
222
- # @param allowed [Object] caller-supplied allowed value (may be nil or Type::STRING)
223
- # @return [Object] resolved allowed (Hash, Array, or the original value)
224
- def infer_allowed_from_schema(schema, allowed)
225
- return allowed unless allowed.nil? || allowed.eql?(Type::STRING)
226
-
227
- schema_reader = Schema::Registry.instance.reader(schema) rescue nil
228
- schema_node = schema_reader&.current
229
- return allowed unless schema_node
230
-
231
- case schema_node['type']
232
- when 'object' then return Hash
233
- when 'array' then return Array
234
- end
235
- # No top-level type: inspect oneOf/anyOf branches; if all resolve to 'object', infer Hash
236
- composite_key = (%w[oneOf anyOf] & schema_node.keys).first
237
- return allowed unless composite_key
238
-
239
- branch_types = schema_node[composite_key].map do |branch|
240
- resolved = branch['$ref'] ? schema_reader.resolve_ref(branch['$ref']).current : branch
241
- resolved['type']
242
- end
243
- if branch_types.all?('object')
244
- Hash
245
- else
246
- Aspera.assert(
247
- !allowed.nil? && !allowed.eql?(Type::STRING),
248
- "option :#{@option}: schema '#{schema}' has mixed-type oneOf branches #{branch_types.uniq}: specify allowed: explicitly"
249
- )
250
- allowed
251
- end
252
- end
253
-
254
- # Initialize @types, @values and @kind from the resolved `allowed` specifier.
255
- # @param allowed [Class, Array<Class>, Array<Symbol>] resolved allowed value (never nil)
256
- def apply_allowed(allowed)
257
- allowed = [allowed] if allowed.is_a?(Class)
258
- Aspera.assert_type(allowed, Array)
259
- if allowed.eql?(Type::NONE)
260
- @kind = :flag
261
- @types = Type::NONE
262
- elsif allowed.take(Type::SYMBOL_ARRAY.length) == Type::SYMBOL_ARRAY
263
- # Array of defined symbol values
264
- @kind = :enum_list
265
- @types = Type::SYMBOL_ARRAY
266
- @values = allowed[Type::SYMBOL_ARRAY.length..]
267
- elsif allowed.all?(Symbol)
268
- @kind = :enum
269
- @types = Type::ENUM
270
- @values = allowed
271
- elsif allowed.all?(Class)
272
- @types = allowed
273
- @kind =
274
- if allowed.sort_by(&:name).eql?(Type::BOOLEAN) then :boolean
275
- elsif allowed.eql?(Type::INTEGER) then :integer
276
- elsif allowed.eql?(Type::FLOAT) then :float
277
- elsif allowed.eql?(Type::STRING_ARRAY) then :string_list
278
- else :other
279
- end
280
- @values = BoolValue::ALL if @kind.eql?(:boolean)
281
- else
282
- Aspera.error_unexpected_value(allowed)
283
- end
284
- # Containers start empty, unless nil is allowed
285
- default = {Array => [], Hash => {}}[@types.first]
286
- store(default, :default) if !default.nil? && !@types.include?(NilClass) && @value.nil?
287
- end
288
-
289
- # Convert value from command line, env or preset (String) to the type of option
290
- # @param value [Object] evaluated value
291
- # @return [Object] converted value
292
- def coerce(value)
293
- case @kind
294
- when :enum
295
- # Boolean from dot-path value, e.g. `no` for `%i[no header read]`
296
- value = (value ? BoolValue::YES_SYM : BoolValue::NO_SYM).to_s if BoolValue::TYPES.include?(value.class)
297
- value.is_a?(String) ? Parser.get_from_list(value, @option, @values) : value
298
- when :boolean
299
- BoolValue.true?(value.is_a?(String) ? Parser.get_from_list(value, @option, BoolValue::ALL) : value)
300
- when :integer
301
- # Decimal, also with leading zeros (e.g. `08`)
302
- if value.is_a?(String)
303
- Integer(value, 10, exception: false).tap { |i| raise BadArgument, "Option #{@option}: invalid integer: #{value}" if i.nil? }
304
- else
305
- value.nil? ? value : Integer(value)
306
- end
307
- when :float
308
- if value.is_a?(String)
309
- Float(value, exception: false).tap { |f| raise BadArgument, "Option #{@option}: invalid number: #{value}" if f.nil? }
310
- else
311
- value.nil? ? value : Float(value)
312
- end
313
- when :string_list
314
- value.is_a?(String) ? [value] : value
315
- when :enum_list
316
- value = [value] if value.is_a?(String)
317
- Aspera.assert_array_all(value, String, type: BadArgument)
318
- value.map { |v| Parser.get_from_list(v, @option, @values) }
319
- else
320
- # nil on a Hash/Array option resets to empty container
321
- value.nil? && [Hash, Array].include?(@types&.first) ? @types.first.new : value
322
- end
323
- end
324
-
325
- # Secret values are hidden wherever they appear: logs, results
326
- # @param value [Object] value of option
327
- def declare_secrets(value)
328
- if @sensitive
329
- Secret::Hider.instance.add_secret_values(value)
330
- else
331
- Secret::Hider.instance.add_secrets_in(value)
332
- end
333
- end
334
-
335
- # @param new_value [Object] value to store
336
- # @param source [Symbol, nil] `OptionSource` of value
337
- def store(new_value, source)
338
- declare_secrets(new_value)
339
- @value = new_value
340
- @source = source
341
- @on_set&.call(new_value)
342
- end
343
- end
344
- end
345
- end