From 928b39a7283ee274dd517e727624eceb3795594d Mon Sep 17 00:00:00 2001 From: Swastik Gour <48011880+swastik959@users.noreply.github.com> Date: Wed, 20 Dec 2023 21:27:28 +0530 Subject: [PATCH] fix: added the ability to set the trivy variables by the user (#797) Signed-off-by: swastik959 Signed-off-by: Alex Jones Co-authored-by: Alex Jones --- pkg/integration/trivy/trivy.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/pkg/integration/trivy/trivy.go b/pkg/integration/trivy/trivy.go index 259a161e0a..c4a602e12c 100644 --- a/pkg/integration/trivy/trivy.go +++ b/pkg/integration/trivy/trivy.go @@ -17,6 +17,7 @@ import ( "context" "fmt" "os" + "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -28,18 +29,26 @@ import ( "helm.sh/helm/v3/pkg/repo" ) -const ( - Repo = "https://aquasecurity.github.io/helm-charts/" - Version = "0.13.0" - ChartName = "trivy-operator" - RepoShortName = "aqua" - ReleaseName = "trivy-operator-k8sgpt" +var ( + Repo = getEnv("TRIVY_REPO", "https://aquasecurity.github.io/helm-charts/") + Version = getEnv("TRIVY_VERSION", "0.13.0") + ChartName = getEnv("TRIVY_CHART_NAME", "trivy-operator") + RepoShortName = getEnv("TRIVY_REPO_SHORT_NAME", "aqua") + ReleaseName = getEnv("TRIVY_RELEASE_NAME", "trivy-operator-k8sgpt") ) type Trivy struct { helm helmclient.Client } +func getEnv(key, defaultValue string) string { + value := os.Getenv(key) + if value == "" { + return defaultValue + } + return value +} + func NewTrivy() *Trivy { helmClient, err := helmclient.New(&helmclient.Options{}) if err != nil {