argoproj-labs / argocd-vault-plugin

An Argo CD plugin to retrieve secrets from Secret Management tools and inject them into Kubernetes secrets
https://argocd-vault-plugin.readthedocs.io
Apache License 2.0
812 stars 190 forks source link

Indent modifiers should not trim orignal spaces #633

Open abc225666 opened 5 months ago

abc225666 commented 5 months ago

Is your feature request related to a problem? Please describe. I am trying to use a multiline string from the Vault and embed it into a subsequence. The multiline string may have its indent stored in the Vault. Here is one example:

{
  "json_field1": "value",
  "json_field2": "value"
}

And the secret resource would be like:

apiVersion: v1
stringData:
  key: |
    some_key: "some_value"
    embed_key: |
      <path:secret/data/mysecret#credential>
...

The result generated is:

apiVersion: v1
stringData:
  key: |
    some_key: "some_value"
    embed_key: |
      {
      "json_field1": "value",
      "json_field2": "value"
    }
...

I have read issues #297 and #451. I trying to add indent 4 after the substitution like <path:secret/data/mysecret#credential | indent 4>. But the result becomes:

apiVersion: v1
stringData:
  key: |
    some_key: "some_value"
    embed_key: |
      {
        "json_field1": "value",
        "json_field2": "value"
        }
...

The indent of the last line is broken. Then I checked the source code of handling indent. It trimmed spaces before adding the selected level of spaces into the lines.

Describe the solution you'd like I think the indent function should keep the original spaces and add the selected number of spaces into the strings.