Skip to content

Commit

Permalink
Merge pull request #6 from wunderio/feature/multisecret-decryption
Browse files Browse the repository at this point in the history
Normalize separators for encoded file list
  • Loading branch information
Jancis authored Mar 24, 2022
2 parents d70fde5 + e701274 commit f5b39c9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
8 changes: 8 additions & 0 deletions IDEAS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Gox - Simple Go Cross Compilation
https://github.com/mitchellh/gox

# Binary signing for OS/X
https://www.kencochrane.com/2020/08/01/build-and-sign-golang-binaries-for-macos-with-github-actions/

# Self updating
https://github.com/rhysd/go-github-selfupdate
15 changes: 13 additions & 2 deletions cmd/secretsDecrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"os"
"regexp"
"strings"

"encoding/base64"
Expand Down Expand Up @@ -31,20 +32,30 @@ var secretsDecryptCmd = &cobra.Command{
}
}

// Replace comma with whitespace and iterate all whitespace separated values.
// This also means there can't be commas nor whitespaces in filenames.
space := regexp.MustCompile(`,\s?|\s+`)
files = space.ReplaceAllString(files, " ")

// Allow failing with exit code 0 when no files defined.
if len(files) == 0 {
fmt.Println("No input files supplied")
return
}

// Split on comma.
fileList := strings.Split(files, ",")
// Split on whitespace.
fileList := strings.Split(files, " ")

// Decrypt files
for i := range fileList {
file := fileList[i]
fmt.Printf("Decrypting %s\n", file)

if debug == true {
fmt.Print("..skipping\n")
continue
}

// Read encrypted file
encryptedMsg, err := os.ReadFile(file)
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions tests/secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ func TestSecretsEncryptDecryptCmd(t *testing.T) {
t.Error("Decrypted file incorrect")
}

// Test multiple file separator
command = "secrets decrypt --file 'tests/test-secret1,tests/test-secret2, tests/test-secret3 tests/test-secret4' --secret-key test --debug"
environment = []string{}
testString = `Decrypting tests/test-secret1
..skipping
Decrypting tests/test-secret2
..skipping
Decrypting tests/test-secret3
..skipping
Decrypting tests/test-secret4
..skipping
`
CliExecTest(t, command, environment, testString, true)

// Change dir back to previous
os.Chdir(wd)
}

0 comments on commit f5b39c9

Please sign in to comment.