act/cmd/secrets.go
Cat™ 2811101dea
Make all secrets case insensitive by formatting them to uppercase (#470)
* Uppercase secrets, print error when secret with same name already exists

* Test lower-to-upper case formatting for secrets
2021-01-12 09:54:53 -08:00

40 lines
980 B
Go

package cmd
import (
"fmt"
"log"
"os"
"strings"
"github.com/howeyc/gopass"
)
type secrets map[string]string
func newSecrets(secretList []string) secrets {
s := make(map[string]string)
for _, secretPair := range secretList {
secretPairParts := strings.SplitN(secretPair, "=", 2)
secretPairParts[0] = strings.ToUpper(secretPairParts[0])
if strings.ToUpper(s[secretPairParts[0]]) == secretPairParts[0] {
log.Fatalf("Secret %s is already defined (secrets are case insensitive)", secretPairParts[0])
}
if len(secretPairParts) == 2 {
s[secretPairParts[0]] = secretPairParts[1]
} else if env, ok := os.LookupEnv(secretPairParts[0]); ok && env != "" {
s[secretPairParts[0]] = env
} else {
fmt.Printf("Provide value for '%s': ", secretPairParts[0])
val, err := gopass.GetPasswdMasked()
if err != nil {
log.Fatal("abort")
}
s[secretPairParts[0]] = string(val)
}
}
return s
}
func (s secrets) AsMap() map[string]string {
return s
}