Skip to content

Commit 4b64d13

Browse files
committed
introduce a --pristine flag to sops exec-env
1 parent a750d72 commit 4b64d13

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

cmd/sops/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ func main() {
129129
Name: "background",
130130
Usage: "background the process and don't wait for it to complete",
131131
},
132+
cli.BoolFlag{
133+
Name: "pristine",
134+
Usage: "insert only the decrypted values into the environment without forwarding existing environment variables",
135+
},
132136
cli.StringFlag{
133137
Name: "user",
134138
Usage: "the user to run the command as",
@@ -163,6 +167,7 @@ func main() {
163167
Command: command,
164168
Plaintext: output,
165169
Background: c.Bool("background"),
170+
Pristine: c.Bool("pristine"),
166171
User: c.String("user"),
167172
}); err != nil {
168173
return toExitError(err)

cmd/sops/subcommand/exec/exec.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type ExecOpts struct {
2121
Command string
2222
Plaintext []byte
2323
Background bool
24+
Pristine bool
2425
Fifo bool
2526
User string
2627
Filename string
@@ -83,7 +84,12 @@ func ExecWithEnv(opts ExecOpts) error {
8384
SwitchUser(opts.User)
8485
}
8586

86-
env := os.Environ()
87+
var env []string
88+
89+
if !opts.Pristine {
90+
env = os.Environ()
91+
}
92+
8793
lines := bytes.Split(opts.Plaintext, []byte("\n"))
8894
for _, line := range lines {
8995
if len(line) == 0 {

0 commit comments

Comments
 (0)