replicatedhq / troubleshoot

Preflight Checks and Support Bundles Framework for Kubernetes Applications
https://troubleshoot.sh
Apache License 2.0
545 stars 93 forks source link

Create a JSON redactor #1457

Open banjoh opened 9 months ago

banjoh commented 9 months ago

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.

banjoh commented 9 months ago

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

Refer to https://github.com/replicatedhq/troubleshoot/issues/1455 bug for context