Class YAMLHelper
java.lang.Object
com.redhat.devtools.intellij.common.utils.YAMLHelper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic com.fasterxml.jackson.databind.JsonNodeaddLabelToResource(String yaml, String labelKey, String labelValue) Add a label to resource metadatastatic com.fasterxml.jackson.databind.JsonNodeeditValueInYAML(String yamlAsString, String[] fieldnames, String value) Edit value of a yaml field and return the update yaml as JsonNodestatic StringgetStringValueFromYAML(String yamlAsString, String[] path) Retrieve value as String from YAML textstatic com.fasterxml.jackson.databind.JsonNodegetValueFromYAML(String yamlAsString, String[] path) Retrieve value as JsonNode from YAML textstatic StringJSONToYAML(com.fasterxml.jackson.databind.JsonNode json) static StringJSONToYAML(com.fasterxml.jackson.databind.JsonNode json, boolean minimizeQuotes) static com.fasterxml.jackson.databind.JsonNoderemoveLabelFromResource(String yaml, String labelKey) Remove a label from resource metadatastatic com.fasterxml.jackson.databind.JsonNodestatic com.fasterxml.jackson.databind.JsonNodeYAMLToJsonNode(String yaml)
-
Constructor Details
-
YAMLHelper
public YAMLHelper()
-
-
Method Details
-
getStringValueFromYAML
Retrieve value as String from YAML text- Parameters:
yamlAsString- Full YAML where to search the value frompath- Path to scan to search for the value (e.g to get the resource name `String[] { "metadata", "name" } `)- Returns:
- last field value or null if the YAML doesn't contain any field
- Throws:
IOException- if erroring during parsing
-
getValueFromYAML
public static com.fasterxml.jackson.databind.JsonNode getValueFromYAML(String yamlAsString, String[] path) throws IOException Retrieve value as JsonNode from YAML text- Parameters:
yamlAsString- Full YAML where to search the value frompath- Path to scan to search for the value (e.g to get the resource name `String[] { "metadata", "name" } `)- Returns:
- last field value or null if the YAML doesn't contain any field
- Throws:
IOException- if erroring during parsing
-
JSONToYAML
- Throws:
IOException
-
JSONToYAML
public static String JSONToYAML(com.fasterxml.jackson.databind.JsonNode json, boolean minimizeQuotes) throws IOException - Throws:
IOException
-
YAMLToJsonNode
public static com.fasterxml.jackson.databind.JsonNode YAMLToJsonNode(String yaml) throws IOException - Throws:
IOException
-
URLToJSON
- Throws:
IOException
-
editValueInYAML
public static com.fasterxml.jackson.databind.JsonNode editValueInYAML(String yamlAsString, String[] fieldnames, String value) throws IOException Edit value of a yaml field and return the update yaml as JsonNode- Parameters:
yamlAsString- original yaml to editfieldnames- array of string to define path of field to change (e.g "spec", "template", "containers[0]", "image")value- new value to add to the field- Returns:
- edited yaml as JsonNode or null if unable to update yaml
- Throws:
IOException- if errored during yaml parsing
-
addLabelToResource
public static com.fasterxml.jackson.databind.JsonNode addLabelToResource(String yaml, String labelKey, String labelValue) throws IOException Add a label to resource metadata- Parameters:
yaml- the YAML resource configurationlabelKey- label key to addlabelValue- label value to add- Returns:
- The updated resource with the new label in the metadata
- Throws:
IOException- if errored during yaml parsing
-
removeLabelFromResource
public static com.fasterxml.jackson.databind.JsonNode removeLabelFromResource(String yaml, String labelKey) throws IOException Remove a label from resource metadata- Parameters:
yaml- the YAML resource configurationlabelKey- label key to remove- Returns:
- the updated resource with the label removed
- Throws:
IOException- if errored during yaml parsing
-