{{- if .Values.chartmuseum.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ printf "%s-envvars" (include "harbor.chartmuseum" .) }}
  namespace: {{ .Release.Namespace | quote }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
    app.kubernetes.io/component: chartmuseum
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
data:
  PORT: {{ ternary .Values.chartmuseum.containerPorts.https .Values.chartmuseum.containerPorts.http .Values.internalTLS.enabled | quote }}
  {{- if .Values.internalTLS.enabled }}
  TLS_CERT: "/etc/harbor/ssl/chartmuseum/tls.crt"
  TLS_KEY: "/etc/harbor/ssl/chartmuseum/tls.key"
  {{- end }}
  {{- if .Values.chartmuseum.useRedisCache }}
  CACHE: "redis"
  CACHE_REDIS_ADDR: {{ printf "%s:%s" ( include "harbor.redis.host" . ) ( include "harbor.redis.port" . ) | quote }}
  CACHE_REDIS_DB: {{ include "harbor.redis.chartmuseumDatabaseIndex" . | quote }}
  {{- end }}
  # The user is hardcoded because the core binary has it hardcoded so it is not configurable.
  BASIC_AUTH_USER: "chart_controller"
  {{- if .Values.chartmuseum.absoluteUrl }}
  CHART_URL: {{ printf "%s/%s" ( include "harbor.externalUrl" . )  .Values.chartmuseum.chartRepoName | quote }}
  {{- end }}
  DEPTH: {{ .Values.chartmuseum.depth | quote }}
  {{- if or (eq .Values.logLevel "debug") .Values.chartmuseum.image.debug }}
  DEBUG: "true"
  {{- else }}
  DEBUG: "false"
  {{- end }}
  LOG_JSON: {{ .Values.chartmuseum.logJson | quote }}
  DISABLE_METRICS: {{ .Values.chartmuseum.disableMetrics | quote }}
  DISABLE_API: {{ .Values.chartmuseum.disableApi | quote }}
  DISABLE_STATEFILES: {{ .Values.chartmuseum.disableStatefiles | quote }}
  ALLOW_OVERWRITE: {{ .Values.chartmuseum.allowOverwrite | quote }}
  AUTH_ANONYMOUS_GET: {{ .Values.chartmuseum.anonymousGet | quote }}
  {{- if .Values.chartmuseum.contextPath }}
  CONTEXT_PATH: {{ .Values.chartmuseum.contextPath | quote }}
  {{- end }}
  {{- if .Values.chartmuseum.indexLimit }}
  INDEX_LIMIT: {{ .Values.chartmuseum.indexLimit | quote }}
  {{- end }}
  {{- if .Values.chartmuseum.maxUploadSize }}
  MAX_UPLOAD_SIZE: {{ .Values.chartmuseum.maxUploadSize | quote }}
  {{- end }}
  {{- if .Values.chartmuseum.storageTimestampTolerance }}
  STORAGE_TIMESTAMP_TOLERANCE: {{ .Values.chartmuseum.storageTimestampTolerance | quote }}
  {{- end }}
  {{- if .Values.chartmuseum.maxStorageObjects }}
  MAX_STORAGE_OBJECTS: {{ .Values.chartmuseum.maxStorageObjects | quote }}
  {{- end }}
  {{- if .Values.chartmuseum.chartPostFormFieldName }}
  CHART_POST_FORM_FIELD_NAME: {{ .Values.chartmuseum.chartPostFormFieldName | quote }}
  {{- end }}
  {{- if .Values.chartmuseum.provPostFormFieldName }}
  PROV_POST_FORM_FIELD_NAME: {{ .Values.chartmuseum.provPostFormFieldName | quote }}
  {{- end }}
  {{- if eq .Values.persistence.imageChartStorage.type "filesystem" }}
  STORAGE: "local"
  STORAGE_LOCAL_ROOTDIR: "/bitnami/data"
  {{- else if eq .Values.persistence.imageChartStorage.type "azure" }}
  STORAGE: "microsoft"
  STORAGE_MICROSOFT_CONTAINER: {{ .Values.persistence.imageChartStorage.azure.container | quote }}
  AZURE_STORAGE_ACCOUNT: {{ .Values.persistence.imageChartStorage.azure.accountname | quote }}
  STORAGE_MICROSOFT_PREFIX: {{ .Values.persistence.imageChartStorage.azure.storagePrefix | quote }}
  AZURE_BASE_URL: {{ .Values.persistence.imageChartStorage.azure.realm | quote }}
  {{- else if eq .Values.persistence.imageChartStorage.type "gcs" }}
  STORAGE: "google"
  STORAGE_GOOGLE_BUCKET: {{ .Values.persistence.imageChartStorage.gcs.bucket }}
  GOOGLE_APPLICATION_CREDENTIALS: /etc/chartmuseum/gcs-key.json
  {{- if .Values.persistence.imageChartStorage.gcs.rootdirectory }}
  STORAGE_GOOGLE_PREFIX: {{ .Values.persistence.imageChartStorage.gcs.rootdirectory | quote }}
  {{- end }}
  {{- else if eq .Values.persistence.imageChartStorage.type "s3" }}
  STORAGE: "amazon"
  {{- if .Values.persistence.imageChartStorage.s3.bucket }}
  STORAGE_AMAZON_BUCKET: {{ .Values.persistence.imageChartStorage.s3.bucket | quote }}
  {{- end }}
  {{- if .Values.persistence.imageChartStorage.s3.rootdirectory }}
  STORAGE_AMAZON_PREFIX: {{ .Values.persistence.imageChartStorage.s3.rootdirectory | quote }}
  {{- end }}
  {{- if .Values.persistence.imageChartStorage.s3.region }}
  STORAGE_AMAZON_REGION: {{ .Values.persistence.imageChartStorage.s3.region | quote }}
  {{- end }}
  {{- if .Values.persistence.imageChartStorage.s3.regionendpoint }}
  STORAGE_AMAZON_ENDPOINT: {{ .Values.persistence.imageChartStorage.s3.regionendpoint | quote }}
  {{- end }}
  {{- if .Values.persistence.imageChartStorage.s3.accesskey }}
  AWS_ACCESS_KEY_ID: {{ .Values.persistence.imageChartStorage.s3.accesskey | quote }}
  {{- end }}
  {{- if .Values.persistence.imageChartStorage.s3.keyid }}
  STORAGE_AMAZON_SSE: {{ .Values.persistence.imageChartStorage.s3.sse | quote }}
  {{- end }}
  {{- else if eq .Values.persistence.imageChartStorage.type "swift" }}
  STORAGE: "openstack"
  STORAGE_OPENSTACK_CONTAINER: {{ .Values.persistence.imageChartStorage.swift.container | quote }}
  {{- if .Values.persistence.imageChartStorage.swift.secretkey }}
  STORAGE_OPENSTACK_PREFIX: {{ .Values.persistence.imageChartStorage.swift.prefix | quote }}
  {{- end }}
  {{- if .Values.persistence.imageChartStorage.swift.secretkey }}
  STORAGE_OPENSTACK_REGION: {{ .Values.persistence.imageChartStorage.swift.region | quote }}
  {{- end }}
  OS_AUTH_URL: {{ .Values.persistence.imageChartStorage.swift.authurl | quote }}
  OS_USERNAME: {{ .Values.persistence.imageChartStorage.swift.username | quote }}
  {{- if .Values.persistence.imageChartStorage.swift.secretkey }}
  OS_PROJECT_ID: {{ .Values.persistence.imageChartStorage.swift.tenantid | quote }}
  {{- end }}
  {{- if .Values.persistence.imageChartStorage.swift.secretkey }}
  OS_PROJECT_NAME: {{ .Values.persistence.imageChartStorage.swift.tenant | quote }}
  {{- end }}
  {{- if .Values.persistence.imageChartStorage.swift.secretkey }}
  OS_DOMAIN_ID: {{ .Values.persistence.imageChartStorage.swift.domainid | quote }}
  {{- end }}
  {{- if .Values.persistence.imageChartStorage.swift.secretkey }}
  OS_DOMAIN_NAME: {{ .Values.persistence.imageChartStorage.swift.domain | quote }}
  {{- end }}
  {{- else if eq .Values.persistence.imageChartStorage.type "oss" }}
  STORAGE: "alibaba"
  STORAGE_ALIBABA_BUCKET: {{ .Values.persistence.imageChartStorage.oss.bucket | quote }}
  {{- if .Values.persistence.imageChartStorage.oss.secretkey }}
  STORAGE_ALIBABA_PREFIX: {{ .Values.persistence.imageChartStorage.oss.rootdirectory | quote }}
  {{- end }}
  {{- if .Values.persistence.imageChartStorage.oss.secretkey }}
  STORAGE_ALIBABA_ENDPOINT: {{ .Values.persistence.imageChartStorage.oss.endpoint | quote }}
  {{- end }}
  ALIBABA_CLOUD_ACCESS_KEY_ID: {{ .Values.persistence.imageChartStorage.oss.accesskeyid | quote }}
  {{- end }}
{{- end }}
