replicatedhq/troubleshoot

Create a JSON redactor

banjoh opened this issue · 1 comments

Describe the rationale for the suggested feature.

Troubleshoot has a YAML redactor that is used to redact values in a YAML file selected using this yamlPath selector syntax. Since we collect JSON files in support bundles, having a similar redactor that behaves the same as the YAML redactor would be beneficial

Describe the feature

Given the below input

{
  "abc": {
    "a": {
      "alpha": "bravo",
      "charlie": "delta"
    },
    "c": {
      "charlie": "delta",
      "echo": "foxtrot"
    }
  },
  "xyz": [
    {
      "xray": "yankee",
      "zulu": "alpha"
    },
    {
      "zulu": "alpha",
      "bravo": "charlie"
    }
  ]
}

A redactor of abc.*.charlie would remove the values for abc.a.charlie and abc.c.charlie, yielding

{
  "abc": {
    "a": {
      "alpha": "bravo",
      "charlie": "***HIDDEN***"
    },
    "c": {
      "charlie": "***HIDDEN***",
      "echo": "foxtrot"
    }
  },
  "xyz": [
    {
      "xray": "yankee",
      "zulu": "alpha"
    },
    {
      "zulu": "alpha",
      "bravo": "charlie"
    }
  ]
}

Describe alternatives you've considered

Using the current set of redactors such as the regex redactor to craft complex redactors for extracting values

Additional context

This redactor will behave the same as the YAML redactor. The implementation will be quite similar, the deference being conversions from JSON to Go objects and back. Some of the code such a redactYaml which is used to search for elements in the extracted Go structure should be reused.

Once this feature is implemented, we need to add a default redactor to redact kURL installer specs of JSON type

Refer to #1455 bug for context