Skip to content

Commit

Permalink
feat(core): add some variable renderer helper
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Sep 20, 2023
1 parent a82ea26 commit f7bcecb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
21 changes: 21 additions & 0 deletions core/src/main/java/io/kestra/core/runners/RunContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static io.kestra.core.utils.Rethrow.throwFunction;

@NoArgsConstructor
public class RunContext {
// Injected
Expand Down Expand Up @@ -429,6 +431,14 @@ public List<String> render(List<String> inline, Map<String, Object> variables) t
return variableRenderer.render(inline, mergeVariables(variables));
}

public Set<String> render(Set<String> inline) throws IllegalVariableEvaluationException {
return variableRenderer.render(inline, this.variables);
}

public Set<String> render(Set<String> inline, Map<String, Object> variables) throws IllegalVariableEvaluationException {
return variableRenderer.render(inline, mergeVariables(variables));
}

public Map<String, Object> render(Map<String, Object> inline) throws IllegalVariableEvaluationException {
return variableRenderer.render(inline, this.variables);
}
Expand All @@ -437,6 +447,17 @@ public Map<String, Object> render(Map<String, Object> inline, Map<String, Object
return variableRenderer.render(inline, mergeVariables(variables));
}

public Map<String, String> renderMap(Map<String, String> inline) throws IllegalVariableEvaluationException {
return inline
.entrySet()
.stream()
.map(throwFunction(entry -> new AbstractMap.SimpleEntry<>(
this.render(entry.getKey(), mergeVariables(variables)),
this.render(entry.getValue(), mergeVariables(variables))
)))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

private Map<String, Object> mergeVariables(Map<String, Object> variables) {
return Stream
.concat(this.variables.entrySet().stream(), variables.entrySet().stream())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ public List<String> render(List<String> list, Map<String, Object> variables) thr
return result;
}

public Set<String> render(Set<String> list, Map<String, Object> variables) throws IllegalVariableEvaluationException {
Set<String> result = new HashSet<>();
for (String inline : list) {
result.add(this.recursiveRender(inline, variables));
}

return result;
}

@Getter
@ConfigurationProperties("kestra.variables")
public static class VariableConfiguration {
Expand Down

0 comments on commit f7bcecb

Please sign in to comment.