From 28f3094057ddcad078d07ee67c7dabc5bca8ea80 Mon Sep 17 00:00:00 2001 From: aoteropas <135861877+aoteropas@users.noreply.github.com> Date: Mon, 4 Dec 2023 09:36:55 +0100 Subject: [PATCH 1/5] fix allowed change ref types environment read change the name of the variable in the if clause for the one that contains the env values. Follow the same approach that with other Env Variables --- jenkins/webhook-proxy/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/webhook-proxy/main.go b/jenkins/webhook-proxy/main.go index df6f58b3a..da3c2c424 100644 --- a/jenkins/webhook-proxy/main.go +++ b/jenkins/webhook-proxy/main.go @@ -204,7 +204,7 @@ func main() { var allowedChangeRefTypes []string envAllowedChangeRefTypes := strings.ToLower(os.Getenv(allowedChangeRefTypesEnvVar)) - if len(allowedChangeRefTypes) == 0 { + if len(envAllowedChangeRefTypes) == 0 { allowedChangeRefTypes = strings.Split(allowedChangeRefTypesDefault, ",") log.Println( "INFO:", From 13c933e943afcec26ef86f312308361daedb2240 Mon Sep 17 00:00:00 2001 From: aoteropas <135861877+aoteropas@users.noreply.github.com> Date: Mon, 4 Dec 2023 10:25:02 +0100 Subject: [PATCH 2/5] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 318a7c796..1cd4fddc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +### Fixed +- Check Environment Variable value for Allowed Change Ref Types ([#1252](https://github.com/opendevstack/ods-core/issues/1252)) + ## [4.3.0] - 2023-07-03 ### Added From e66e2ec8497e610491c564997754a94bd18a97d9 Mon Sep 17 00:00:00 2001 From: aoteropas <135861877+aoteropas@users.noreply.github.com> Date: Tue, 5 Dec 2023 10:09:39 +0100 Subject: [PATCH 3/5] set to lower the request chage type to match the one stored when reading the env variable it is set to lower to unify the values. setting to lower the request information to ensure that comparison works --- jenkins/webhook-proxy/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/webhook-proxy/main.go b/jenkins/webhook-proxy/main.go index da3c2c424..45d9dce15 100644 --- a/jenkins/webhook-proxy/main.go +++ b/jenkins/webhook-proxy/main.go @@ -402,7 +402,7 @@ func (s *Server) HandleRoot() http.HandlerFunc { } else { kind = "forward" } - if !includes(s.AllowedChangeRefTypes, req.Changes[0].Ref.Type) { + if !includes(s.AllowedChangeRefTypes, strings.ToLower(req.Changes[0].Ref.Type)) { log.Println(requestID, fmt.Sprintf( "Skipping change ref type %s as %s does not include it", req.Changes[0].Ref.Type, From 0bcc0a22fe68f1f5b2f6bcba440883b2dd2963e8 Mon Sep 17 00:00:00 2001 From: aoteropas <135861877+aoteropas@users.noreply.github.com> Date: Tue, 5 Dec 2023 11:15:27 +0100 Subject: [PATCH 4/5] set the default value for change types to lower case --- jenkins/webhook-proxy/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/webhook-proxy/main.go b/jenkins/webhook-proxy/main.go index 45d9dce15..0919afbae 100644 --- a/jenkins/webhook-proxy/main.go +++ b/jenkins/webhook-proxy/main.go @@ -205,7 +205,7 @@ func main() { var allowedChangeRefTypes []string envAllowedChangeRefTypes := strings.ToLower(os.Getenv(allowedChangeRefTypesEnvVar)) if len(envAllowedChangeRefTypes) == 0 { - allowedChangeRefTypes = strings.Split(allowedChangeRefTypesDefault, ",") + allowedChangeRefTypes = strings.Split(strings.ToLower(allowedChangeRefTypesDefault), ",") log.Println( "INFO:", allowedChangeRefTypesEnvVar, From 1ec94ed4fb0814ef3cfdddb60d19e5a98bf43e3e Mon Sep 17 00:00:00 2001 From: aoteropas <135861877+aoteropas@users.noreply.github.com> Date: Tue, 5 Dec 2023 11:54:05 +0100 Subject: [PATCH 5/5] Update main.go --- jenkins/webhook-proxy/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jenkins/webhook-proxy/main.go b/jenkins/webhook-proxy/main.go index 0919afbae..e6604dd9c 100644 --- a/jenkins/webhook-proxy/main.go +++ b/jenkins/webhook-proxy/main.go @@ -39,7 +39,7 @@ const ( allowedExternalProjectsEnvVar = "ALLOWED_EXTERNAL_PROJECTS" allowedExternalProjectsDefault = "opendevstack" allowedChangeRefTypesEnvVar = "ALLOWED_CHANGE_REF_TYPES" - allowedChangeRefTypesDefault = "BRANCH" + allowedChangeRefTypesDefault = "branch" namespaceSuffix = "-cd" letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" ) @@ -205,7 +205,7 @@ func main() { var allowedChangeRefTypes []string envAllowedChangeRefTypes := strings.ToLower(os.Getenv(allowedChangeRefTypesEnvVar)) if len(envAllowedChangeRefTypes) == 0 { - allowedChangeRefTypes = strings.Split(strings.ToLower(allowedChangeRefTypesDefault), ",") + allowedChangeRefTypes = strings.Split(allowedChangeRefTypesDefault, ",") log.Println( "INFO:", allowedChangeRefTypesEnvVar,