-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add option to elevate to global context
- Loading branch information
Karl DeBisschop
committed
Dec 24, 2019
1 parent
866dcd3
commit 489d89a
Showing
6 changed files
with
119 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ | |
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.dtolabs.rundeck.core.execution.workflow.SharedOutputContext; | ||
import com.dtolabs.rundeck.core.execution.workflow.steps.StepException; | ||
import com.dtolabs.rundeck.core.plugins.Plugin; | ||
import com.dtolabs.rundeck.plugins.ServiceNameConstants; | ||
|
@@ -34,14 +33,15 @@ | |
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
/** | ||
* Workflow Step Plug-in to find value of first matching field name in JSON file. | ||
* Workflow Step Plug-in to find value of first matching field name in JSON | ||
* file. | ||
* | ||
* Scans the specified file for the indicated field name and returns the value | ||
* of the first matching value node. Search through non-value nodes is performed | ||
* in a depth-first manner, so the match found is the first value match seen when | ||
* when scanning down the file and earlier matches will mask matches that are | ||
* less deep in the tree but later in the file. Breadth-first search could be | ||
* implemented as an option but is not done here. | ||
* in a depth-first manner, so the match found is the first value match seen | ||
* when when scanning down the file and earlier matches will mask matches that | ||
* are less deep in the tree but later in the file. Breadth-first search could | ||
* be implemented as an option but is not done here. | ||
* | ||
* @author Karl DeBisschop <[email protected]> | ||
* @since 2019-12-11 | ||
|
@@ -63,21 +63,25 @@ public class JsonFindValueStepPlugin implements StepPlugin { | |
@PluginProperty(title = "Field Name", description = "Field name to lookup in JSON", required = true) | ||
private String fieldName; | ||
|
||
@PluginProperty(title = "Make global?", description = "Elevate this variable to global scope (default: false)", required = false) | ||
private boolean elevateToGlobal; | ||
|
||
@Override | ||
public void executeStep(PluginStepContext context, Map<String, Object> configuration) throws StepException { | ||
String path = configuration.getOrDefault("path", this.path).toString(); | ||
String group = configuration.getOrDefault("group", this.group).toString(); | ||
String name = configuration.getOrDefault("name", this.name).toString(); | ||
String fieldName = configuration.getOrDefault("fieldName", this.fieldName).toString(); | ||
boolean elevateToGlobal = configuration.getOrDefault("elevateToGlobal", this.elevateToGlobal).toString() | ||
.equals("true"); | ||
|
||
try { | ||
FileReader reader = new FileReader(path); | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
JsonNode rootNode = objectMapper.readTree(reader); | ||
String value = this.searchTree(rootNode, fieldName); | ||
if (value != null) { | ||
SharedOutputContext sharedOutputContext = context.getOutputContext(); | ||
sharedOutputContext.addOutput(group, name, value); | ||
FileLookupUtils.addOutput(context, group, name, value, elevateToGlobal); | ||
} | ||
} catch (FileNotFoundException e) { | ||
String msg = "Could not find file " + path; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.