From b86e6cefda49dc8c81ad070f99d3a748f39d8431 Mon Sep 17 00:00:00 2001 From: David Docampo Date: Wed, 9 Aug 2023 14:12:44 +0200 Subject: [PATCH] add logic to add in --age parameter on sops commands --- cmd/root.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 9fdb7f4..a93b94e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -77,14 +77,28 @@ func executeSops(args []string) { if wantedEncryptionKey == nil { log.Printf("Could not find encryption key \"%s\"", appConfig.EncryptionKeyName) } else { - err = os.Setenv("SOPS_AGE_KEY", wantedEncryptionKey.PrivateKey) - if err != nil { - log.Fatalf("could not set env variable: %v", err) + for index, arg := range args { + if arg == "sops" { + argsUntilSops := make([]string, len(args[:index+1])) + argsAfterSops := make([]string, len(args[index+1:])) + + copy(argsUntilSops, args[:index+1]) + copy(argsAfterSops, args[index+1:]) + + firstArgHalf := append(argsUntilSops, "--age", wantedEncryptionKey.PublicKey) + args = append(firstArgHalf, argsAfterSops...) + } } + } if wantedDecryptionKey == nil { log.Printf("Could not find decryption key \"%s\"", appConfig.DecryptionKeyName) + } else { + err = os.Setenv("SOPS_AGE_KEY", wantedDecryptionKey.PrivateKey) + if err != nil { + log.Fatalf("could not set env variable: %v", err) + } } var passThroughOut bytes.Buffer