2020-02-17 23:51:49 -06:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
2021-05-06 15:13:14 -05:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"golang.org/x/term"
|
2020-02-17 23:51:49 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
type secrets map[string]string
|
|
|
|
|
|
|
|
func newSecrets(secretList []string) secrets {
|
|
|
|
s := make(map[string]string)
|
|
|
|
for _, secretPair := range secretList {
|
2020-03-02 10:11:46 -06:00
|
|
|
secretPairParts := strings.SplitN(secretPair, "=", 2)
|
2021-01-12 11:54:53 -06:00
|
|
|
secretPairParts[0] = strings.ToUpper(secretPairParts[0])
|
|
|
|
if strings.ToUpper(s[secretPairParts[0]]) == secretPairParts[0] {
|
2021-05-06 15:13:14 -05:00
|
|
|
log.Errorf("Secret %s is already defined (secrets are case insensitive)", secretPairParts[0])
|
2021-01-12 11:54:53 -06:00
|
|
|
}
|
2020-02-17 23:51:49 -06:00
|
|
|
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])
|
2021-05-06 15:13:14 -05:00
|
|
|
val, err := term.ReadPassword(int(os.Stdin.Fd()))
|
2022-02-25 10:47:49 -06:00
|
|
|
fmt.Println()
|
2020-02-17 23:51:49 -06:00
|
|
|
if err != nil {
|
2021-05-06 15:13:14 -05:00
|
|
|
log.Errorf("failed to read input: %v", err)
|
|
|
|
os.Exit(1)
|
2020-02-17 23:51:49 -06:00
|
|
|
}
|
|
|
|
s[secretPairParts[0]] = string(val)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s secrets) AsMap() map[string]string {
|
|
|
|
return s
|
|
|
|
}
|