Fix oauth file envvars (#3726)

Co-authored-by: Anbraten <6918444+anbraten@users.noreply.github.com>
This commit is contained in:
Dan 2024-05-27 05:22:31 -04:00 committed by GitHub
parent abc92ddb11
commit 6132136d55
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 8 deletions

View file

@ -314,11 +314,13 @@ var flags = append([]cli.Flag{
Name: "forge-oauth-client",
Usage: "oauth2 client id",
EnvVars: []string{"WOODPECKER_FORGE_CLIENT", "WOODPECKER_GITHUB_CLIENT", "WOODPECKER_GITLAB_CLIENT", "WOODPECKER_GITEA_CLIENT", "WOODPECKER_BITBUCKET_CLIENT", "WOODPECKER_BITBUCKET_DC_CLIENT_ID"},
FilePath: getFirstNonEmptyEnvVar([]string{"WOODPECKER_FORGE_CLIENT_FILE", "WOODPECKER_GITHUB_CLIENT_FILE", "WOODPECKER_GITLAB_CLIENT_FILE", "WOODPECKER_GITEA_CLIENT_FILE", "WOODPECKER_BITBUCKET_CLIENT_FILE", "WOODPECKER_BITBUCKET_DC_CLIENT_ID_FILE"}),
},
&cli.StringFlag{
Name: "forge-oauth-secret",
Usage: "oauth2 client secret",
EnvVars: []string{"WOODPECKER_FORGE_SECRET", "WOODPECKER_GITHUB_SECRET", "WOODPECKER_GITLAB_SECRET", "WOODPECKER_GITEA_SECRET", "WOODPECKER_BITBUCKET_SECRET", "WOODPECKER_BITBUCKET_DC_CLIENT_SECRET"},
FilePath: getFirstNonEmptyEnvVar([]string{"WOODPECKER_FORGE_SECRET_FILE", "WOODPECKER_GITHUB_SECRET_FILE", "WOODPECKER_GITLAB_SECRET_FILE", "WOODPECKER_GITEA_SECRET_FILE", "WOODPECKER_BITBUCKET_SECRET_FILE", "WOODPECKER_BITBUCKET_DC_CLIENT_SECRET_FILE"}),
},
&cli.BoolFlag{
Name: "forge-skip-verify",
@ -457,3 +459,13 @@ func datasourceDefaultValue() string {
}
return "woodpecker.sqlite"
}
func getFirstNonEmptyEnvVar(envVars []string) string {
for _, envVar := range envVars {
val := os.Getenv(envVar)
if val != "" {
return val
}
}
return ""
}

View file

@ -21,6 +21,7 @@ import (
"encoding/hex"
"errors"
"fmt"
"strings"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
@ -114,8 +115,8 @@ func setupForgeService(c *cli.Context, _store store.Store) error {
_forge.AdditionalOptions = make(map[string]any)
}
_forge.Client = c.String("forge-oauth-client")
_forge.ClientSecret = c.String("forge-oauth-secret")
_forge.Client = strings.TrimSpace(c.String("forge-oauth-client"))
_forge.ClientSecret = strings.TrimSpace(c.String("forge-oauth-secret"))
_forge.URL = c.String("forge-url")
_forge.SkipVerify = c.Bool("forge-skip-verify")
_forge.OAuthHost = c.String("forge-oauth-host")