Skip to content

Commit

Permalink
feat(core): add NamespaceFiles props on WorkingDirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Nov 8, 2023
1 parent cf63fe9 commit 9f5c949
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,7 +25,7 @@
@EqualsAndHashCode
@Getter
@NoArgsConstructor
public abstract class AbstractExecScript extends Task implements RunnableTask<ScriptOutput> {
public abstract class AbstractExecScript extends Task implements RunnableTask<ScriptOutput>, NamespaceFilesInterface {
@Builder.Default
@Schema(
title = "Runner to use"
Expand Down Expand Up @@ -65,6 +67,8 @@ public abstract class AbstractExecScript extends Task implements RunnableTask<Sc
@NotEmpty
protected List<String> interpreter = List.of("/bin/sh", "-c");

private NamespaceFiles namespaceFiles;

abstract public DockerOptions getDocker();

/**
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -49,6 +51,9 @@ public class CommandsWrapper {
@With
private Boolean warningOnStdErr;

@With
private NamespaceFiles namespaceFiles;

public CommandsWrapper(RunContext runContext) {
this.runContext = runContext;

Expand Down Expand Up @@ -76,7 +81,8 @@ public CommandsWrapper withCommands(List<String> commands) throws IOException, I
logConsumer,
runnerType,
dockerOptions,
warningOnStdErr
warningOnStdErr,
namespaceFiles
);
}

Expand All @@ -99,7 +105,8 @@ public CommandsWrapper withEnv(Map<String, String> envs) throws IllegalVariableE
logConsumer,
runnerType,
dockerOptions,
warningOnStdErr
warningOnStdErr,
namespaceFiles
);
}

Expand All @@ -115,9 +122,24 @@ public CommandsWrapper addEnv(Map<String, String> envs) {
return this;
}

@SuppressWarnings("unchecked")
public ScriptOutput run() throws Exception {
RunnerResult runnerResult;

if (this.namespaceFiles != null) {
String tenantId = ((Map<String, String>) runContext.getVariables().get("flow")).get("tenantId");
String namespace = ((Map<String, String>) 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 {
Expand Down

0 comments on commit 9f5c949

Please sign in to comment.