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,688 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: IBM Corp.
4
- # SPDX-License-Identifier: Apache-2.0
5
-
6
- require 'psych'
7
- require 'rexml/document'
8
- require 'stringio'
9
- require 'zlib'
10
- require 'rubygems/package'
11
-
12
- module Aspera
13
- # Check of an Orchestrator workflow file (`.yml`) or package (`.wkf`), before import.
14
- #
15
- # Orchestrator 4.1.6 does not validate the graph on import (`import_workflow`, `import_with_constraints`): an invalid workflow is imported,
16
- # then fails to publish, or at run time. These checks follow the rules of the designer (`Whiteboard#parse_workflow`).
17
- # With the specifications of plugins (`plugins.yml` of the plugin documentation), action templates and inputs of steps are also checked:
18
- # attributes and their values, required inputs, inputs and outputs that the plugin does not have with its template.
19
- # Not checked: availability of plugins on the server.
20
- #
21
- # The interface is that of a REST operation, so that it can be replaced by a call to Orchestrator when one exists:
22
- # - request: the fields of `import_workflow`: `file_name` (`import_file_name`) and `content` (`import_file`, bytes),
23
- # and the specifications of plugins (`specs`), that Orchestrator would not need
24
- # - response: a Hash (JSON compatible)
25
- # `valid`: `true` if there is no issue with severity `error`
26
- # `file_name`: name of the checked file
27
- # `issues`: list of Hash
28
- # `severity`: `error` (the workflow will not import, publish or run correctly) or `warning`
29
- # `code`: stable identifier of the rule, for programs, e.g. `graph.step_orphan`
30
- # `file`: file of the package where the issue is (absent for a single `.yml` file)
31
- # `path`: where in the file, e.g. `graph/Step[Say hello]`
32
- # `message`: description for humans
33
- #
34
- # The file is parsed without instantiating Ruby objects.
35
- class OrchestratorWorkflowChecker
36
- ERROR = 'error'
37
- WARNING = 'warning'
38
- # Columns of tables `workflows` and `whiteboards` (Orchestrator 4.1.6), and attributes ignored by the import
39
- WORKFLOW_ATTRIBUTES = %w[
40
- id name portable_id created_by folder_id generated_from revision_id label run_as source_revision comments description tags templates
41
- max_running cleanup_after_days purge_after_days user_lock locked_by created_at updated_at global_variables hide_workflow
42
- ].freeze
43
- WHITEBOARD_ATTRIBUTES = %w[id created_by revision_id workflow_id error_free revisions_log xml_export created_at updated_at].freeze
44
- VALUE_TYPES = %w[string int float flag date array hash object pwd attachment].freeze
45
- # Element 6 (plugin versions) is informational: Orchestrator 4.1.6 only reads elements 1 to 5
46
- ELEMENT_COUNTS = [5, 6].freeze
47
- TRUE_VALUES = %w[true 1 t].freeze
48
- # SimpleParameterLookup: separator of the columns of the table, input that returns the table indexed by a column
49
- LOOKUP_DELIMITER = ':::'
50
- LOOKUP_INDEX_INPUT = 'KeyForTableIndexing'
51
- UNNAMED = ['', 'undefined', 'null'].freeze
52
- SUCCESS_STATUSES = %w[complete true].freeze
53
- BOOLEAN_TEXT = %w[true false].freeze
54
- STEP_CHILDREN = %w[Inputs Outputs].freeze
55
- PARAMETER_MAPPINGS = %w[parameter global].freeze
56
- # Columns of every action template, besides those of the plugin
57
- TEMPLATE_COLUMNS = %w[id name comments created_at updated_at].freeze
58
- # Texts that the database layer (ActiveRecord) reads as false
59
- FALSE_VALUES = %w[false 0 f off].freeze
60
- INTEGER_TYPES = %w[integer bigint].freeze
61
- # Template attribute with Ruby code that computes the inputs or the outputs: they are then unknown
62
- SPEC_CODE = {inputs: 'inputs_spec_code', outputs: 'outputs_spec_code'}.freeze
63
- # Note of a plugin specification: some inputs or outputs come from the template, other than through declared lists
64
- PARTLY_DEFINED = {inputs: /\AInputs are partly defined/, outputs: /\AOutputs are partly defined/}.freeze
65
- # Placeholder that creates a required input: <%= variable %>
66
- PLACEHOLDER = /<%=\s*([A-Za-z_]\w*)\s*%>/
67
- # Value of a template attribute that is a single name (of an input or an output): no line break, no structure (type map, list)
68
- SINGLE_NAME = /\A[^\r\n{}\[\],:=]+\z/
69
- # Column separator of a table (attribute `parameters_associations` of `SimpleParameterLookup`), whose first line holds the column names
70
- TABLE_SEPARATOR = ':::'
71
- # Elements of a step that a `Map_to` of type `output` gives as attributes (in lower case)
72
- STEP_IDENTITY = %w[Step_name Step_type Action_id].freeze
73
- # Maximum size of the entries of a package once decompressed: a small package can decompress to gigabytes (decompression bomb)
74
- PACKAGE_MAX_SIZE = 256 * 1024 * 1024
75
- private_constant :PACKAGE_MAX_SIZE
76
- private_constant :WORKFLOW_ATTRIBUTES, :WHITEBOARD_ATTRIBUTES, :VALUE_TYPES, :ELEMENT_COUNTS, :TRUE_VALUES, :UNNAMED, :SUCCESS_STATUSES,
77
- :BOOLEAN_TEXT, :STEP_CHILDREN, :PARAMETER_MAPPINGS, :TEMPLATE_COLUMNS, :FALSE_VALUES, :INTEGER_TYPES, :SPEC_CODE, :PARTLY_DEFINED, :PLACEHOLDER,
78
- :STEP_IDENTITY, :SINGLE_NAME, :TABLE_SEPARATOR, :LOOKUP_DELIMITER, :LOOKUP_INDEX_INPUT
79
-
80
- class << self
81
- # @param file_name [String] Name of the file, ending with `yml` or `wkf`
82
- # @param content [String] Bytes of the file
83
- # @param specs [Hash, nil] Specifications of plugins (`plugins.yml`), to check templates and inputs of steps, or nil
84
- # @return [Hash] Response, see class description
85
- def check(file_name:, content:, specs: nil)
86
- checker = new(file_name, specs)
87
- checker.run(content)
88
- {
89
- 'valid' => checker.issues.none? { |issue| issue['severity'].eql?(ERROR) },
90
- 'file_name' => file_name,
91
- 'issues' => checker.issues
92
- }
93
- end
94
- end
95
-
96
- attr_reader :issues
97
-
98
- # @param file_name [String] Name of the file
99
- # @param specs [Hash, nil] Specifications of plugins: class name => attributes, inputs, outputs
100
- def initialize(file_name, specs = nil)
101
- @file_name = file_name
102
- @specs = specs
103
- @issues = []
104
- # file of the package being checked
105
- @member = nil
106
- # attributes of the action templates of the workflow being checked, by key <StepType>__<N>
107
- @template_attributes = {}
108
- end
109
-
110
- # @param content [String] Bytes of the file
111
- def run(content)
112
- case File.extname(@file_name)
113
- when '.yml' then check_yaml(content)
114
- when '.wkf' then check_package(content)
115
- else add(ERROR, 'file.extension', 'file', "extension must be yml or wkf: #{@file_name}")
116
- end
117
- end
118
-
119
- private
120
-
121
- def add(severity, code, path, message)
122
- @issues.push({'severity' => severity, 'code' => code, 'file' => @member, 'path' => path, 'message' => message}.compact)
123
- end
124
-
125
- # @param content [String] Bytes of a `.wkf` file: gzipped tar with a manifest (list of files, the first one is the main workflow)
126
- def check_package(content)
127
- files = {}
128
- size = 0
129
- begin
130
- Zlib::GzipReader.wrap(StringIO.new(content)) do |gzip|
131
- Gem::Package::TarReader.new(gzip) do |tar|
132
- tar.each do |entry|
133
- # Size declared in the header: checked before the entry is decompressed (read, or skipped)
134
- size += entry.header.size
135
- return add(ERROR, 'package.too_large', 'file', "package is too large when decompressed: more than #{PACKAGE_MAX_SIZE} bytes") if size > PACKAGE_MAX_SIZE
136
- files[entry.full_name] = entry.read if entry.file?
137
- end
138
- end
139
- end
140
- rescue Zlib::Error, Gem::Package::Error => e
141
- return add(ERROR, 'package.archive', 'file', "not a gzipped tar archive: #{e.message}")
142
- end
143
- manifest = files.keys.find { |name| File.basename(name).match?(/\AWorkflow_.*\.txt\z/) }
144
- return add(ERROR, 'package.manifest_missing', 'file', 'no manifest file (Workflow_*.txt) in package') if manifest.nil?
145
- list = Psych.safe_load(files[manifest])
146
- return add(ERROR, 'package.manifest_invalid', manifest, 'manifest must be a list of file names') unless list.is_a?(Array) && !list.empty? && list.all?(String)
147
- list.each_with_index do |name, index|
148
- member = files.find { |key, _| File.basename(key).eql?(File.basename(name)) }&.last
149
- next add(ERROR, 'package.file_missing', manifest, "file listed but not in package: #{name}") if member.nil?
150
- # sub-workflows are checked as the main workflow; remote nodes and nested packages are not
151
- next unless name.end_with?('.yml') && (index.zero? || File.basename(name).start_with?('Workflow_'))
152
- @member = File.basename(name)
153
- check_yaml(member)
154
- end
155
- @member = nil
156
- rescue Psych::Exception => e
157
- add(ERROR, 'package.manifest_invalid', manifest.to_s, "invalid manifest: #{e.message}")
158
- end
159
-
160
- # @param content [String] Bytes of a workflow file
161
- def check_yaml(content)
162
- text = content.dup.force_encoding(Encoding::UTF_8)
163
- return add(ERROR, 'yaml.encoding', 'file', 'file is not UTF-8') unless text.valid_encoding?
164
- begin
165
- root = Psych.parse_stream(text).children.first&.root
166
- rescue Psych::SyntaxError => e
167
- return add(ERROR, 'yaml.invalid', 'file', "invalid YAML: #{e.message}")
168
- end
169
- return add(ERROR, 'yaml.empty', 'file', 'empty file') if root.nil?
170
- return add(ERROR, 'yaml.not_list', 'file', 'a workflow file is a YAML list of elements') unless root.is_a?(Psych::Nodes::Sequence)
171
- @plain = text.lines.none? { |line| line.match?(/^ *concise_attributes:/) }
172
- @template_attributes = {}
173
- check_layout(text) if @plain
174
- elements = root.children
175
- add(ERROR, 'yaml.element_count', 'file', "expected #{ELEMENT_COUNTS.join(' or ')} elements (workflow, whiteboard, templates, dependencies, packed dependencies, plugin versions), found #{elements.size}") unless ELEMENT_COUNTS.include?(elements.size)
176
- return if elements.size < 2
177
- workflow = check_attributes(elements[0], 'Workflow', 'workflow', WORKFLOW_ATTRIBUTES)
178
- add(ERROR, 'workflow.name_missing', 'workflow', 'attribute name is missing') if workflow['name'].to_s.strip.empty?
179
- whiteboard = check_attributes(elements[1], 'Whiteboard', 'whiteboard', WHITEBOARD_ATTRIBUTES)
180
- add(ERROR, 'whiteboard.error_free', 'whiteboard', 'error_free is not true: the workflow cannot be published') unless TRUE_VALUES.include?(whiteboard['error_free'].to_s.downcase)
181
- templates = elements.size > 2 ? check_templates(elements[2]) : []
182
- elements[3..4]&.each_with_index do |element, index|
183
- add(ERROR, 'dependencies.not_map', "element #{index + 4}", 'must be a map') unless element.is_a?(Psych::Nodes::Mapping)
184
- end
185
- if whiteboard['xml_export'].to_s.strip.empty?
186
- add(ERROR, 'whiteboard.xml_missing', 'whiteboard', 'attribute xml_export is missing')
187
- else
188
- check_graph(whiteboard['xml_export'], templates)
189
- end
190
- check_dependencies(elements[3], elements[4]) if elements.size > 4
191
- end
192
-
193
- # Plain format is converted by Orchestrator line by line: each element starts with a dash at column 0
194
- def check_layout(text)
195
- count = text.lines.count { |line| line.match?(/^- /) }
196
- return if ELEMENT_COUNTS.include?(count)
197
- add(ERROR, 'yaml.layout', 'file', "plain format: each element must start with '- ' at column 0 (#{ELEMENT_COUNTS.join(' or ')} expected), found #{count} such lines")
198
- end
199
-
200
- # @return [Hash{String=>Psych::Nodes::Node}] Keys and values of a mapping
201
- def pairs(node)
202
- return {} unless node.is_a?(Psych::Nodes::Mapping)
203
- node.children.each_slice(2).to_h { |key, value| [key.respond_to?(:value) ? key.value : nil, value] }
204
- end
205
-
206
- def scalar(node)
207
- node.is_a?(Psych::Nodes::Scalar) ? node.value : nil
208
- end
209
-
210
- # @return [Hash{String=>String}] Attributes of a workflow, a whiteboard or a template, in plain or Rails format
211
- def attributes(node)
212
- content = pairs(node)
213
- if content.key?('concise_attributes')
214
- content['concise_attributes'].children.to_h do |item|
215
- item_pairs = pairs(item)
216
- [scalar(item_pairs['name']), scalar(item_pairs['value_before_type_cast'])]
217
- end
218
- else
219
- inner = content['attributes']
220
- (inner.is_a?(Psych::Nodes::Mapping) ? pairs(inner) : content.except('attributes', 'new_record', 'active_record_yaml_version')).transform_values { |value| scalar(value) }
221
- end
222
- end
223
-
224
- def check_attributes(node, klass, path, known)
225
- unless node.is_a?(Psych::Nodes::Mapping) && node.tag.eql?("!ruby/object:#{klass}")
226
- add(ERROR, "#{path}.type", path, "element must be a map tagged !ruby/object:#{klass}")
227
- return {}
228
- end
229
- attributes(node).tap do |attrs|
230
- attrs.each_key { |name| add(WARNING, "#{path}.attribute_unknown", path, "unknown attribute: #{name} (the import may fail)") unless known.include?(name) }
231
- end
232
- end
233
-
234
- # @return [Array<String>] Keys of the action templates
235
- def check_templates(node)
236
- return [] unless node.is_a?(Psych::Nodes::Mapping)
237
- pairs(node).filter_map do |key, template|
238
- path = "templates/#{key}"
239
- match = key.to_s.match(/\A(.+)__(\d+)\z/)
240
- if match.nil?
241
- add(ERROR, 'template.key', path, "key must be <StepType>__<N>: #{key}")
242
- elsif !template.respond_to?(:tag) || !template.tag.eql?("!ruby/object:#{match[1]}")
243
- add(ERROR, 'template.tag', path, "value must be tagged !ruby/object:#{match[1]}")
244
- else
245
- check_boolean_values(path, template) if @plain
246
- @template_attributes[key] = attributes(template)
247
- check_template_attributes(path, match[1], @template_attributes[key]) unless @specs.nil?
248
- end
249
- key
250
- end
251
- end
252
-
253
- # In plain format, a blank attribute is dropped, and false is blank
254
- def check_boolean_values(path, template)
255
- attributes(template).each do |name, value|
256
- add(WARNING, 'template.boolean', path, "#{name} is #{value}: write 1 or 0, false is dropped in plain format") if BOOLEAN_TEXT.include?(value)
257
- end
258
- end
259
-
260
- def check_dependencies(listed, packed)
261
- return unless listed.is_a?(Psych::Nodes::Mapping) && packed.is_a?(Psych::Nodes::Mapping)
262
- external = pairs(listed).values.flat_map { |list| list.is_a?(Psych::Nodes::Sequence) ? list.children : [] }
263
- return if external.empty? || !packed.children.empty?
264
- names = external.map do |dep|
265
- fields = pairs(dep)
266
- "#{scalar(fields[':entity'] || fields['entity'])} #{scalar(fields[':id_value'] || fields['id_value'])}".strip
267
- end
268
- add(WARNING, 'dependencies.external', 'dependencies', "uses entities not included in the file, they must exist on the server: #{names.uniq.join(', ')}")
269
- end
270
-
271
- def text_of(element, name)
272
- element.elements[name]&.text&.strip
273
- end
274
-
275
- def check_graph(xml, templates)
276
- begin
277
- root = REXML::Document.new(xml).root
278
- rescue REXML::ParseException => e
279
- return add(ERROR, 'graph.xml_invalid', 'xml_export', "invalid XML: #{e.message.lines.first&.strip}")
280
- end
281
- return add(ERROR, 'graph.xml_invalid', 'xml_export', 'no XML root element') if root.nil?
282
- terminals = %w[Start End Fail Error].to_h { |name| [name, root.get_elements(name)] }
283
- terminals.each do |name, nodes|
284
- add(ERROR, 'graph.terminal_count', "graph/#{name}", "#{name} must be present once, found #{nodes.size}") unless nodes.size.eql?(1)
285
- end
286
- steps = root.get_elements('Steps/Step')
287
- add(ERROR, 'graph.no_step', 'graph', 'at least one Step is required') if steps.empty?
288
- ids = (terminals.values.flatten + steps).map { |node| node.attributes['id'] }
289
- (ids.tally.select { |_, count| count > 1 }.keys + ids.compact.select(&:empty?)).each do |id|
290
- add(ERROR, 'graph.id_not_unique', 'graph', "node id must be unique and not empty: '#{id}'")
291
- end
292
- check_steps(steps, templates)
293
- closing = terminals.values_at('End', 'Fail', 'Error').flatten
294
- (closing + steps).each { |node| check_node(node, ids) }
295
- check_branches(closing, steps)
296
- # starvation is computed on a graph without loop
297
- check_starvation(terminals['Start'].first&.attributes&.[]('id'), closing, steps) unless check_loops(closing, steps)
298
- check_parameters(root, steps)
299
- check_routers(root)
300
- check_lookups(steps)
301
- check_step_interfaces(steps) unless @specs.nil?
302
- end
303
-
304
- # SimpleParameterLookup returns a row only if an input selects it: an input named as a column of the header of the table.
305
- # Without one, no row matches and the step ends with Failed (No configuration match), unless it returns the array of rows
306
- # (SimpleParameterLookup#execute). The header of a table in a file (param_file_name) is not known.
307
- def check_lookups(steps)
308
- steps.each do |step|
309
- next unless text_of(step, 'Step_type').eql?('SimpleParameterLookup')
310
- values = @template_attributes["SimpleParameterLookup__#{text_of(step, 'Action_id')}"]
311
- next if values.nil? || blank?(values['parameters_associations']) || !blank?(values['param_file_name'])
312
- next if TRUE_VALUES.include?(values['return_array_of_rows'].to_s.downcase)
313
- header = values['parameters_associations'].lines.first.to_s.strip.split(LOOKUP_DELIMITER, -1).map(&:strip)
314
- # a carried variable is also given to the step under its name
315
- provided = step.get_elements('Inputs/Input').map { |input| input.attributes['name'] } + step.get_elements('Outputs/Carry_thru').map { |carry| carry.attributes['name'] }
316
- next if provided.include?(LOOKUP_INDEX_INPUT) || provided.intersect?(header)
317
- add(
318
- ERROR, 'step.lookup_without_key', node_path(step),
319
- "no input is mapped to a column of the table (#{header.join(', ')}): no row matches and the step ends with Failed, unless return_array_of_rows is set"
320
- )
321
- end
322
- end
323
-
324
- # Line styles of links in the designer: it writes `new <router>()` in the page to draw each link (WhiteboardsHelper#connect_xmlsteps)
325
- ROUTERS = %w[Manhattan Bezier Null Fan].map { |name| "draw2d.#{name}ConnectionRouter" }.freeze
326
-
327
- # Links: prerequisites of nodes and links of parameters (Parameter in Start or Step); absent router: Manhattan
328
- def check_routers(root)
329
- root.each_element('//Prerequisite[@router] | //Start/Parameters/Parameter[@router] | //Step/Parameters/Parameter[@router]') do |link|
330
- router = link.attributes['router']
331
- next if ROUTERS.include?(router)
332
- add(
333
- ERROR, 'graph.router', node_path(link.parent.parent),
334
- "router '#{router}' of the link from '#{link.attributes['id']}' is not one of #{ROUTERS.join(', ')}: the designer cannot draw the workflow"
335
- )
336
- end
337
- end
338
-
339
- def node_path(node)
340
- node.name.eql?('Step') ? "graph/Step[#{text_of(node, 'Step_name')}]" : "graph/#{node.name}"
341
- end
342
-
343
- def check_node(node, ids)
344
- path = node_path(node)
345
- factor = text_of(node, 'Synch_factor')
346
- if factor.nil? || !factor.match?(/\A-?\d+\z/)
347
- add(ERROR, 'graph.synch_factor', path, 'Synch_factor is missing or not an integer')
348
- elsif factor.to_i.negative?
349
- add(ERROR, 'graph.synch_factor_negative', path, 'negative Synch_factor is never met')
350
- elsif factor.to_i.positive? && %w[x y].any? { |name| node.elements['Synch_factor'].attributes[name].to_s.empty? }
351
- # the designer writes the position of the join symbol, and draws the workflow with it (WhiteboardsHelper#draw_operator)
352
- add(WARNING, 'graph.synch_factor_position', path, 'Synch_factor is not 0 and has no attributes x and y (position of the join symbol): the designer shows an empty canvas')
353
- end
354
- node.get_elements('Prerequisites/Prerequisite').each do |pre|
355
- add(ERROR, 'graph.prerequisite_unknown', path, "prerequisite refers to unknown node '#{pre.attributes['id']}'") unless ids.include?(pre.attributes['id'])
356
- end
357
- end
358
-
359
- def check_steps(steps, templates)
360
- names = []
361
- steps.each do |step|
362
- name = text_of(step, 'Step_name')
363
- type = text_of(step, 'Step_type')
364
- action_id = text_of(step, 'Action_id')
365
- path = node_path(step)
366
- if UNNAMED.include?(name.to_s)
367
- add(ERROR, 'graph.step_unnamed', "graph/Step[#{step.attributes['id']}]", 'step is not named')
368
- elsif names.include?(name)
369
- add(ERROR, 'graph.step_name_not_unique', path, 'step name is not unique')
370
- end
371
- names.push(name)
372
- if UNNAMED.include?(type.to_s)
373
- add(ERROR, 'graph.step_type_missing', path, 'Step_type is not defined')
374
- elsif action_id.to_s.empty?
375
- add(ERROR, 'graph.action_id_missing', path, 'Action_id is missing')
376
- elsif !templates.include?("#{type}__#{action_id}")
377
- add(ERROR, 'graph.template_missing', path, "no action template #{type}__#{action_id} in element 3")
378
- end
379
- STEP_CHILDREN.each do |child|
380
- add(ERROR, 'graph.step_element_missing', path, "#{child} is missing (may be empty)") if step.elements[child].nil?
381
- end
382
- add(ERROR, 'graph.step_orphan', path, 'no prerequisite, the step never runs (orphaned)') if step.get_elements('Prerequisites/Prerequisite').empty?
383
- check_output_references(step, steps, path)
384
- end
385
- end
386
-
387
- def check_output_references(step, steps, path)
388
- step.get_elements('Inputs/Input/Map_to').each do |map|
389
- next unless map.attributes['type'].eql?('output')
390
- source = steps.find { |other| text_of(other, 'Step_name').eql?(map.attributes['step_name']) }
391
- next unless source.nil? || !text_of(source, 'Step_type').eql?(map.attributes['step_type']) || !text_of(source, 'Action_id').eql?(map.attributes['action_id'])
392
- add(ERROR, 'graph.output_unknown', path, "input #{map.parent.attributes['name']} refers to unknown output of step '#{map.attributes['step_name']}' (step_name, step_type, action_id must match)")
393
- end
394
- end
395
-
396
- def check_branches(closing, steps)
397
- success = ->(pre) { SUCCESS_STATUSES.include?(pre.attributes['status'].to_s.downcase) }
398
- consumers = (closing + steps).flat_map { |node| node.get_elements('Prerequisites/Prerequisite').select(&success).map { |pre| pre.attributes['id'] } }
399
- steps.each do |step|
400
- next if consumers.include?(step.attributes['id'])
401
- add(ERROR, 'graph.step_no_output', node_path(step), 'no node follows it with status Complete (step does not have output)')
402
- end
403
- return unless closing.all? { |node| node.get_elements('Prerequisites/Prerequisite').empty? }
404
- add(ERROR, 'graph.no_termination', 'graph', 'workflow does not terminate: End, Fail and Error have no prerequisite')
405
- end
406
-
407
- # Starvation: a node that waits for exclusive conditions never starts, and the work order never ends.
408
- # Conditions of a node: pairs [step id, status] that must all be true for the node to start.
409
- # With Synch_factor 0 (AND), those of all its prerequisites; otherwise (OR), those common to all its prerequisites.
410
- # A prerequisite on a step adds its status to the conditions of that step.
411
- # A step ends with one status: two statuses of the same step in the conditions of a node are exclusive,
412
- # for example the Complete and Failed exits of a step, or an if and an else branch joined without OR.
413
- # Not checked: steps after an ArrayFanout (one execution per element, with different statuses).
414
- def check_starvation(start_id, closing, steps)
415
- nodes = (closing + steps).to_h { |node| [node.attributes['id'], node] }
416
- fanned = steps.select do |step|
417
- step.get_elements('Prerequisites/Prerequisite').any? { |pre| text_of(nodes[pre.attributes['id']] || step, 'Step_type').eql?('ArrayFanout') }
418
- end.map { |step| step.attributes['id'] }
419
- memo = {}
420
- conditions = lambda do |id, visiting|
421
- return [] if id.eql?(start_id) || !nodes.key?(id) || visiting.include?(id)
422
- return memo[id] if memo.key?(id)
423
- node = nodes[id]
424
- branches = node.get_elements('Prerequisites/Prerequisite').map do |pre|
425
- source = pre.attributes['id']
426
- own = source.eql?(start_id) || fanned.include?(source) ? [] : [[source, pre.attributes['status'].to_s.downcase]]
427
- (own + conditions.call(source, visiting + [id])).uniq
428
- end
429
- memo[id] = if branches.empty? then []
430
- elsif text_of(node, 'Synch_factor').to_i.zero? then branches.reduce(:|)
431
- else branches.reduce(:&)
432
- end
433
- end
434
- exclusive = ->(list) { list.group_by(&:first).select { |_, pairs| pairs.size > 1 }.transform_values { |pairs| pairs.map(&:last) } }
435
- nodes.each do |id, node|
436
- conflicts = exclusive.call(conditions.call(id, []))
437
- # report where the conflict starts, not on the nodes that follow
438
- inherited = node.get_elements('Prerequisites/Prerequisite').flat_map { |pre| exclusive.call(conditions.call(pre.attributes['id'], [])).keys }
439
- conflicts.except(*inherited).each do |step_id, statuses|
440
- step_name = text_of(nodes[step_id], 'Step_name')
441
- add(
442
- ERROR, 'graph.starvation', node_path(node),
443
- "never starts: it waits for step '#{step_name}' to end with #{statuses.map(&:capitalize).join(' and ')}, which are exclusive; " \
444
- 'join exclusive branches with an OR (Synch_factor 1), otherwise the work order never ends'
445
- )
446
- end
447
- end
448
- end
449
-
450
- # Loop: a link back to a node it comes from. A step runs once in a work order: it does not run again.
451
- # @return [Boolean] true if a loop was found
452
- def check_loops(closing, steps)
453
- found = false
454
- nodes = (closing + steps).to_h { |node| [node.attributes['id'], node] }
455
- sources = nodes.transform_values { |node| node.get_elements('Prerequisites/Prerequisite').map { |pre| pre.attributes['id'] }.uniq & nodes.keys }
456
- state = {}
457
- visit = lambda do |id|
458
- state[id] = :visiting
459
- sources[id].each do |source|
460
- if state[source].eql?(:visiting)
461
- found = true
462
- add(
463
- ERROR, 'graph.loop', node_path(nodes[source]),
464
- "link back to '#{text_of(nodes[id], 'Step_name') || nodes[id].name}' (loop): a step runs only once in a work order; " \
465
- 'to repeat, use a sub-workflow with retries, or an ArrayFanout'
466
- )
467
- elsif state[source].nil?
468
- visit.call(source)
469
- end
470
- end
471
- state[id] = :done
472
- end
473
- nodes.each_key { |id| visit.call(id) if state[id].nil? }
474
- found
475
- end
476
-
477
- def check_parameters(root, steps)
478
- linked = (root.get_elements('Start/Parameters/Parameter') + steps.flat_map { |step| step.get_elements('Parameters/Parameter') }).map { |link| link.attributes['id'] }
479
- defined = {}
480
- root.get_elements('Parameters/Parameter').each do |parameter|
481
- name = text_of(parameter, 'Name')
482
- type = text_of(parameter, 'Value_type')
483
- path = "graph/Parameter[#{name || parameter.attributes['id']}]"
484
- add(ERROR, 'graph.parameter_name', path, 'Name is missing') if name.to_s.empty?
485
- add(ERROR, 'graph.parameter_type', path, "Value_type must be one of #{VALUE_TYPES.join(', ')}") unless VALUE_TYPES.include?(type)
486
- mandatory_at_runtime = text_of(parameter, 'Runtime_override').eql?('true') && !text_of(parameter, 'Runtime_optional').eql?('true')
487
- add(WARNING, 'graph.parameter_value', path, 'Value is missing') if !mandatory_at_runtime && parameter.elements['Value'].nil?
488
- defined[name] = parameter.attributes['id']
489
- end
490
- steps.each do |step|
491
- step.get_elements('Inputs/Input/Map_to').each do |map|
492
- next unless PARAMETER_MAPPINGS.include?(map.attributes['type'])
493
- id = defined[map.attributes['name']]
494
- if id.nil?
495
- add(ERROR, 'graph.parameter_undefined', node_path(step), "input refers to undefined parameter '#{map.attributes['name']}'")
496
- elsif !linked.include?(id)
497
- add(ERROR, 'graph.parameter_not_linked', node_path(step), "parameter '#{map.attributes['name']}' is not linked to Start or to a step: inputs mapped to it are not created")
498
- end
499
- end
500
- end
501
- end
502
-
503
- # --- Checks with the specifications of plugins ---
504
-
505
- def blank?(value)
506
- value.nil? || value.to_s.strip.empty?
507
- end
508
-
509
- # @param values [Hash{String=>String}] Attributes of the template
510
- def check_template_attributes(path, type, values)
511
- spec = @specs[type]
512
- if spec.nil?
513
- similar = @specs.keys.find { |name| name.casecmp?(type) }
514
- return add(ERROR, 'template.plugin_case', path, "plugin #{type} does not exist, class names are case sensitive: #{similar}") if similar
515
- return add(WARNING, 'template.plugin_unknown', path, "plugin #{type} is not in the specifications: its template and the inputs of its steps are not checked")
516
- end
517
- columns = spec['attributes'] || {}
518
- values.each do |name, value|
519
- attribute = columns[name]
520
- if attribute.nil?
521
- next if TEMPLATE_COLUMNS.include?(name)
522
- next add(ERROR, 'template.attribute_unknown', path, "#{type} has no attribute #{name}: the import fails") if @plain
523
- next add(WARNING, 'template.attribute_unknown', path, "#{type} has no attribute #{name}: the import may fail")
524
- end
525
- # a placeholder is replaced at run time
526
- next if blank?(value) || value.include?('<%')
527
- check_value(path, name, attribute, value)
528
- end
529
- end
530
-
531
- # Values are cast by the database layer (ActiveRecord): a text that is not false is true, a text that is not a number is 0
532
- def check_value(path, name, attribute, value)
533
- case attribute['type']
534
- when 'boolean'
535
- return if (TRUE_VALUES + FALSE_VALUES).include?(value.downcase)
536
- return add(WARNING, 'template.attribute_value', path, "#{name}: #{value} is read as true: write 1 or 0")
537
- when *INTEGER_TYPES
538
- return add(WARNING, 'template.attribute_value', path, "#{name}: #{value} is not an integer, it is read as #{value.to_i}") unless value.match?(/\A-?\d+\z/)
539
- end
540
- allowed = attribute['values']
541
- return if allowed.nil? || allowed.map(&:to_s).include?(value)
542
- add(ERROR, 'template.attribute_value', path, "#{name}: #{value} is not an allowed value: #{allowed.join(', ')}")
543
- end
544
-
545
- # Value of an attribute as the plugin sees it: typed for booleans and integers
546
- def typed(value, type)
547
- return value unless value.is_a?(String)
548
- case type
549
- when 'boolean' then !FALSE_VALUES.include?(value.downcase)
550
- when *INTEGER_TYPES then value.to_i
551
- else value
552
- end
553
- end
554
-
555
- # Values of the attributes of a template as the plugin sees them: nil when blank
556
- # An attribute not in the template takes its database default; in plain format, so does a blank one (and false is blank)
557
- # @return [Hash{String=>Object}]
558
- def effective_values(spec, values)
559
- (spec['attributes'] || {}).to_h do |name, attribute|
560
- value = values[name]
561
- value = nil if blank?(value) || (@plain && value.eql?('false'))
562
- value = attribute['default'] if value.nil? && (@plain || !values.key?(name))
563
- [name, typed(value, attribute['type'])]
564
- end
565
- end
566
-
567
- # @param conditions [Hash] `if_blank`, `if_set`, `when` and `conditional` of an input or output of the specifications
568
- # @return [Boolean, nil] true if the conditions are met, nil if unknown
569
- def met(conditions, values)
570
- return if conditions['conditional']
571
- Array(conditions['if_blank']).all? { |name| values[name].nil? } &&
572
- Array(conditions['if_set']).all? { |name| !values[name].nil? } &&
573
- (conditions['when'] || {}).all? do |name, condition|
574
- value = values[name]
575
- if condition.key?('in')
576
- condition['in'].any? { |item| item.nil? ? value.nil? : item.to_s.eql?(value.to_s) }
577
- else
578
- !value.nil? && condition['not_in'].none? { |item| item.to_s.eql?(value.to_s) }
579
- end
580
- end
581
- end
582
-
583
- # @return [Array<String>] Names declared by a type map `{'name'=>'type'}` (Ruby or JSON syntax) or a list `['name']`
584
- def declared_names(value)
585
- text = value.strip
586
- return text.scan(/['"]([^'"]+)['"]\s*(?:=>|:)/).flatten if text.start_with?('{')
587
- return text.scan(/['"]([^'"]+)['"]/).flatten if text.start_with?('[')
588
- []
589
- end
590
-
591
- # Names given by the value of a template attribute, for a name in angle brackets (`<attribute>`) in the specification
592
- # @return [Array<String>, nil] The names, or `nil` if they cannot be found in the value
593
- def names_in_value(value)
594
- text = value.to_s.strip
595
- return [] if text.empty?
596
- return [text] if text.match?(SINGLE_NAME)
597
- header = text.lines.first.strip
598
- return header.split(TABLE_SEPARATOR).map(&:strip) if header.include?(TABLE_SEPARATOR)
599
- nil
600
- end
601
-
602
- # Inputs and outputs of a step, for the attributes of its template
603
- # @return [Hash] `:inputs` and `:outputs`: name => {`exists`, `required`} (true, false or nil if unknown),
604
- # and `:complete`: kind => true if all inputs (or outputs) are known, so that an other one does not exist
605
- def step_interface(spec, attributes)
606
- values = effective_values(spec, attributes)
607
- interface = {inputs: {}, outputs: {}, complete: {}}
608
- %i[inputs outputs].each do |kind|
609
- # false when names come from an attribute value whose format is not known
610
- names_known = true
611
- (spec[kind.to_s] || {}).each do |name, info|
612
- exists = met(info, values)
613
- next if exists.eql?(false)
614
- names = [name]
615
- # a name in angle brackets comes from the value of that attribute
616
- if name =~ /\A<(\w+)>\z/
617
- names = names_in_value(values[Regexp.last_match(1)])
618
- names_known = false if names.nil?
619
- end
620
- required = info['required'].is_a?(Hash) ? met(info['required'], values) : info['required']
621
- Array(names).each do |each_name|
622
- interface[kind][each_name] = {'exists' => exists, 'required' => required.eql?('depends') ? nil : required}
623
- end
624
- end
625
- declared = (spec['attributes'] || {}).values.any? { |attribute| attribute['declares'].to_s.end_with?(kind.to_s) }
626
- partly = Array(spec['notes']).any? { |note| note.match?(PARTLY_DEFINED[kind]) }
627
- interface[:complete][kind] = names_known && (declared || !partly) && blank?(attributes[SPEC_CODE[kind]])
628
- end
629
- (spec['attributes'] || {}).each do |name, attribute|
630
- value = attributes[name]
631
- next if blank?(value)
632
- case attribute['declares']
633
- when 'required_inputs', 'optional_inputs'
634
- required = attribute['declares'].eql?('required_inputs')
635
- declared_names(value).each { |input| interface[:inputs][input] ||= {'exists' => true, 'required' => required} }
636
- when 'outputs'
637
- declared_names(value).each { |output| interface[:outputs][output] ||= {'exists' => true} }
638
- end
639
- next unless attribute['placeholders']
640
- value.scan(PLACEHOLDER).flatten.each { |input| interface[:inputs][input] ||= {'exists' => true, 'required' => true} }
641
- # inputs of other placeholders (functions of variables) are not known
642
- interface[:complete][:inputs] = false if value.scan('<%').size > value.scan(PLACEHOLDER).size
643
- end
644
- interface
645
- end
646
-
647
- def check_step_interfaces(steps)
648
- interfaces = {}
649
- interface_of = lambda do |step|
650
- type = text_of(step, 'Step_type')
651
- key = "#{type}__#{text_of(step, 'Action_id')}"
652
- next if @specs[type].nil? || !@template_attributes.key?(key)
653
- interfaces[key] ||= step_interface(@specs[type], @template_attributes[key])
654
- end
655
- steps.each do |step|
656
- path = node_path(step)
657
- type = text_of(step, 'Step_type')
658
- interface = interface_of.call(step)
659
- unless interface.nil?
660
- inputs = step.get_elements('Inputs/Input').map { |input| input.attributes['name'] }
661
- # a carried variable is also given to the step under its name
662
- provided = inputs + step.get_elements('Outputs/Carry_thru').map { |carry| carry.attributes['name'] }
663
- unknown = interface[:complete][:inputs] ? inputs - interface[:inputs].keys : []
664
- unknown.each { |name| add(WARNING, 'step.input_unknown', path, "#{type} has no input #{name} with this template: Orchestrator ignores it") }
665
- interface[:inputs].each do |name, input|
666
- next unless input['exists'].eql?(true) && input['required'].eql?(true) && !provided.include?(name)
667
- add(ERROR, 'step.input_missing', path, "required input #{name} is not mapped")
668
- end
669
- if interface[:complete][:outputs]
670
- (step.get_elements('Outputs/Output').map { |output| output.attributes['name'] } - interface[:outputs].keys).each do |name|
671
- add(WARNING, 'step.output_unknown', path, "#{type} has no output #{name} with this template: its settings are ignored")
672
- end
673
- end
674
- end
675
- step.get_elements('Inputs/Input/Map_to').each do |map|
676
- next unless map.attributes['type'].eql?('output')
677
- source = steps.find { |other| STEP_IDENTITY.all? { |name| text_of(other, name).eql?(map.attributes[name.downcase]) } }
678
- source_interface = source && interface_of.call(source)
679
- next if source_interface.nil? || !source_interface[:complete][:outputs] || source_interface[:outputs].key?(map.attributes['name'])
680
- add(
681
- WARNING, 'step.output_not_produced', path,
682
- "input #{map.parent.attributes['name']} maps output #{map.attributes['name']} of step '#{map.attributes['step_name']}', which #{map.attributes['step_type']} does not produce with its template"
683
- )
684
- end
685
- end
686
- end
687
- end
688
- end