From c4960cdd2c639245cced5cbbe5085f585c03266a Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 23 Feb 2022 08:59:52 +0100 Subject: [PATCH] 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 --- cmd/server/setup.go | 2 +- server/plugins/environments/filesystem.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/server/setup.go b/cmd/server/setup.go index 67028852e..e113ffe1c 100644 --- a/cmd/server/setup.go +++ b/cmd/server/setup.go @@ -173,7 +173,7 @@ func setupRegistryService(c *cli.Context, s store.Store) model.RegistryService { } 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. diff --git a/server/plugins/environments/filesystem.go b/server/plugins/environments/filesystem.go index 449e66420..f237ba596 100644 --- a/server/plugins/environments/filesystem.go +++ b/server/plugins/environments/filesystem.go @@ -3,6 +3,8 @@ package environments import ( "strings" + "github.com/rs/zerolog/log" + "github.com/woodpecker-ci/woodpecker/server/model" ) @@ -10,12 +12,17 @@ type builtin struct { globals []*model.Environ } -// Filesystem returns a new local registry service. -func Filesystem(params []string) model.EnvironService { +// Parse returns a EnvironService based on a string slice where key and value are separated by a ":" delimeter. +func Parse(params []string) model.EnvironService { var globals []*model.Environ for _, item := range params { 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]}) } return &builtin{globals}