Class YAMLHelper

java.lang.Object
com.redhat.devtools.intellij.common.utils.YAMLHelper

public class YAMLHelper extends Object
  • Constructor Details

    • YAMLHelper

      public YAMLHelper()
  • Method Details

    • getStringValueFromYAML

      public static String getStringValueFromYAML(String yamlAsString, String[] path) throws IOException
      Retrieve value as String from YAML text
      Parameters:
      yamlAsString - Full YAML where to search the value from
      path - 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 from
      path - 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

      public static String JSONToYAML(com.fasterxml.jackson.databind.JsonNode json) throws IOException
      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

      public static com.fasterxml.jackson.databind.JsonNode URLToJSON(URL file) throws IOException
      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 edit
      fieldnames - 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 configuration
      labelKey - label key to add
      labelValue - 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 configuration
      labelKey - label key to remove
      Returns:
      the updated resource with the label removed
      Throws:
      IOException - if errored during yaml parsing