2019-01-17 16:15:35 +08:00
|
|
|
package actions
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-01-31 15:14:18 +08:00
|
|
|
"log"
|
2019-01-17 16:15:35 +08:00
|
|
|
"os"
|
|
|
|
|
2019-01-31 15:14:18 +08:00
|
|
|
"github.com/actions/workflow-parser/model"
|
|
|
|
"github.com/howeyc/gopass"
|
2019-01-17 16:15:35 +08:00
|
|
|
)
|
|
|
|
|
2019-01-31 15:14:18 +08:00
|
|
|
var secretCache map[string]string
|
2019-01-17 16:15:35 +08:00
|
|
|
|
2019-01-31 15:14:18 +08:00
|
|
|
type actionEnvironmentApplier struct {
|
|
|
|
*model.Action
|
2019-01-17 16:15:35 +08:00
|
|
|
}
|
|
|
|
|
2019-01-31 15:14:18 +08:00
|
|
|
func newActionEnvironmentApplier(action *model.Action) environmentApplier {
|
|
|
|
return &actionEnvironmentApplier{action}
|
2019-01-17 16:15:35 +08:00
|
|
|
}
|
|
|
|
|
2019-01-31 15:14:18 +08:00
|
|
|
func (action *actionEnvironmentApplier) applyEnvironment(env map[string]string) {
|
|
|
|
for envKey, envValue := range action.Env {
|
|
|
|
env[envKey] = envValue
|
2019-01-17 16:15:35 +08:00
|
|
|
}
|
|
|
|
|
2019-01-31 15:14:18 +08:00
|
|
|
for _, secret := range action.Secrets {
|
|
|
|
if secretVal, ok := os.LookupEnv(secret); ok {
|
|
|
|
env[secret] = secretVal
|
|
|
|
} else {
|
|
|
|
if secretCache == nil {
|
|
|
|
secretCache = make(map[string]string)
|
|
|
|
}
|
2019-01-17 16:15:35 +08:00
|
|
|
|
2019-01-31 15:14:18 +08:00
|
|
|
if _, ok := secretCache[secret]; !ok {
|
|
|
|
fmt.Printf("Provide value for '%s': ", secret)
|
|
|
|
val, err := gopass.GetPasswdMasked()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("abort")
|
|
|
|
}
|
2019-01-17 16:15:35 +08:00
|
|
|
|
2019-01-31 15:14:18 +08:00
|
|
|
secretCache[secret] = string(val)
|
|
|
|
}
|
|
|
|
env[secret] = secretCache[secret]
|
|
|
|
}
|
2019-01-17 16:15:35 +08:00
|
|
|
}
|
|
|
|
}
|