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

@ -311,14 +311,16 @@ var flags = append([]cli.Flag{
EnvVars: []string{"WOODPECKER_FORGE_URL", "WOODPECKER_GITHUB_URL", "WOODPECKER_GITLAB_URL", "WOODPECKER_GITEA_URL", "WOODPECKER_BITBUCKET_URL"}, EnvVars: []string{"WOODPECKER_FORGE_URL", "WOODPECKER_GITHUB_URL", "WOODPECKER_GITLAB_URL", "WOODPECKER_GITEA_URL", "WOODPECKER_BITBUCKET_URL"},
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "forge-oauth-client", Name: "forge-oauth-client",
Usage: "oauth2 client id", 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"}, 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{ &cli.StringFlag{
Name: "forge-oauth-secret", Name: "forge-oauth-secret",
Usage: "oauth2 client 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"}, 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{ &cli.BoolFlag{
Name: "forge-skip-verify", Name: "forge-skip-verify",
@ -457,3 +459,13 @@ func datasourceDefaultValue() string {
} }
return "woodpecker.sqlite" 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" "encoding/hex"
"errors" "errors"
"fmt" "fmt"
"strings"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/urfave/cli/v2" "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.AdditionalOptions = make(map[string]any)
} }
_forge.Client = c.String("forge-oauth-client") _forge.Client = strings.TrimSpace(c.String("forge-oauth-client"))
_forge.ClientSecret = c.String("forge-oauth-secret") _forge.ClientSecret = strings.TrimSpace(c.String("forge-oauth-secret"))
_forge.URL = c.String("forge-url") _forge.URL = c.String("forge-url")
_forge.SkipVerify = c.Bool("forge-skip-verify") _forge.SkipVerify = c.Bool("forge-skip-verify")
_forge.OAuthHost = c.String("forge-oauth-host") _forge.OAuthHost = c.String("forge-oauth-host")