{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ printf "%s-envvars" (include "harbor.trivy" .) }}
  namespace: {{ include "common.names.namespace" . | quote }}
  {{- $versionLabel := dict "app.kubernetes.io/version" ( include "common.images.version" ( dict "imageRoot" .Values.trivy.image "chart" .Chart ) ) }}
  {{- $labels := include "common.tplvalues.merge" ( dict "values" ( list .Values.commonLabels $versionLabel ) "context" . ) }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" $labels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: trivy
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
data:
  SCANNER_LOG_LEVEL: {{ .Values.logLevel | quote }}
  SCANNER_TRIVY_CACHE_DIR: {{ printf "%s/%s" .Values.trivy.cacheDir "trivy" | quote }}
  SCANNER_TRIVY_REPORTS_DIR: {{ printf "%s/%s" .Values.trivy.cacheDir "reports" | quote }}
  SCANNER_TRIVY_DEBUG_MODE: {{ .Values.trivy.debugMode | quote }}
  SCANNER_TRIVY_VULN_TYPE: {{ .Values.trivy.vulnType | quote }}
  SCANNER_TRIVY_SEVERITY: {{ .Values.trivy.severity | quote }}
  SCANNER_TRIVY_IGNORE_UNFIXED: {{ .Values.trivy.ignoreUnfixed | quote }}
  SCANNER_TRIVY_SKIP_UPDATE: {{ .Values.trivy.skipUpdate | quote }}
  SCANNER_TRIVY_SKIP_JAVA_DB_UPDATE: {{ .Values.trivy.skipJavaDbUpdate | quote }}
  {{- if .Values.trivy.dbRepository }}
  SCANNER_TRIVY_DB_REPOSITORY: {{ .Values.trivy.dbRepository | quote }}
  {{- end }}
  {{- if .Values.trivy.javaDbRepository }}
  SCANNER_TRIVY_JAVA_DB_REPOSITORY: {{ .Values.trivy.javaDbRepository | quote }}
  {{- end }}
  SCANNER_TRIVY_INSECURE: {{ .Values.trivy.insecure | quote }}
  SCANNER_API_SERVER_ADDR: {{ printf ":%d" (ternary .Values.trivy.containerPorts.https .Values.trivy.containerPorts.http .Values.internalTLS.enabled | int) | quote }}
  {{- if .Values.internalTLS.enabled }}
  INTERNAL_TLS_ENABLED: "true"
  SCANNER_API_SERVER_TLS_KEY: /etc/harbor/ssl/trivy/tls.key
  SCANNER_API_SERVER_TLS_CERTIFICATE: /etc/harbor/ssl/trivy/tls.crt
  {{- end }}
  {{- if has "trivy" .Values.proxy.components }}
  HTTP_PROXY: {{ .Values.proxy.httpProxy | quote }}
  HTTPS_PROXY: {{ .Values.proxy.httpsProxy | quote }}
  NO_PROXY: {{ include "harbor.noProxy" . | quote }}
  {{- end }}
