envyaml icon indicating copy to clipboard operation
envyaml copied to clipboard

Handling multi-line env

Open vbr-cts opened this issue 4 years ago • 1 comments

Hi. I'm trying to find a way to handle multi-line env variables. Basically, I have a pkcs certificate that I need to get from env through EnvYaml.

Simple test case:

user$ export VAR=$(printf "foo\nbar")
user$ echo "$VAR"
foo
bar
user$ cat a.yaml
foo: "$VAR"

Then in python:

os.environ['VAR']
'foo\nbar'
>>> envyaml.EnvYAML('a.yaml')['foo']
'foo bar'

As you can see, the line break gets stripped. This is because by default, line breaks are stripped from quoted strings in yaml. Using a multi-line block with > or | doesn't work because we break indentation.

One way that works is to force replace all line breaks in the value with \n (or two line breaks).

This way, my yaml ends up looking like this, and parsing works:

foo: "a\nb"

I guess an even cleaner way would be to completely escape strings before doing the substitution ?

vbr-cts avatar Nov 02 '21 20:11 vbr-cts

Its late now, but a workaround could be base64 -w0 your certificate and store it in env and decode in py

awcator avatar Nov 07 '24 06:11 awcator