{"action":"created","issue":{"url":"https://api.github.com/repos/TomPoulton/hiera-eyaml/issues/176","labels_url":"https://api.github.com/repos/TomPoulton/hiera-eyaml/issues/176/labels{/name}","comments_url":"https://api.github.com/repos/TomPoulton/hiera-eyaml/issues/176/comments","events_url":"https://api.github.com/repos/TomPoulton/hiera-eyaml/issues/176/events","html_url":"https://github.com/TomPoulton/hiera-eyaml/issues/176","id":110701344,"number":176,"title":"`eyaml decrypt` for hiera values with newlines is not well-formed YAML","user":{"login":"r4v5","id":789416,"avatar_url":"https://avatars.githubusercontent.com/u/789416?v=3","gravatar_id":"","url":"https://api.github.com/users/r4v5","html_url":"https://github.com/r4v5","followers_url":"https://api.github.com/users/r4v5/followers","following_url":"https://api.github.com/users/r4v5/following{/other_user}","gists_url":"https://api.github.com/users/r4v5/gists{/gist_id}","starred_url":"https://api.github.com/users/r4v5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/r4v5/subscriptions","organizations_url":"https://api.github.com/users/r4v5/orgs","repos_url":"https://api.github.com/users/r4v5/repos","events_url":"https://api.github.com/users/r4v5/events{/privacy}","received_events_url":"https://api.github.com/users/r4v5/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-10-09T17:17:14Z","updated_at":"2015-11-11T16:07:51Z","closed_at":null,"body":"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:\r\n\r\n```\r\n% echo \"line1\r\nline2\r\nline3\" | eyaml encrypt --stdin -o block -l key\r\nkey: >\r\n    ENC[PKCS7,MIIBiQYJKoZIhvcNAQcDoIIBejCCAXYCAQAxggEhMIIBHQIBADAFMAACAQEw\r\n    DQYJKoZIhvcNAQEBBQAEggEAK880nZE8zYawt/V/Xby1xVRs1oGPGPyIYJtx\r\n    JWwxJXSbgXAVVgdOs9GziVm9h5qs3UJh4nyvpSsmkWA7NwyaVqghNfFW9Nrp\r\n    LNBbul/AYpXtRCCzDiM3o6yhVwKiD6O617sxkXbrLEMmMbtNQIjGljhF99UC\r\n    sjS2NAls8bj4S9qWwQreHzbuq1b/hZdNSKEQT/RPgd+UDa5fSsGLjttm+/DN\r\n    r/5yzTQd2lxnjZPXx0M/qpJ+QQ4ysiCZtu1IZOIGmdrtCbaE0+IcKDjyKQOH\r\n    CywUP2IJJvK2CtQoBwTXAIv27tFMfF9tNplqw8U9lAXFNVvlpzEmSVBzW5lz\r\n    JDXfFzBMBgkqhkiG9w0BBwEwHQYJYIZIAWUDBAEqBBA+oruEuGnbeoBV7vVM\r\n    NgeLgCClNIZMfkn4FRm6EiY2R3j7kBq/EA3ECMmXlnPpi/xq0w==]\r\n% echo \"line1\r\nline2\r\nline3\" | eyaml encrypt --stdin -o block -l key > test.eyaml\r\n% eyaml decrypt -f test.eyaml\r\nkey: line1\r\nline2\r\nline3\r\n\r\n% eyaml decrypt -f test.eyaml > test.yaml\r\n% irb\r\n2.1.2 :001 > require 'yaml'\r\n => true\r\n2.1.2 :002 > YAML.load_file('test.yaml')\r\nPsych::SyntaxError: (test.yaml): could not find expected ':' while scanning a simple key at line 2 column 1\r\n        from /Users/mdonahue/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/psych.rb:370:in `parse'\r\n        from /Users/mdonahue/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/psych.rb:370:in `parse_stream'\r\n        from /Users/mdonahue/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/psych.rb:318:in `parse'\r\n        from /Users/mdonahue/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/psych.rb:245:in `load'\r\n        from /Users/mdonahue/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/psych.rb:464:in `block in load_file'\r\n        from /Users/mdonahue/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/psych.rb:464:in `open'\r\n        from /Users/mdonahue/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/psych.rb:464:in `load_file'\r\n        from (irb):2\r\n        from /Users/mdonahue/.rvm/rubies/ruby-2.1.2/bin/irb:11:in `<main>'\r\n```\r\n\r\nI'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: \r\n```\r\nkey: |\r\n  line1\r\n  line2\r\n  line3\r\n```"},"comment":{"url":"https://api.github.com/repos/TomPoulton/hiera-eyaml/issues/comments/155829002","html_url":"https://github.com/TomPoulton/hiera-eyaml/issues/176#issuecomment-155829002","issue_url":"https://api.github.com/repos/TomPoulton/hiera-eyaml/issues/176","id":155829002,"user":{"login":"TomPoulton","id":1509138,"avatar_url":"https://avatars.githubusercontent.com/u/1509138?v=3","gravatar_id":"","url":"https://api.github.com/users/TomPoulton","html_url":"https://github.com/TomPoulton","followers_url":"https://api.github.com/users/TomPoulton/followers","following_url":"https://api.github.com/users/TomPoulton/following{/other_user}","gists_url":"https://api.github.com/users/TomPoulton/gists{/gist_id}","starred_url":"https://api.github.com/users/TomPoulton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TomPoulton/subscriptions","organizations_url":"https://api.github.com/users/TomPoulton/orgs","repos_url":"https://api.github.com/users/TomPoulton/repos","events_url":"https://api.github.com/users/TomPoulton/events{/privacy}","received_events_url":"https://api.github.com/users/TomPoulton/received_events","type":"User","site_admin":false},"created_at":"2015-11-11T16:07:51Z","updated_at":"2015-11-11T16:07:51Z","body":"You could use a small ruby script to \"clean\" the string before parsing it to eyaml\r\n\r\n```ruby\r\n# clean.rb\r\nstring = ARGF.read\r\nstring = string.strip().gsub(/\\n/, '\\n')\r\nputs \"\\\"#{string}\\\"\"\r\n```\r\n\r\n```bash\r\n$ echo \"line1\r\nline2\r\nline3\" | ruby clean.rb | eyaml encrypt --stdin -o block -l key > test.eyaml\r\n$ eyaml decrypt -f test.eyaml > test.yaml\r\n$ cat test.yaml\r\nkey: \"line1\\nline2\\nline3\"\r\n\r\n$ irb\r\nirb(main):001:0> require 'yaml'\r\n=> true\r\nirb(main):002:0> puts YAML.load_file('test.yaml')['key']\r\nline1\r\nline2\r\nline3\r\n```\r\n\r\nThis won't use the YAML multiline literal syntax (`|`) but it will preserve the newlines in the value\r\n\r\nThe string input version is simpler, you just wrap the string in double and single quotes to preserve the newlines:\r\n\r\n```bash\r\n$ eyaml encrypt -s '\"line1\\nline2\\nline3\"' -o block -l key > test.eyaml\r\n$ eyaml decrypt -f test.eyaml > test.yaml\r\n$ cat test.yaml\r\nkey: \"line1\\nline2\\nline3\"\r\n```\r\n"}}