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

introduce a --pristine flag to sops exec-env #912

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/sops/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ func main() {
Name: "background",
Usage: "background the process and don't wait for it to complete",
},
cli.BoolFlag{
Name: "pristine",
Usage: "insert only the decrypted values into the environment without forwarding existing environment variables",
},
cli.StringFlag{
Name: "user",
Usage: "the user to run the command as",
Expand Down Expand Up @@ -171,6 +175,7 @@ func main() {
Command: command,
Plaintext: output,
Background: c.Bool("background"),
Pristine: c.Bool("pristine"),
User: c.String("user"),
}); err != nil {
return toExitError(err)
Expand Down
8 changes: 7 additions & 1 deletion cmd/sops/subcommand/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type ExecOpts struct {
Command string
Plaintext []byte
Background bool
Pristine bool
Fifo bool
User string
Filename string
Expand Down Expand Up @@ -83,7 +84,12 @@ func ExecWithEnv(opts ExecOpts) error {
SwitchUser(opts.User)
}

env := os.Environ()
var env []string

if !opts.Pristine {
env = os.Environ()
}

lines := bytes.Split(opts.Plaintext, []byte("\n"))
for _, line := range lines {
if len(line) == 0 {
Expand Down
Loading