Since sops writes its output to stdout it should also be possible to read from stdin rather than a file too.
This would allow applications which do hot reloading of config in a language which is not go / python to exec. sops with out the need to write and then delete a temporary file.
Sugested API:
command that generates json | sops -d --from-stdin
You can just use stdin as the input file:
โฏ echo '{"hello": "world"}' | sops -e /dev/stdin
{
"hello": "ENC[AES256_GCM,data:f9HqiA4=,iv:2Zlwb5rAlbML777KDhQOi7wY1j/IJbMQG8IXZBVFbSw=,tag:38fqiraPmNrYhk82QZPdWA==,type:str]",
"sops": {
"kms": null,
"gcp_kms": null,
"lastmodified": "2018-04-16T17:26:04Z",
"mac": "ENC[AES256_GCM,data:ZkLpyPeN1RmBch88K8N2U2E/j1YqcqbxmOY6owyAal2Dqb4y0cnlLEnBPX3OoeTjMfBhn/x/QrdFTnSKfQmWScNOQvp2Q6JBySvT2FYRbHSZIxwnWFphnf2kT0JjtPrs8MeMdnn/AzCeNk6L2NkFZs731U4qTGIhrv3Y6m05Q9A=,iv:Y41f0BzP40DC7ad0KZPwXTtHypqpJ964F7Go1w6TJ8g=,tag:0RzXOrXMTwMREnTP3UK7hw==,type:str]",
"pgp": [
{
"created_at": "2018-04-16T17:26:02Z",
"enc": "-----BEGIN PGP MESSAGE-----\n\nwYwDEEVDpnzXnMABBABz64++hpdXJxE9R5sUoLWaBSDfvX1HJc0dNzpe3kGpkwCm\nL3JwhBWWePR9jYim1Y/FhdIPz5j3WL9D6QBo3d/hXVtl1FT1vC9BelHnlUP/JhC+\ng+mO+z9Z23kVfZjls+Jw9zucCUxPLjQrjeLdHu1hyrwlNi7kncbrkbIXXeWOY9Lg\nAeT8zed22tkXKx7LU4ZLLhXF4cdM4Drg9OETC+Cq4kY+LwXgQOWojv9AAh16Po0Z\nBPYF+yB03PAFGmSwZK2oVIYQXHF5DuDJ5A5OVFHkmdMqht/bfphrjbHiyok+DuHy\nNwA=\n=93Ug\n-----END PGP MESSAGE-----",
"fp": "1022470DE3F0BC54BC6AB62DE05550BC07FB1A0A"
}
],
"unencrypted_suffix": "_unencrypted",
"version": "3.0.0"
}
}
Please add this to the readme's examples. It's useful!
Sorry @autrilla I did actually try exactly that before raising the issue, I should have been more specific - sorry.
Specifically:
echo '{"hello" : "world"}' | sops -e /dev/stdin > test.json
cat test.json
This works and I can see:
{
"hello": "ENC[AES256_GCM,data:KIYR/dM=,iv:GcuHkiLDtFVZygWN078uYRm1GqXhgsJ7dknqcfDFUl8=,tag:QoCmIGlcGkSk4BSgjWlYaA==,type:str]",
"sops": {
"kms": [
{
"arn": "SNIP",
"created_at": "2018-04-16T17:57:55Z",
"enc": "SNIP"
}
],
"gcp_kms": null,
"lastmodified": "2018-04-16T17:57:55Z",
"mac": "SNIP",
"pgp": null,
"unencrypted_suffix": "_unencrypted",
"version": "3.0.3"
}
}
However when I try:
cat test.json | sops -d /dev/stdin
I am shown an error:
Error dumping file: No binary data found in tree
I suspect, this is a bug but I'm willing to be shown otherwise...
SOPS uses the file's extension to deduce the format it should use (YAML, JSON or binary). Since in this case the file doesn't have an extension, you need to use the --input-type and --output-type flags to tell SOPS what format to expect (and output), like so:
โฏ cat test.json | sops --input-type json --output-type json -d /dev/stdin
{
"hello": "world"
}
On the other hand, I'm not sure why it works without those flags for encrypting. That is probably a bug.
Thanks @autrilla, appologies for not figuring that myself!
Closing in favor of #337
Most helpful comment
Please add this to the readme's examples. It's useful!