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,7 +4,9 @@
4
4
  # SPDX-License-Identifier: Apache-2.0
5
5
 
6
6
  require_relative '../assert'
7
+ require_relative '../log'
7
8
  require_relative '../yaml'
9
+ require_relative '../string_ext'
8
10
  require_relative 'reader'
9
11
  require 'singleton'
10
12
 
@@ -17,15 +19,62 @@ module Aspera
17
19
  class Registry
18
20
  include Singleton
19
21
 
22
+ # Schemas added by the libraries that read them (`register`), by key: `file`, `doc_options`
23
+ @registered = {}
24
+
20
25
  class << self
26
+ # Add a schema of a library that uses the registry, e.g. the domain library: called by the file that reads it.
27
+ # The schema is owned (values are validated against it).
28
+ # @param key [Symbol, String] Key of the schema
29
+ # @param file [String] Absolute path of the schema file
30
+ # @param doc_options [Proc, nil] Called without argument: options of `Documentation` for the whole schema (e.g. annotations of properties)
31
+ # @return [nil]
32
+ def register(key, file, doc_options: nil)
33
+ key = key.to_sym
34
+ Aspera.assert(!LOCATIONS.key?(key)) { "schema #{key} is a built-in schema" }
35
+ Aspera.assert(!@registered.key?(key) || @registered[key][:file].eql?(file)) { "schema #{key} is registered with another file: #{@registered[key][:file]}" }
36
+ # A reserved key cannot be claimed by a bundle (`built_in?`): no need to look at the bundles, which keeps the load of the domain files cheap
37
+ unless RESERVED.include?(key)
38
+ claimed = bundle_schema(key)
39
+ Aspera.assert(claimed.nil?) { "schema #{key} is registered with #{file} and provided by plugin #{claimed.bundle} (#{claimed.file})" }
40
+ end
41
+ Aspera.assert_type(doc_options, Proc, NilClass) { 'doc_options' }
42
+ @registered[key] = {file: file, doc_options: doc_options}.freeze
43
+ nil
44
+ end
45
+
46
+ # @param sym [Symbol] Key of a schema
47
+ # @return [Hash, nil] Schema added by `register`: `file`, `doc_options`, `nil` if none
48
+ def registered(sym)
49
+ @registered[sym]
50
+ end
51
+
52
+ # @param sym [Symbol] Key of a schema: of the gem (`LOCATIONS`), added by a library (`register`) or provided by a bundle
21
53
  def known?(sym)
22
- LOCATIONS.key?(sym)
54
+ LOCATIONS.key?(sym) || @registered.key?(sym) || !bundle_schema(sym).nil?
55
+ end
56
+
57
+ # @param sym [Symbol] Key of a schema
58
+ # @return [Boolean] `true` if the key is a schema of the gem, reserved for a library (even if its file is not loaded yet) or added by a library: a bundle cannot use it
59
+ def built_in?(sym)
60
+ LOCATIONS.key?(sym) || RESERVED.include?(sym) || @registered.key?(sym)
23
61
  end
24
62
 
25
63
  # @param name_path [String] schema path, e.g. `opts:components.schemas.HttpOptions`
26
64
  # @return [Boolean] `true` if schema is owned by ascli (not a vendor API)
27
65
  def owned?(name_path)
28
- OWNED.include?(name_path.split(':', 2).first.to_sym)
66
+ sym = name_path.split(':', 2).first.to_sym
67
+ return OWNED.include?(sym) if LOCATIONS.key?(sym)
68
+ return true if @registered.key?(sym)
69
+ bundle_schema(sym)&.owned || false
70
+ end
71
+
72
+ # @param sym [Symbol] Key of a schema
73
+ # @return [BundleRegistry::SchemaFile, nil] Schema provided by an available bundle (its folder, declared in its manifest), `nil` if none
74
+ def bundle_schema(sym)
75
+ # Loaded on use: `bundle_registry` requires this file
76
+ require_relative '../bundle_registry'
77
+ BundleRegistry.instance.schema(sym)
29
78
  end
30
79
 
31
80
  # Split a component string into registry key and optional path prefix.
@@ -57,56 +106,31 @@ module Aspera
57
106
  end
58
107
  end
59
108
 
109
+ # Schemas of the framework, relative to `lib`: the other ones are added by the libraries that use them (`register`) and by bundles (manifest)
60
110
  LOCATIONS = {
61
- spec: 'aspera/transfer/spec.schema.yaml',
62
- args: 'aspera/sync/args.schema.yaml',
63
- conf: 'aspera/sync/conf.schema.yaml',
64
- opts: 'aspera/cli/options.schema.yaml',
65
- preview: 'aspera/preview/options.schema.yaml',
66
- aoc: 'aspera/schema/IBM Aspera on Cloud API-0.2.6-enhanced.yaml',
67
- automation: 'aspera/schema/IBM Aspera on Cloud Automation API-1.0.5-enhanced.yaml',
68
- faspex: 'aspera/schema/IBM Aspera Faspex API-5.0-enhanced.yaml',
69
- faspio: 'aspera/schema/IBM Aspera faspio Gateway API-1.0.0-enhanced.yaml',
70
- console: 'aspera/schema/IBM Aspera Console-enhanced.yaml',
71
- node: 'aspera/schema/IBM Aspera Node API-4.4.6.yaml',
72
- shares: 'aspera/schema/IBM_Aspera_Shares.yaml',
73
- orchestrator: 'aspera/schema/IBM Aspera Orchestrator API-v1-enhanced.yaml',
74
- async_tables: 'aspera/schema/async_tables.yaml',
75
- ascp_log: 'aspera/ascp/log.schema.yaml',
76
- transferd: 'aspera/schema/transferd-config.schema.json'
111
+ opts: 'aspera/cli/options.schema.yaml',
112
+ manifest: 'aspera/plugin.schema.yaml'
77
113
  }.freeze
78
114
 
79
115
  # Schemas owned by ascli: values are validated against them (vendor API schemas are validated by the API)
80
- OWNED = %i[spec args conf opts preview async_tables ascp_log transferd].freeze
116
+ OWNED = %i[opts manifest].freeze
81
117
 
82
118
  OPTIONS = 'opts'
119
+ # Keys of the schemas of the domain library, added by their files (`register`)
83
120
  TRANSFER_SPEC = 'spec'
84
121
  SYNC_CONF = 'conf'
85
122
  SYNC_ARGS = 'args'
86
- PREVIEW_OPTIONS = 'preview'
87
- AOC = 'aoc'
88
- AUTOMATION = 'automation'
89
- FASPEX = 'faspex'
90
- FASPIO = 'faspio'
91
- CONSOLE = 'console'
92
- NODE = 'node'
93
- ORCHESTRATOR = 'orchestrator'
94
- SHARES = 'shares+/api/v1'
95
123
  ASYNC_TABLES = 'async_tables'
96
124
  ASCP_LOG = 'ascp_log'
125
+ # Keys reserved for the domain library: a bundle cannot claim them, whether or not their file is loaded (plain data: the framework does not require the domain files)
126
+ RESERVED = [TRANSFER_SPEC, SYNC_CONF, SYNC_ARGS, ASYNC_TABLES, ASCP_LOG].map(&:to_sym).freeze
127
+ # Manifest `plugin.yaml` of a plugin bundle, see `BundleRegistry`
128
+ MANIFEST = 'manifest'
97
129
  LOG_OPTIONS = "#{OPTIONS}:components.schemas.LogOptions".freeze
98
130
  UI_OPTIONS = "#{OPTIONS}:components.schemas.UiOptions".freeze
99
131
  SECURITY_OPTIONS = "#{OPTIONS}:components.schemas.SecurityOptions".freeze
100
132
  TEMP_OPTIONS = "#{OPTIONS}:components.schemas.TempOptions".freeze
101
- DIRECT_AGENT_OPTIONS = "#{OPTIONS}:components.schemas.DirectAgentOptions".freeze
102
- NODE_AGENT_OPTIONS = "#{OPTIONS}:components.schemas.NodeAgentOptions".freeze
103
- NODE_EMULATOR_OPTIONS = "#{OPTIONS}:components.schemas.NodeEmulatorOptions".freeze
104
- HTTPGW_AGENT_OPTIONS = "#{OPTIONS}:components.schemas.HttpgwAgentOptions".freeze
105
- TRANSFERD_AGENT_OPTIONS = "#{OPTIONS}:components.schemas.TransferdAgentOptions".freeze
106
- TRANSFER_AGENT_OPTIONS = "#{OPTIONS}:components.schemas.TransferAgentOptions".freeze
107
133
  SMTP_OPTIONS = "#{OPTIONS}:components.schemas.SmtpOptions".freeze
108
- SERVICE_OPTIONS = "#{OPTIONS}:components.schemas.ServiceOptions".freeze
109
- TRANSFERD_SERVICE_CONFIG = "#{OPTIONS}:components.schemas.TransferdServiceConfig".freeze
110
134
  HTTP_OPTIONS = "#{OPTIONS}:components.schemas.HttpOptions".freeze
111
135
  VAULT_OPTIONS = "#{OPTIONS}:components.schemas.VaultOptions".freeze
112
136
  VAULT_SECRET = "#{OPTIONS}:components.schemas.VaultSecret".freeze
@@ -116,20 +140,26 @@ module Aspera
116
140
  PRESET_LOOKUP_CRITERIA = "#{OPTIONS}:components.schemas.PresetLookupCriteria".freeze
117
141
  WIZARD_OPTIONS = "#{OPTIONS}:components.schemas.WizardOptions".freeze
118
142
  IMAGE_OPTIONS = "#{OPTIONS}:components.schemas.ImageOptions".freeze
119
- ASCP_LOGS_OPTIONS = "#{OPTIONS}:components.schemas.AscpLogsOptions".freeze
120
143
  OUT_OPTIONS = "#{OPTIONS}:components.schemas.OutOptions".freeze
121
144
  POLL_OPTIONS = "#{OPTIONS}:components.schemas.PollOptions".freeze
122
- PACKAGE_FOLDER_OPTIONS = "#{OPTIONS}:components.schemas.PackageFolderOptions".freeze
123
145
  WEB_SERVER_OPTIONS = "#{OPTIONS}:components.schemas.WebServerOptions".freeze
124
- GATEWAY_OPTIONS = "#{OPTIONS}:components.schemas.Faspex4GatewayOptions".freeze
125
- POSTPROC_OPTIONS = "#{OPTIONS}:components.schemas.Faspex4PostProcOptions".freeze
126
146
 
127
147
  REQ_BODY = '.requestBody.content.application/json.schema'
128
148
  # Suffix appended to a dotted path to signal query-param extraction in reader()
129
149
  QUERY_PARAMS_SUFFIX = '.parameters'
150
+ # Marker of a component whose `oneOf` variants are also given by the entries of an extension point of bundles, see `add_variants`
151
+ VARIANTS = 'x-cli-variants'
152
+ # Added to such a component: values of the selector that are not variants because their entry is declared by an unavailable bundle, with the reason
153
+ UNAVAILABLE = 'x-cli-unavailable'
154
+ # `$ref` to a node of another schema of the registry: `<key>:#/<path>`, see `add_references`
155
+ EXTERNAL_REF = %r{\A([a-z][a-z0-9_]*):#/(.+)\z}
130
156
 
131
157
  def initialize
132
158
  @cache = {}
159
+ # Schema files being read (see `add_references`)
160
+ @loading = []
161
+ # Entries of the extension points used for the variants of a document, by file and by point (see `add_variants`)
162
+ @variant_entries = {}
133
163
  @main_folder = File.expand_path('../..', __dir__)
134
164
  end
135
165
 
@@ -144,23 +174,187 @@ module Aspera
144
174
  name, path = name_path.split(':', 2)
145
175
  sym = name.to_sym
146
176
  Aspera.assert(Registry.known?(sym)) { "schema: #{sym}" }
147
- spec_file = File.join(@main_folder, LOCATIONS[sym])
177
+ spec_file = schema_file(sym)
148
178
  # JSON is read with the YAML loader: it accepts the header comment added by `rake tools:openapi`
149
- @cache[sym] = Yaml.safe_load(File.read(spec_file)) unless @cache.key?(sym)
179
+ # Read again when the entries of its variants changed (e.g. bundles of a plugin folder added since)
180
+ load_document(spec_file, sym) unless @cache.key?(spec_file) && variants_current?(spec_file)
150
181
  # Query-params path: strip the suffix, navigate to the operation node, extract parameters
151
182
  if path&.end_with?(QUERY_PARAMS_SUFFIX)
152
183
  parent_path = path.delete_suffix(QUERY_PARAMS_SUFFIX)
153
- node = @cache[sym].dig(*parent_path.split('.'))
184
+ node = @cache[spec_file].dig(*parent_path.split('.'))
154
185
  # Parameters may be references to components.parameters
155
186
  params = (node&.fetch('parameters', []) || []).map do |param|
156
- param.key?('$ref') ? @cache[sym].dig(*param['$ref'].delete_prefix('#/').split('/')) : param
187
+ param.key?('$ref') ? @cache[spec_file].dig(*param['$ref'].delete_prefix('#/').split('/')) : param
157
188
  end
158
189
  return Reader.from_query_params(params.compact)
159
190
  end
160
- reader = Reader.new(@cache[sym])
191
+ reader = Reader.new(@cache[spec_file])
161
192
  return reader unless path
162
193
  reader.dig(*path.split('.'))
163
194
  end
195
+
196
+ # @param name_path [String] Schema path: key, and optional path in the schema (`<key>:<path>`)
197
+ # @return [Hash] Options of `Documentation` for the schema, given when its key was added (`register`): only for the whole schema (no path); empty if none
198
+ def doc_options(name_path)
199
+ name, path = name_path.split(':', 2)
200
+ doc_options = Registry.registered(name.to_sym)&.fetch(:doc_options)
201
+ return {} if !path.nil? || doc_options.nil?
202
+ doc_options.call
203
+ end
204
+
205
+ private
206
+
207
+ # Read a schema file in the cache, with the references to other schemas and the variants of bundles added
208
+ # @param spec_file [String] Schema file
209
+ # @param sym [Symbol] Key of the schema
210
+ # @return [nil]
211
+ def load_document(spec_file, sym)
212
+ Aspera.assert(!@loading.include?(spec_file)) { "schema #{sym}: circular reference between schemas" }
213
+ @loading.push(spec_file)
214
+ @cache[spec_file] = add_variants(add_references(Yaml.safe_load(File.read(spec_file)), sym), spec_file)
215
+ nil
216
+ ensure
217
+ @loading.delete(spec_file)
218
+ end
219
+
220
+ # @param sym [Symbol] Key of a known schema
221
+ # @return [String] Absolute path of its file
222
+ def schema_file(sym)
223
+ return File.join(@main_folder, LOCATIONS[sym]) if LOCATIONS.key?(sym)
224
+ return Registry.registered(sym)[:file] if Registry.registered(sym)
225
+ Registry.bundle_schema(sym).file
226
+ end
227
+
228
+ # Replace each `$ref` to a node of another schema of the registry (`<key>:#/<path>`) with a copy of that node:
229
+ # the readers and the validator see one document, with local references only. The node may not contain references.
230
+ # @param node [Object] Document read from a schema file, or a node of it: modified in place
231
+ # @param sym [Symbol] Key of the document
232
+ # @return [Object] The node, with the references replaced (the same object, unless it is a reference)
233
+ def add_references(node, sym)
234
+ case node
235
+ when Hash
236
+ match = node['$ref'].is_a?(String) ? EXTERNAL_REF.match(node['$ref']) : nil
237
+ if match.nil?
238
+ # replaced in place (the document was just read): no copy of the nodes without reference
239
+ node.each { |key, value| node[key] = add_references(value, sym) }
240
+ return node
241
+ end
242
+ Aspera.assert(node.keys.eql?(['$ref'])) { "schema #{sym}: #{node['$ref']}: a reference to another schema has no sibling keys" }
243
+ Aspera.assert(!match[1].to_sym.eql?(sym)) { "schema #{sym}: #{node['$ref']}: use a local reference" }
244
+ target = reader(match[1]).current.dig(*match[2].split('/'))
245
+ Aspera.assert_type(target, Hash) { "schema #{sym}: #{node['$ref']}" }
246
+ Aspera.assert(!reference?(target)) { "schema #{sym}: #{node['$ref']}: the referenced node may not contain references" }
247
+ Marshal.load(Marshal.dump(target))
248
+ when Array then node.map! { |value| add_references(value, sym) }
249
+ else node
250
+ end
251
+ end
252
+
253
+ # @param node [Object] Node of a schema
254
+ # @return [Boolean] `true` if the node contains a `$ref`
255
+ def reference?(node)
256
+ case node
257
+ when Hash then node.key?('$ref') || node.each_value.any? { |value| reference?(value) }
258
+ when Array then node.any? { |value| reference?(value) }
259
+ else false
260
+ end
261
+ end
262
+
263
+ # @param spec_file [String] Schema file read in the cache
264
+ # @return [Boolean] `true` if the entries of the extension points of its variants are the same as when it was read
265
+ def variants_current?(spec_file)
266
+ entries = @variant_entries.fetch(spec_file, {})
267
+ return true if entries.empty?
268
+ entries.all? { |point, used| [BundleRegistry.instance.extensions(point), BundleRegistry.instance.unavailable_extensions(point)].eql?(used) }
269
+ end
270
+
271
+ # Add the variants given by bundles to the components of `components.schemas` that have the marker `x-cli-variants`
272
+ # (`point`: extension point, `value`: field of an entry with the value of the discriminator, `schema`: field with the schema file of the variant,
273
+ # relative to the folder of the bundle, `suffix`: of the name of the component, optional `unique`: field whose value, a one-letter string, is unique among the variants:
274
+ # an entry without it is skipped, as `Agent::Factory#provided_agents` does).
275
+ # For each entry of the point: a component `<Value><suffix>` read from the file, a `$ref` in `oneOf`, an entry in `discriminator.mapping`
276
+ # (both created if the document has none).
277
+ # An entry with the value of a variant of the document replaces it; an entry with the value of an earlier entry,
278
+ # with the `unique` field of an earlier entry, or whose schema file cannot be read, is skipped with a warning. The marker is removed.
279
+ # The entries used are kept: the document is read again when they change (see `variants_current?`).
280
+ # @param document [Object] Document read from a schema file
281
+ # @param spec_file [String] Schema file of the document
282
+ # @return [Object] The document, with the variants added
283
+ def add_variants(document, spec_file)
284
+ @variant_entries[spec_file] = {}
285
+ schemas = document.dig('components', 'schemas') if document.is_a?(Hash) && document['components'].is_a?(Hash)
286
+ return document unless schemas.is_a?(Hash)
287
+ schemas.values.select { |schema| schema.is_a?(Hash) && schema.key?(VARIANTS) }.each do |selector|
288
+ marker = selector.delete(VARIANTS)
289
+ # A document without variants of its own has no `oneOf` nor `discriminator.mapping`: created
290
+ one_of = selector['oneOf'] ||= []
291
+ discriminator = selector['discriminator']
292
+ Aspera.assert_type(discriminator, Hash) { "#{VARIANTS}: discriminator" }
293
+ mapping = discriminator['mapping'] ||= {}
294
+ Aspera.assert_type(one_of, Array) { "#{VARIANTS}: oneOf" }
295
+ Aspera.assert_type(mapping, Hash) { "#{VARIANTS}: discriminator.mapping" }
296
+ # Loaded on use: `bundle_registry` requires this file
297
+ require_relative '../bundle_registry'
298
+ added = []
299
+ # Value of the field `unique` taken, by value of the variant
300
+ taken = {}
301
+ unique = marker['unique']
302
+ point = marker.fetch('point').to_sym
303
+ entries = BundleRegistry.instance.extensions(point)
304
+ @variant_entries[spec_file][point] = [entries, BundleRegistry.instance.unavailable_extensions(point)]
305
+ entries.each do |entry|
306
+ value, file = entry.fields.values_at(marker.fetch('value'), marker.fetch('schema'))
307
+ label = "Variant #{value} of bundle #{entry.bundle} is skipped"
308
+ next Log.log.warn { "#{label}: no #{marker['value']} or #{marker['schema']}" } unless value.is_a?(String) && file.is_a?(String)
309
+ next Log.log.warn { "#{label}: added by an earlier entry" } if added.include?(value)
310
+ unless unique.nil?
311
+ letter = entry.fields[unique]
312
+ next Log.log.warn { "#{label}: #{unique} #{letter.inspect} is not a one-letter string" } unless letter.is_a?(String) && letter.length.eql?(1)
313
+ owner = taken.key(letter)
314
+ end
315
+ next Log.log.warn { "#{label}: #{unique} #{entry.fields[unique]} is taken by #{owner}" } unless owner.nil?
316
+ component = "#{value.snake_to_capital}#{marker.fetch('suffix')}"
317
+ ref = "#/components/schemas/#{component}"
318
+ next Log.log.warn { "#{label}: component #{component} exists" } if schemas.key?(component) && !mapping[value].eql?(ref)
319
+ path = File.join(BundleRegistry.instance[entry.bundle].path, file)
320
+ variant = read_variant(path)
321
+ next Log.log.warn { "#{label}: cannot read #{path}: #{variant}" } if variant.is_a?(String)
322
+ schemas[component] = variant
323
+ index = one_of.index { |item| item['$ref'].eql?(mapping[value]) } if mapping.key?(value)
324
+ if index.nil?
325
+ one_of.push({'$ref' => ref})
326
+ else
327
+ one_of[index] = {'$ref' => ref}
328
+ end
329
+ mapping[value] = ref
330
+ added.push(value)
331
+ taken[value] = entry.fields[unique] unless unique.nil?
332
+ end
333
+ unavailable = unavailable_variants(marker, point, mapping)
334
+ selector[UNAVAILABLE] = unavailable unless unavailable.empty?
335
+ end
336
+ document
337
+ end
338
+
339
+ # @param marker [Hash] Marker `x-cli-variants`
340
+ # @param point [Symbol] Extension point
341
+ # @param mapping [Hash] Variants of the selector
342
+ # @return [Hash{String => String}] Why a value of the selector is not a variant: its entry is declared by a bundle that is unavailable
343
+ def unavailable_variants(marker, point, mapping)
344
+ BundleRegistry.instance.unavailable_extensions(point).each_with_object({}) do |entry, result|
345
+ value = entry.fields[marker.fetch('value')]
346
+ result[value] ||= BundleRegistry.instance.load_error(entry.bundle) if value.is_a?(String) && !mapping.key?(value)
347
+ end
348
+ end
349
+
350
+ # @param path [String] Schema file of a variant (YAML or JSON)
351
+ # @return [Hash, String] The schema, or why it cannot be read
352
+ def read_variant(path)
353
+ variant = Yaml.safe_load(File.read(path))
354
+ variant.is_a?(Hash) ? variant : 'not a mapping'
355
+ rescue Psych::Exception, AssertError, SystemCallError => e
356
+ e.message
357
+ end
164
358
  end
165
359
  end
166
360
  end
@@ -18,44 +18,49 @@ module Aspera
18
18
  include Singleton
19
19
 
20
20
  def initialize
21
- # compiled documents, key: [registry key, partial]
21
+ # Compiled documents, key: [registry key, partial], value: [document of the registry, compiled document]
22
22
  @documents = {}
23
23
  end
24
24
 
25
25
  # Validate a value against a schema.
26
26
  # @param value [Object] value to validate
27
27
  # @param path [String] schema path, e.g. `opts:components.schemas.HttpOptions`
28
- # @param partial [Boolean] `true`: value may be incomplete, `required` is not enforced, `null` values (removal) are ignored
28
+ # @param partial [Boolean] `true`: value may be incomplete, `required` is not enforced, the selector of variants (`discriminator`) may be missing
29
+ # @param ignore_null [Boolean] `true`: `null` values (removal of an entry) are ignored, as if absent
29
30
  # @return [Array<String>] error messages, empty if valid or schema not validated
30
- def errors(value, path, partial: false)
31
+ def errors(value, path, partial: false, ignore_null: partial)
31
32
  return [] unless path.is_a?(String) && Registry.owned?(path)
32
33
  key, dotted = path.split(':', 2)
33
34
  schema = document(key, partial)
34
35
  schema = schema.ref("#/#{dotted.split('.').map { |s| s.gsub('~', '~0').gsub('/', '~1') }.join('/')}") if dotted
35
36
  # JSON view of value: symbol keys and values become strings
36
37
  data = JSON.parse(JSON.generate(value))
37
- data = without_null(data) if partial
38
- schema.validate(data).filter_map { |error| message(error, partial) }
38
+ data = without_null(data) if ignore_null
39
+ results = schema.validate(data).to_a
40
+ # Only an error that is reported cancels the unknown-key error (not the missing selector of a partial value)
41
+ reported = results.select { |error| message(error, partial) }
42
+ results.reject { |error| unreliable_unevaluated?(error, reported, results, key, partial) }.filter_map { |error| message(error, partial) }
39
43
  end
40
44
 
41
45
  private
42
46
 
43
47
  # @param key [String] registry key
44
48
  # @param partial [Boolean] remove `required` from schema
45
- # @return [JSONSchemer::Schema] compiled schema document
49
+ # @return [JSONSchemer::Schema] compiled schema document, compiled again when the registry reads the document again (see `Registry#reader`)
46
50
  def document(key, partial)
47
- @documents[[key, partial]] ||=
48
- begin
49
- require 'json_schemer'
50
- root = Registry.instance.reader(key).current
51
- root = without_required(root) if partial
52
- meta =
53
- case root['openapi']
54
- when /^3\.0\./ then JSONSchemer.openapi30
55
- when /^3\.1\./ then JSONSchemer.openapi31
56
- end
57
- meta ? JSONSchemer.schema(root, meta_schema: meta) : JSONSchemer.schema(root)
51
+ source = Registry.instance.reader(key).current
52
+ compiled_source, compiled = @documents[[key, partial]]
53
+ return compiled if compiled_source.equal?(source)
54
+ require 'json_schemer'
55
+ root = partial ? without_required(source) : source
56
+ meta =
57
+ case root['openapi']
58
+ when /^3\.0\./ then JSONSchemer.openapi30
59
+ when /^3\.1\./ then JSONSchemer.openapi31
58
60
  end
61
+ compiled = meta ? JSONSchemer.schema(root, meta_schema: meta) : JSONSchemer.schema(root)
62
+ @documents[[key, partial]] = [source, compiled]
63
+ compiled
59
64
  end
60
65
 
61
66
  # @param node [Object] schema node
@@ -78,15 +83,56 @@ module Aspera
78
83
  end
79
84
  end
80
85
 
86
+ # A key refused by `unevaluatedProperties` is unknown only if the variants of the object are evaluated without error.
87
+ # Else (selector of variants invalid, or error in the variant), no key of the variant is evaluated, and all are refused.
88
+ # With the selector missing in a partial value (ignored error), the variant is not known: a key of any variant is accepted.
89
+ # @param error [Hash] json_schemer error
90
+ # @param reported [Array<Hash>] Errors of the validation that are reported
91
+ # @param results [Array<Hash>] All errors of the validation
92
+ # @param key [String] registry key
93
+ # @param partial [Boolean] partial validation
94
+ # @return [Boolean] `true` if the error is a key refused by `unevaluatedProperties`, that is not a real unknown key
95
+ def unreliable_unevaluated?(error, reported, results, key, partial)
96
+ return false unless error['schema_pointer'].end_with?('/unevaluatedProperties')
97
+ object = error['data_pointer'].sub(%r{/[^/]*\z}, '')
98
+ inside = lambda do |other|
99
+ !other['schema_pointer'].eql?(error['schema_pointer']) &&
100
+ (other['data_pointer'].eql?(object) || other['data_pointer'].start_with?("#{object}/"))
101
+ end
102
+ return true if reported.any?(&inside)
103
+ return false unless partial && results.any? { |other| inside.call(other) && other['type'].eql?('discriminator') }
104
+ variant_key?(key, error['schema_pointer'].delete_suffix('/unevaluatedProperties'), error['data_pointer'].split('/').last)
105
+ end
106
+
107
+ # @param key [String] registry key
108
+ # @param pointer [String] JSON pointer of a schema node with `oneOf` variants
109
+ # @param name [String] property name
110
+ # @return [Boolean] `true` if a variant of the node has a property of that name
111
+ def variant_key?(key, pointer, name)
112
+ source = Registry.instance.reader(key).current
113
+ node = source.dig(*pointer.split('/').drop(1).map { |s| s.gsub('~1', '/').gsub('~0', '~') })
114
+ return false unless node.is_a?(Hash)
115
+ node.fetch('oneOf', []).any? do |variant|
116
+ ref = variant['$ref']
117
+ variant = source.dig(*ref.delete_prefix('#/').split('/')) if ref
118
+ variant.is_a?(Hash) && variant.fetch('properties', {}).key?(name)
119
+ end
120
+ end
121
+
81
122
  # @param error [Hash] json_schemer error
82
123
  # @param partial [Boolean] partial validation
83
124
  # @return [String, nil] message, or nil if error is ignored
84
125
  def message(error, partial)
126
+ # Same message for both ways of refusing other keys
127
+ return "object property at `#{error['data_pointer']}` is a disallowed additional property" if error['schema_pointer'].end_with?('/unevaluatedProperties')
85
128
  return error['error'] unless error['type'].eql?('discriminator')
86
129
  property = error['schema'].dig('discriminator', 'propertyName')
87
130
  object = error['data']
88
131
  # Partial value: selector may come from another source or a default
89
132
  return if partial && object.is_a?(Hash) && !object.key?(property)
133
+ # Value of an agent of a bundle that is unavailable: tell why, instead of listing the available ones
134
+ reason = error['schema'][Registry::UNAVAILABLE]&.[](object[property]) if object.is_a?(Hash) && object[property].is_a?(String)
135
+ return reason unless reason.nil?
90
136
  allowed = error['schema'].dig('discriminator', 'mapping')&.keys
91
137
  "value at `#{error['data_pointer']}/#{property}` is not one of: #{allowed}"
92
138
  end
@@ -29,6 +29,8 @@ module Aspera
29
29
  # So a text is valid from 1 to 2 periods after its creation (15 to 30 minutes by default), and is also accepted if the clock of the receiver is up to 1 period behind.
30
30
  # When unsealing, spaces and line breaks are ignored (a text split on several lines is valid), as well as quotes and punctuation around the text.
31
31
  # Letter case matters.
32
+ # Unless reversed, the text never starts with `-`, so that it can be given as an argument on a command line (it would be read as an option):
33
+ # with encryption, an IV that gives `-` is drawn again; without, the text starts with the header of deflate.
32
34
  #
33
35
  # With `encrypt: false`, there is no encryption and no validity period: the text is only Hash -> JSON -> deflate -> Base64 URL-safe, readable by anyone, without detection of errors.
34
36
  # It is used for links that must stay valid and are decoded by other programs (e.g. JavaScript in a browser).
@@ -67,6 +69,8 @@ module Aspera
67
69
  cipher = OpenSSL::Cipher.new(CIPHER).encrypt
68
70
  cipher.key = derive_key(base_key, secret, time.to_i / period)
69
71
  iv = cipher.random_iv
72
+ # The text starts with the IV: an IV that gives `-` as first character (`+` before URL-safe) is drawn again
73
+ iv = cipher.random_iv while [iv].pack('m0').start_with?('+')
70
74
  body = cipher.update(deflated) + cipher.final
71
75
  iv + cipher.auth_tag(TAG_SIZE) + body
72
76
  else