vault-upgrade-hook icon indicating copy to clipboard operation
vault-upgrade-hook copied to clipboard

Allow to parameterize scripts via bindings

Open kwin opened this issue 5 years ago • 1 comments

It would be nice to pass properties from the hook to all contained scripts (e.g. to influence the root node from which to start). Otherwise this information has to be repeated in all contained scripts. For Groovy/Scripting and Sling Pipes one can use bindings for that. I would suggest that nested properties with a specific name are created as bindings automatically

kwin avatar May 25 '20 12:05 kwin

EDIT: if you are using GroovyConsole script you can set a property data on the parent node of the scripts. The content is interpreted as Json and added to the script as a binding:

package definition

vtl:definition
  - upgrader
      - your_script_folder
          - properties:
              - handler=groovyconsole
              - data={"myBinding":"custom-value"}
          - script0.groovy

script0.groovy

println data.myBinding

Still we should find a way for the other handlers and document the above properly.

~~very good point, in GroovyConsole scripts there is already a workaround for that: With slingRequest['scriptPath'] you can access the path of the current script and with that information you can read properties of that node or the parent node via normal means~~

~~But you are totally right, a more elegant solution for that would be awesome.~~

andreas-haller avatar May 29 '20 05:05 andreas-haller