Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix newline encoding for dotenv store #612

Merged
merged 1 commit into from
Jan 24, 2020
Merged

Conversation

scjudd
Copy link
Contributor

@scjudd scjudd commented Jan 23, 2020

When reading and writing dotenv files, we need to make sure to encode/decode newline characters. SOPS does not currently do this, as can be seen below:

$ echo '{"foo": "foo\nbar\nbaz"}' > plaintext.json
$ sops -e --output ciphertext.json plaintext.json
$ sops -d --output-type dotenv ciphertext.json
foo=foo
bar
baz

This output is invalid and cannot even be fed back into SOPS:

$ sops -d --output-type dotenv --output plaintext.env ciphertext.json
$ sops -e plaintext.env
Error unmarshalling file: invalid dotenv input line: bar

This commit fixes the issue, such that the final sops -d ... command above produces the correct output:

$ sops -d --output-type dotenv ciphertext.json
foo=foo\nbar\nbaz

When reading and writing dotenv files, we need to make sure to
encode/decode newline characters. SOPS does not currently do this, as
can be seen from the below:

```console
$ echo '{"foo": "foo\nbar\nbaz"}' > plaintext.json
$ sops -e --output ciphertext.json plaintext.json
$ sops -d --output-type dotenv ciphertext.json
foo=foo
bar
baz
```

This output, is invalid and cannot even be fed back into SOPS:

```console
$ sops -d --output-type dotenv --output plaintext.env ciphertext.json
$ sops -e plaintext.env
Error unmarshalling file: invalid dotenv input line: bar
```

This commit fixes the issue, such that the final `sops -d ...` command
above produces the correct output:

```console
$ sops -d --output-type dotenv ciphertext.json
foo=foo\nbar\nbaz
```
@codecov-io
Copy link

Codecov Report

Merging #612 into develop will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #612      +/-   ##
===========================================
+ Coverage    37.13%   37.15%   +0.02%     
===========================================
  Files           21       21              
  Lines         2892     2893       +1     
===========================================
+ Hits          1074     1075       +1     
  Misses        1724     1724              
  Partials        94       94
Impacted Files Coverage Δ
stores/stores.go 0% <ø> (ø) ⬆️
stores/dotenv/store.go 32.45% <100%> (+0.59%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db9c552...e4cff4e. Read the comment docs.

@ajvb ajvb requested a review from autrilla January 23, 2020 23:00
Copy link
Contributor

@autrilla autrilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@autrilla autrilla merged commit 1634350 into getsops:develop Jan 24, 2020
rochaporto pushed a commit to rochaporto/sops that referenced this pull request Jun 22, 2020
When reading and writing dotenv files, we need to make sure to
encode/decode newline characters. SOPS does not currently do this, as
can be seen from the below:

```console
$ echo '{"foo": "foo\nbar\nbaz"}' > plaintext.json
$ sops -e --output ciphertext.json plaintext.json
$ sops -d --output-type dotenv ciphertext.json
foo=foo
bar
baz
```

This output, is invalid and cannot even be fed back into SOPS:

```console
$ sops -d --output-type dotenv --output plaintext.env ciphertext.json
$ sops -e plaintext.env
Error unmarshalling file: invalid dotenv input line: bar
```

This commit fixes the issue, such that the final `sops -d ...` command
above produces the correct output:

```console
$ sops -d --output-type dotenv ciphertext.json
foo=foo\nbar\nbaz
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants