Skip to content

Commit

Permalink
refactor: move cli to dynamic properties (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgabelle authored Jan 2, 2025
1 parent 1891c1c commit 603cecc
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/java/io/kestra/plugin/gcp/cli/GCloudCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.kestra.core.models.annotations.Example;
import io.kestra.core.models.annotations.Plugin;
import io.kestra.core.models.annotations.PluginProperty;
import io.kestra.core.models.property.Property;
import io.kestra.core.models.tasks.runners.ScriptService;
import io.kestra.core.models.tasks.*;
import io.kestra.core.models.tasks.runners.TaskRunner;
Expand All @@ -22,6 +23,7 @@
import jakarta.validation.constraints.NotNull;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -42,7 +44,7 @@
code = """
id: gcp_g_cloud_cli
namespace: company.team
tasks:
- id: g_cloud_cli
type: io.kestra.plugin.gcp.cli.GCloudCLI
Expand All @@ -59,7 +61,7 @@
code = """
id: gcp_g_cloud_cli
namespace: company.team
tasks:
- id: g_cloud_cli
type: io.kestra.plugin.gcp.cli.GCloudCLI
Expand All @@ -75,7 +77,7 @@
code = """
id: gcp_g_cloud_cli
namespace: company.team
tasks:
- id: g_cloud_cli
type: io.kestra.plugin.gcp.cli.GCloudCLI
Expand All @@ -84,7 +86,7 @@
commands:
# Outputs as a flow output for UI display
- gcloud pubsub topics list --format=json | tr -d '\n ' | xargs -0 -I {} echo '::{"outputs":{"gcloud":{}}}::'
# Outputs as a file, preferred way for large payloads
- gcloud storage ls --json > storage.json
"""
Expand Down Expand Up @@ -148,11 +150,13 @@ public class GCloudCLI extends Task implements RunnableTask<ScriptOutput>, Names

private Object inputFiles;

private List<String> outputFiles;
private Property<List<String>> outputFiles;

@Override
public ScriptOutput run(RunContext runContext) throws Exception {

var renderedOutputFiles = runContext.render(this.outputFiles).asList(String.class);

CommandsWrapper commands = new CommandsWrapper(runContext)
.withWarningOnStdErr(true)
.withDockerOptions(injectDefaults(getDocker()))
Expand All @@ -167,7 +171,7 @@ public ScriptOutput run(RunContext runContext) throws Exception {
.withEnv(this.getEnv(runContext))
.withNamespaceFiles(namespaceFiles)
.withInputFiles(inputFiles)
.withOutputFiles(outputFiles);
.withOutputFiles(renderedOutputFiles.isEmpty() ? null : renderedOutputFiles);

return commands.run();
}
Expand Down

0 comments on commit 603cecc

Please sign in to comment.