fix: added the ability to set the trivy variables by the user (#797)

Signed-off-by: swastik959 <Sswastik959@gmail.com>
Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
Co-authored-by: Alex Jones <alexsimonjones@gmail.com>
This commit is contained in:
Swastik Gour 2023-12-20 21:27:28 +05:30 committed by GitHub
parent c23f24de2e
commit 928b39a728
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,7 @@ import (
"context" "context"
"fmt" "fmt"
"os" "os"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
@ -28,18 +29,26 @@ import (
"helm.sh/helm/v3/pkg/repo" "helm.sh/helm/v3/pkg/repo"
) )
const ( var (
Repo = "https://aquasecurity.github.io/helm-charts/" Repo = getEnv("TRIVY_REPO", "https://aquasecurity.github.io/helm-charts/")
Version = "0.13.0" Version = getEnv("TRIVY_VERSION", "0.13.0")
ChartName = "trivy-operator" ChartName = getEnv("TRIVY_CHART_NAME", "trivy-operator")
RepoShortName = "aqua" RepoShortName = getEnv("TRIVY_REPO_SHORT_NAME", "aqua")
ReleaseName = "trivy-operator-k8sgpt" ReleaseName = getEnv("TRIVY_RELEASE_NAME", "trivy-operator-k8sgpt")
) )
type Trivy struct { type Trivy struct {
helm helmclient.Client helm helmclient.Client
} }
func getEnv(key, defaultValue string) string {
value := os.Getenv(key)
if value == "" {
return defaultValue
}
return value
}
func NewTrivy() *Trivy { func NewTrivy() *Trivy {
helmClient, err := helmclient.New(&helmclient.Options{}) helmClient, err := helmclient.New(&helmclient.Options{})
if err != nil { if err != nil {