1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-08-11 17:50:58 +00:00

support for secrets

Signed-off-by: Casey Lee <cplee@nektos.com>
This commit is contained in:
Casey Lee 2020-02-17 21:51:49 -08:00
parent bdb0c35ba3
commit 0094b96051
14 changed files with 708 additions and 9 deletions

36
cmd/secrets.go Normal file
View file

@ -0,0 +1,36 @@
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.Split(secretPair, "=")
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
}