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

Allow to override fileName with different value #1332

Merged
merged 3 commits into from
Dec 16, 2023

Conversation

felixfontein
Copy link
Contributor

This adds a --filename-override parameter which can be used when providing data to encrypt (or decrypt) from /dev/stdin.

For example: echo 'foo: bar' | ~/go/bin/sops --encrypt --filename-override foobar.yaml /dev/stdin will take the data to encrypt from the echo command's output, and act as if foobar.yaml has been supplied instead of /dev/stdin. This is relevant for finding creation rules in the SOPS configuration, and for determining the input and output type if these are not explicitly specified via --input-type and --output-type.

Fixes #594.

Copy link
Contributor

@devstein devstein left a comment

Choose a reason for hiding this comment

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

Nice work. One clarifying comment. Should we add an example for documentation? Something like "Encrypting data from stdout and writing to a new file"

cmd/sops/main.go Show resolved Hide resolved
@felixfontein
Copy link
Contributor Author

Nice work. One clarifying comment. Should we add an example for documentation? Something like "Encrypting data from stdout and writing to a new file"

Yeah, documentation is definitely needed. I'll work on that next.

README.rst Outdated
Encrypting and decrypting from other programs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When using ``sops`` in scripts or from other programs, there are often situations where you do not want to write encrypted or decrypted data to disk. The best way to avoid this is to pass data to SOPS via stdin, and to let SOPS write data to stdout. By default, the encrypt and decrypt operations write data to stdout already. To pass data via stdin, you need to pass ``/dev/stdin`` as the input filename. Please note that this only works on Unix-like operating systems such as macOS and Linux. On Windows, you have to use named pipes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure about Windows here. Is it true that you need named pipes for this? Or is there another mechanism?

Copy link
Member

Choose a reason for hiding this comment

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

With #1104, it would simply be a -. I would need to revise this to incorporate my own feedback, as it appears the contributor gave up.

Copy link
Member

Choose a reason for hiding this comment

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

I'll update this section once I have recreated the above.

$ sops --decrypt test.enc.yaml


Encrypting and decrypting from other programs
Copy link
Member

Choose a reason for hiding this comment

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

In think we need to line wrap the documentation, as that seems to be the case for the majority of the sections in the README and eases reading in e.g. a terminal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd actually argue that explicitly wrapping lines is bad, since terminals by default wrap lines and thus you use the full terminal width, as opposed to explicit line wrapping, which looks mostly bad except if it is applied consistently and your terminal is wider than the limit used in the file. But that's something we should look at at another point in time :)

I've wrapped lines to a similar length as other parts of this file for now.

Copy link
Member

@hiddeco hiddeco left a comment

Choose a reason for hiding this comment

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

Besides my comment around linewraping, this looks good to me. Thanks @felixfontein 🙇

@felixfontein felixfontein force-pushed the filename-override branch 2 times, most recently from 26c77c7 to 4aac57a Compare December 16, 2023 16:29
Signed-off-by: Felix Fontein <felix@fontein.de>
Signed-off-by: Felix Fontein <felix@fontein.de>
Signed-off-by: Felix Fontein <felix@fontein.de>
@felixfontein felixfontein merged commit 3028179 into getsops:main Dec 16, 2023
10 checks passed
@felixfontein felixfontein deleted the filename-override branch December 16, 2023 20:25
@felixfontein
Copy link
Contributor Author

@hiddeco thanks a lot for reviewing this!

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.

creation_rules from can't be matched when encrypting from stdin
3 participants