vmware-archive / kubecfg

A tool for managing complex enterprise Kubernetes environments as code.
Apache License 2.0
728 stars 62 forks source link

ext-code/tla-code improperly parsed #280

Closed camh- closed 4 years ago

camh- commented 4 years ago

The command line flags --ext-code and --tla-code do not handle values with commas or double quotes in them and produce an error when you try:

$ kubecfg show --ext-code 'foo={a: 1, b: 2}'
ERROR Missing environment variable:  b: 2}

$ kubecfg show --ext-code 'foo="bar"`
ERROR invalid argument "foo=\"bar\"" for "--ext-code" flag: parse error on line 1, column 4: bare " in non-quoted-field

This happens because the flag is parsed with Cobra's StringSlice() flag type which supports multiple comma separated values. This explains why the comma doesn't work. The double quotes do not work because StringSlice() parses values with encoding/csv - i.e. as a CSV value. This escapes double quotes.

It does not look like there is any way to escape the value such that it can be parsed as intended.

I think the correct fix is to parse these flags with StringArray() instead which does not try to split the value on commas (and no CSV parsing to muck up double quotes). I think this change should be made for all 8 variants of ext/tla options so that commas and double-quotes can be used in string values and filenames. This is also consistent with the jsonnet cli, which does not support comma-separated flag values.