enable fallback secret names [ci skip]

This commit is contained in:
Brad Rydzewski
2017-08-27 12:57:23 -07:00
parent da903e4d81
commit f25b013937
2 changed files with 38 additions and 20 deletions

View File

@@ -8,12 +8,19 @@ import (
"strings"
)
// gcr default username
const username = "_json_key"
func main() {
var (
username = "_json_key"
password = os.Getenv("GCR_TOKEN")
registry = os.Getenv("PLUGIN_REGISTRY")
repo = os.Getenv("PLUGIN_REPO")
repo = getenv("PLUGIN_REPO")
registry = getenv("PLUGIN_REGISTRY")
password = getenv(
"PLUGIN_JSON_KEY",
"GCR_JSON_KEY",
"GOOGLE_CREDENTIALS",
"GOOGLE_APPLICATION_CREDENTIALS",
)
)
// decode the token if base64 encoded
@@ -32,9 +39,9 @@ func main() {
// should prepend.
if !strings.HasPrefix(repo, registry) {
repo = path.Join(registry, repo)
os.Setenv("PLUGIN_REPO", repo)
}
os.Setenv("PLUGIN_REPO", repo)
os.Setenv("PLUGIN_REGISTRY", registry)
os.Setenv("DOCKER_USERNAME", username)
os.Setenv("DOCKER_PASSWORD", password)
@@ -48,3 +55,13 @@ func main() {
os.Exit(1)
}
}
func getenv(key ...string) (s string) {
for _, k := range key {
s = os.Getenv(k)
if s != "" {
return
}
}
return
}