{{- $domains := .Values.domains -}}
{{- if .Values.global }}
  {{- if .Values.global.domains }}
    {{- $domains = .Values.global.domains -}}
  {{- end -}}
{{- end -}}

{{- if not $domains -}}
  {{- if .Values.environment.ADRESS -}}
    {{- $name := dict "name" (.Values.environment.ADRESS | trimPrefix "https://" | trimPrefix "http://") -}}
    {{- $domains = (list (merge .Values.environment $name)) -}}
  {{- else -}}
    {{- $domains = list (merge .Values.environment) -}}
  {{- end -}}
{{- end -}}

apiVersion: v1
kind: ConfigMap
metadata:
  name: webconfig
  namespace: {{ .Release.Namespace  }}
data:
  EMBED_MODE: "{{ .Values.environment.EMBED_MODE }}"
  FLASK_ORIGINS: {{ (append (append .Values.environment.FLASK_ORIGINS (printf "https://%s" .Values.global.rds.domain)) (printf "http://%s" .Values.global.rds.domain)) | toJson | squote }}
  SECRET_KEY: "{{ .Values.environment.SECRET_KEY }}"
  DESCRIBO_API_ENDPOINT: "{{ .Values.environment.DESCRIBO_API_ENDPOINT }}"
  DESCRIBO_API_SECRET: {{ .Values.global.describo.api_secret | quote }}
  VUE_APP_DESCRIBO_URL: https://{{ .Values.global.describo.domain }}/application
  VUE_APP_FRONTENDHOST: https://{{ .Values.global.rds.domain }}
  VUE_APP_SOCKETIO_HOST: https://{{ .Values.global.rds.domain }}
  SOCKETIO_HOST: https://{{ .Values.global.rds.domain }}
  SOCKETIO_PATH: "{{ .Values.environment.SOCKETIO_PATH }}"
  VUE_APP_BASE_URL: "{{ .Values.environment.VUE_APP_BASE_URL }}"
  {{- with (mustMergeOverwrite (.Values.global | default dict) .Values.environment) }}
  REDIS_HELPER_HOST: {{ .REDIS_HELPER_HOST | default "redis-helper" | quote }}
  REDIS_HELPER_PORT: {{ .REDIS_HELPER_PORT | default "6379" | quote }}
  REDIS_HOST: {{ .REDIS_HOST | default "redis" | quote }}
  REDIS_PORT: {{ .REDIS_PORT | default "6379" | quote }}
  {{- end }}
  PROMETHEUS_MULTIPROC_DIR: "/tmp"
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: domainsconfig
  namespace: {{ .Release.Namespace  }}
data:
  domains.json: |-
{{- $domains | toJson | nindent 4 }}
