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

{{- $scheme := ternary "https" "http" .Values.internalTLS.enabled -}}
{{- $port := ternary .Values.core.containerPorts.https .Values.core.containerPorts.http .Values.internalTLS.enabled | int -}}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ printf "%s-envvars" (include "harbor.core" .) }}
  namespace: {{ include "common.names.namespace" . | quote }}
  {{- $versionLabel := dict "app.kubernetes.io/version" ( include "common.images.version" ( dict "imageRoot" .Values.core.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: core
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
data:
  PORT: {{ $port | quote }}
  DATABASE_TYPE: "postgresql"
  POSTGRESQL_HOST: {{ include "harbor.database.host" . | quote }}
  POSTGRESQL_PORT: {{ include "harbor.database.port" . | quote }}
  POSTGRESQL_USERNAME: {{ include "harbor.database.username" . | quote }}
  POSTGRESQL_DATABASE: {{ include "harbor.database.coreDatabase" . | quote }}
  POSTGRESQL_SSLMODE: {{ include "harbor.database.sslmode" . | quote }}
  POSTGRESQL_MAX_IDLE_CONNS: {{ .Values.database.maxIdleConns | quote }}
  POSTGRESQL_MAX_OPEN_CONNS: {{ .Values.database.maxOpenConns | quote }}
  EXT_ENDPOINT: {{ include "harbor.externalUrl" . | quote }}
  CORE_URL: {{ include "harbor.core.url" . | quote }}
  JOBSERVICE_URL: {{ include "harbor.jobservice.url" . | quote }}
  REGISTRY_URL: {{ include "harbor.registry.url" . | quote }}
  TOKEN_SERVICE_URL: {{ include "harbor.tokenService.url" . | quote }}
  CORE_LOCAL_URL: {{ printf "%s://127.0.0.1:%d" $scheme $port | quote }}
  CFG_EXPIRATION: "5"
  ADMIRAL_URL: "NA"
  WITH_TRIVY: {{ .Values.trivy.enabled | quote }}
  TRIVY_ADAPTER_URL: {{ include "harbor.trivy.url" . | quote }}
  REGISTRY_STORAGE_PROVIDER_NAME: {{ .Values.persistence.imageChartStorage.type | quote }}
  LOG_LEVEL: {{ .Values.logLevel | quote }}
  CONFIG_PATH: "/etc/core/app.conf"
  SYNC_REGISTRY: "false"
  CHART_CACHE_DRIVER: "redis"
  PORTAL_URL: {{ include "harbor.portal.url" . | quote }}
  REGISTRY_CONTROLLER_URL: {{ include "harbor.registryCtl.url" . | quote }}
  REGISTRY_CREDENTIAL_USERNAME: {{ .Values.registry.credentials.username | quote }}
  PERMITTED_REGISTRY_TYPES_FOR_PROXY_CACHE: "docker-hub,harbor,azure-acr,aws-ecr,google-gcr,quay,docker-registry,github-ghcr,jfrog-artifactory"
  {{- if .Values.core.uaaSecret }}
  UAA_CA_ROOT: "/etc/core/auth-ca/auth-ca.crt"
  {{- end }}
  {{- if has "core" .Values.proxy.components }}
  HTTP_PROXY: {{ .Values.proxy.httpProxy | quote }}
  HTTPS_PROXY: {{ .Values.proxy.httpsProxy | quote }}
  NO_PROXY: {{ include "harbor.noProxy" . | quote }}
  {{- end }}
  {{- if .Values.metrics.enabled}}
  METRIC_ENABLE: "true"
  METRIC_PATH: {{ .Values.metrics.path | quote }}
  METRIC_PORT: {{ .Values.core.containerPorts.metrics | quote }}
  METRIC_NAMESPACE: harbor
  METRIC_SUBSYSTEM: core
  {{- end }}
  {{- if .Values.tracing.enabled }}
  TRACE_SERVICE_NAME: "harbor-core"
  {{- include "harbor.tracing.envvars" . | nindent 2}}
  {{- end }}
  ARTIFACT_PULL_ASYNC_FLUSH_DURATION: {{ .Values.core.artifactPullAsyncFlushDuration | quote }}
  GDPR_DELETE_USER: {{ ternary "true" "false" .Values.core.gdpr.deleteUser | quote }}
  GDPR_AUDIT_LOGS: {{ ternary "true" "false" .Values.core.gdpr.auditLogsCompliant | quote }}
  {{- if .Values.cache.enabled }}
  CACHE_ENABLED: "true"
  CACHE_EXPIRE_HOURS: {{ .Values.cache.expireHours | quote }}
  {{- end }}
  QUOTA_UPDATE_PROVIDER: {{ .Values.core.quotaUpdateProvider | quote }}
