Skip to content

Commit 2ad1cfd

Browse files
e-nikolovhiddeco
authored andcommitted
introduce a --pristine flag to sops exec-env
Signed-off-by: Emil Nikolov <emil.e.nikolov@gmail.com>
1 parent 1882df3 commit 2ad1cfd

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
@@ -137,6 +137,10 @@ func main() {
137137
Name: "background",
138138
Usage: "background the process and don't wait for it to complete",
139139
},
140+
cli.BoolFlag{
141+
Name: "pristine",
142+
Usage: "insert only the decrypted values into the environment without forwarding existing environment variables",
143+
},
140144
cli.StringFlag{
141145
Name: "user",
142146
Usage: "the user to run the command as",
@@ -171,6 +175,7 @@ func main() {
171175
Command: command,
172176
Plaintext: output,
173177
Background: c.Bool("background"),
178+
Pristine: c.Bool("pristine"),
174179
User: c.String("user"),
175180
}); err != nil {
176181
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)