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

View File

@ -9,22 +9,14 @@ import (
func main() { func main() {
var ( var (
registry = "registry.heroku.com" registry = "registry.heroku.com"
process = os.Getenv("PLUGIN_PROCESS_TYPE") process = getenv("PLUGIN_PROCESS_TYPE")
app = os.Getenv("PLUGIN_APP") app = getenv("PLUGIN_APP")
email = os.Getenv("PLUGIN_EMAIL") email = getenv("PLUGIN_EMAIL", "HEROKU_EMAIL")
key = os.Getenv("PLUGIN_API_KEY") key = getenv("PLUGIN_API_KEY", "HEROKU_API_KEY")
) )
// if the heroku email is provided as a named secret if process == "" {
// then we should use it. process = "web"
if os.Getenv("HEROKU_EMAIL") != "" {
email = os.Getenv("HEROKU_EMAIL")
}
// if the heroku api key is provided as a named secret
// then we should use it.
if os.Getenv("HEROKU_API_KEY") != "" {
key = os.Getenv("HEROKU_API_KEY")
} }
os.Setenv("PLUGIN_REGISTRY", registry) os.Setenv("PLUGIN_REGISTRY", registry)
@ -34,7 +26,6 @@ func main() {
os.Setenv("DOCKER_USERNAME", email) os.Setenv("DOCKER_USERNAME", email)
os.Setenv("DOCKER_EMAIL", email) os.Setenv("DOCKER_EMAIL", email)
// invoke the base docker plugin binary
cmd := exec.Command("drone-docker") cmd := exec.Command("drone-docker")
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
@ -43,3 +34,13 @@ func main() {
os.Exit(1) os.Exit(1)
} }
} }
func getenv(key ...string) (s string) {
for _, k := range key {
s = os.Getenv(k)
if s != "" {
return
}
}
return
}