apiVersion: v1
kind: ConfigMap
metadata:
  name: flowforge-config
data:
  flowforge.yml: |
    port: 3000
    host: 0.0.0.0
    domain: {{ .Values.forge.domain }}
    {{- if .Values.forge.entryPoint }}
    base_url: http{{- if .Values.forge.https -}}s{{- end -}}://{{ .Values.forge.entryPoint }}
    {{- else }}
    base_url: http{{- if .Values.forge.https -}}s{{- end -}}://forge.{{ .Values.forge.domain }}
    {{- end }}
    api_url: http://forge.{{ .Release.Namespace }}
    db:
      type: postgres
      host: {{ .Release.Name }}-postgresql
      {{- if and (not .Values.forge.localPostgresql) (.Values.forge.postgres) }}
      port: {{ .Values.forge.postgres.port | default 5432 }}
      {{- end }}
      user: {{ .Values.forge.dbUsername }}
      password: {{ .Values.forge.dbPassword }}
    driver:
      type: kubernetes
      options:
        registry: {{ .Values.forge.registry }}
        {{- if .Values.forge.registrySecrets }}
        registrySecrets:
          {{- range .Values.forge.registrySecrets }}
          - {{ . }}
          {{- end }}
        {{- end}}
        {{- if .Values.forge.projectSelector }}
        projectSelector:
          {{- range $key, $value := .Values.forge.projectSelector }}
          {{ $key }}: {{ $value }}
          {{- end}}
        {{- end }}
        {{- if .Values.forge.projectNamespace }}
        projectNamespace: {{ .Values.forge.projectNamespace }}
        {{- end }}
        {{- if .Values.forge.cloudProvider }}
        cloudProvider: {{ .Values.forge.cloudProvider }}
        {{- end }}
    {{- if .Values.forge.email }}
    email:
      enabled: true
      {{- if .Values.forge.email.from }}
      from: {{ .Values.forge.email.from | quote }}
      {{- end}}
    {{- if .Values.forge.email.smtp }}
      smtp:
        host: {{ .Values.forge.email.smtp.host }}
        port: {{ .Values.forge.email.smtp.port | default 587  }}
        secure: {{ .Values.forge.email.smtp.tls | default false  }}
        auth:
          user: {{ .Values.forge.email.smtp.user }}
          pass: {{ .Values.forge.email.smtp.password }}
    {{- end }}
    {{- if .Values.forge.email.ses }}
      ses:
        region: {{ .Values.forge.email.ses.region }}
    {{- end }}
    {{- else }}
    email:
      enabled: false
    {{- end }}
    {{- if .Values.forge.ee }}
    {{- if .Values.forge.ee.billing }}
    billing:
      {{- if .Values.forge.ee.billing.stripe }}
      stripe:
        key: {{ .Values.forge.ee.billing.stripe.key }}
        wh_secret: {{ .Values.forge.ee.billing.stripe.wh_secret }}
        team_price: {{ .Values.forge.ee.billing.stripe.team_price }}
        team_product: {{ .Values.forge.ee.billing.stripe.team_product }}
        project_price: {{ .Values.forge.ee.billing.stripe.project_price }}
        project_product: {{ .Values.forge.ee.billing.stripe.project_product }}
      {{- end }}
    {{- end }}
    {{- end }}

