apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "cerebro.fullname" . }}
  labels:
    app: {{ template "cerebro.name" . }}
    chart: {{ template "cerebro.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
data:
  application.conf: |-
    {{- if .Values.config.secret }}
    secret = {{ .Values.config.secret | quote }}
    {{- else }}
    secret = {{ randAlphaNum 64 | quote }}
    {{- end }}

    {{- if .Values.config.tlsVerify }}
    play.ws.ssl.loose.acceptAnyCertificate = false
    {{- else }}
    play.ws.ssl.loose.acceptAnyCertificate = true
    {{- end }}
    {{- if .Values.config.tlsCaCert }}
    play.ws.ssl {
      trustManager = {
        stores = [
          { type = "PEM", path = {{ .Values.config.tlsCaCert | quote }} }
        ]
      }
    }
    {{- end }}

    basePath = {{ .Values.config.basePath | quote }}

    pidfile.path = /dev/null

    rest.history.size = {{ .Values.config.restHistorySize }}

    data.path = "/var/db/cerebro/cerebro.db"

    es = {
      gzip = true
    }

    auth = {
      # either basic or ldap
      type: ${?AUTH_TYPE}
      settings {
        # LDAP
        url = ${?LDAP_URL}
        base-dn = ${?LDAP_BASE_DN}
        method = ${?LDAP_METHOD}
        user-template = ${?LDAP_USER_TEMPLATE}
        bind-dn = ${?LDAP_BIND_DN}
        bind-pw = ${?LDAP_BIND_PWD}
        group-search {
          base-dn = ${?LDAP_GROUP_BASE_DN}
          user-attr = ${?LDAP_USER_ATTR}
          user-attr-template = ${?LDAP_USER_ATTR_TEMPLATE}
          group = ${?LDAP_GROUP}
        }

        # Basic auth
        username = ${?BASIC_AUTH_USER}
        password = ${?BASIC_AUTH_PWD}
      }
    }

    hosts = [
      {{- range $index, $element := .Values.config.hosts }}
      {{ if $index }},{{ end }}
      {
        host = {{ $element.host | quote }}
        name = {{ $element.name | quote }}
      }
      {{- end }}
    ]
