Ignore items from WOODPECKER_ENVIRONMENT only containing a key and no value (#781)

* fix 761

* refactor: rename to match what it does & log ignore case
This commit is contained in:
6543 2022-02-23 08:59:52 +01:00 committed by GitHub
parent dde0678246
commit c4960cdd2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -173,7 +173,7 @@ func setupRegistryService(c *cli.Context, s store.Store) model.RegistryService {
} }
func setupEnvironService(c *cli.Context, s store.Store) model.EnvironService { func setupEnvironService(c *cli.Context, s store.Store) model.EnvironService {
return environments.Filesystem(c.StringSlice("environment")) return environments.Parse(c.StringSlice("environment"))
} }
// setupRemote helper function to setup the remote from the CLI arguments. // setupRemote helper function to setup the remote from the CLI arguments.

View file

@ -3,6 +3,8 @@ package environments
import ( import (
"strings" "strings"
"github.com/rs/zerolog/log"
"github.com/woodpecker-ci/woodpecker/server/model" "github.com/woodpecker-ci/woodpecker/server/model"
) )
@ -10,12 +12,17 @@ type builtin struct {
globals []*model.Environ globals []*model.Environ
} }
// Filesystem returns a new local registry service. // Parse returns a EnvironService based on a string slice where key and value are separated by a ":" delimeter.
func Filesystem(params []string) model.EnvironService { func Parse(params []string) model.EnvironService {
var globals []*model.Environ var globals []*model.Environ
for _, item := range params { for _, item := range params {
kvPair := strings.SplitN(item, ":", 2) kvPair := strings.SplitN(item, ":", 2)
if len(kvPair) != 2 {
// ignore items only containing a key and no value
log.Warn().Msgf("key '%s' has no value, will be ignored", kvPair[0])
continue
}
globals = append(globals, &model.Environ{Name: kvPair[0], Value: kvPair[1]}) globals = append(globals, &model.Environ{Name: kvPair[0], Value: kvPair[1]})
} }
return &builtin{globals} return &builtin{globals}