Open r4v5 opened 9 years ago
I have the same issue. Are there any workaround?
You could use a small ruby script to "clean" the string before parsing it to eyaml
# clean.rb
string = ARGF.read
string = string.strip().gsub(/\n/, '\n')
puts "\"#{string}\""
$ echo "line1
line2
line3" | ruby clean.rb | eyaml encrypt --stdin -o block -l key > test.eyaml
$ eyaml decrypt -f test.eyaml > test.yaml
$ cat test.yaml
key: "line1\nline2\nline3"
$ irb
irb(main):001:0> require 'yaml'
=> true
irb(main):002:0> puts YAML.load_file('test.yaml')['key']
line1
line2
line3
This won't use the YAML multiline literal syntax (|
) but it will preserve the newlines in the value
The string input version is simpler, you just wrap the string in double and single quotes to preserve the newlines:
$ eyaml encrypt -s '"line1\nline2\nline3"' -o block -l key > test.eyaml
$ eyaml decrypt -f test.eyaml > test.yaml
$ cat test.yaml
key: "line1\nline2\nline3"
I have a branch over at https://github.com/peculater/hiera-eyaml/tree/multiline-values that seems to work for this. I'm not quite confident in it enough to make a PR, but will likely be shortly. We started using it in prod today. ;-)
I'm trying to write something that verifies eyaml-encrypted secrets (think SSH or SSL keys and making sure that the public key and private key match within a precommit hook). However, hiera-eyaml 2.0.7 doesn't seem to handle newlines properly in an
eyaml decrypt
. For instance:I'd expect the output to be parseable by psych. It looks like, if the encrypted value contains a newline, we'd want the output to be similar to: