diff --git a/plugin-script/src/main/java/io/kestra/plugin/scripts/exec/AbstractExecScript.java b/plugin-script/src/main/java/io/kestra/plugin/scripts/exec/AbstractExecScript.java index eaf1bf19..05e6f7dd 100644 --- a/plugin-script/src/main/java/io/kestra/plugin/scripts/exec/AbstractExecScript.java +++ b/plugin-script/src/main/java/io/kestra/plugin/scripts/exec/AbstractExecScript.java @@ -2,6 +2,8 @@ import io.kestra.core.exceptions.IllegalVariableEvaluationException; import io.kestra.core.models.annotations.PluginProperty; +import io.kestra.core.models.tasks.NamespaceFiles; +import io.kestra.core.models.tasks.NamespaceFilesInterface; import io.kestra.core.models.tasks.RunnableTask; import io.kestra.core.models.tasks.Task; import io.kestra.core.runners.RunContext; @@ -23,7 +25,7 @@ @EqualsAndHashCode @Getter @NoArgsConstructor -public abstract class AbstractExecScript extends Task implements RunnableTask { +public abstract class AbstractExecScript extends Task implements RunnableTask, NamespaceFilesInterface { @Builder.Default @Schema( title = "Runner to use" @@ -65,6 +67,8 @@ public abstract class AbstractExecScript extends Task implements RunnableTask interpreter = List.of("/bin/sh", "-c"); + private NamespaceFiles namespaceFiles; + abstract public DockerOptions getDocker(); /** @@ -90,6 +94,7 @@ protected CommandsWrapper commands(RunContext runContext) throws IllegalVariable .withEnv(this.getEnv()) .withWarningOnStdErr(this.getWarningOnStdErr()) .withRunnerType(this.getRunner()) - .withDockerOptions(this.injectDefaults(getDocker())); + .withDockerOptions(this.injectDefaults(getDocker())) + .withNamespaceFiles(namespaceFiles); } } diff --git a/plugin-script/src/main/java/io/kestra/plugin/scripts/exec/scripts/runners/CommandsWrapper.java b/plugin-script/src/main/java/io/kestra/plugin/scripts/exec/scripts/runners/CommandsWrapper.java index 04d08651..84f521ed 100644 --- a/plugin-script/src/main/java/io/kestra/plugin/scripts/exec/scripts/runners/CommandsWrapper.java +++ b/plugin-script/src/main/java/io/kestra/plugin/scripts/exec/scripts/runners/CommandsWrapper.java @@ -1,6 +1,8 @@ package io.kestra.plugin.scripts.exec.scripts.runners; import io.kestra.core.exceptions.IllegalVariableEvaluationException; +import io.kestra.core.models.tasks.NamespaceFiles; +import io.kestra.core.runners.NamespaceFilesService; import io.kestra.core.runners.RunContext; import io.kestra.core.utils.IdUtils; import io.kestra.plugin.scripts.exec.scripts.models.DockerOptions; @@ -49,6 +51,9 @@ public class CommandsWrapper { @With private Boolean warningOnStdErr; + @With + private NamespaceFiles namespaceFiles; + public CommandsWrapper(RunContext runContext) { this.runContext = runContext; @@ -76,7 +81,8 @@ public CommandsWrapper withCommands(List commands) throws IOException, I logConsumer, runnerType, dockerOptions, - warningOnStdErr + warningOnStdErr, + namespaceFiles ); } @@ -99,7 +105,8 @@ public CommandsWrapper withEnv(Map envs) throws IllegalVariableE logConsumer, runnerType, dockerOptions, - warningOnStdErr + warningOnStdErr, + namespaceFiles ); } @@ -115,9 +122,24 @@ public CommandsWrapper addEnv(Map envs) { return this; } + @SuppressWarnings("unchecked") public ScriptOutput run() throws Exception { RunnerResult runnerResult; + if (this.namespaceFiles != null) { + String tenantId = ((Map) runContext.getVariables().get("flow")).get("tenantId"); + String namespace = ((Map) runContext.getVariables().get("flow")).get("namespace"); + + NamespaceFilesService namespaceFilesService = runContext.getApplicationContext().getBean(NamespaceFilesService.class); + namespaceFilesService.inject( + runContext, + tenantId, + namespace, + this.workingDirectory, + this.namespaceFiles + ); + } + if (runnerType.equals(RunnerType.DOCKER)) { runnerResult = new DockerScriptRunner(runContext.getApplicationContext()).run(this, this.dockerOptions); } else {