{{- include "common.values.setup" . -}}
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "common.names.fullname" . }}-config
  labels:
  {{- include "common.labels" . | nindent 4 }}
data:
  conf.php: |
    ;<?php http_response_code(403); /*
    ; config file for PrivateBin
    ;
    ; An explanation of each setting can be find online at https://github.com/PrivateBin/PrivateBin/wiki/Configuration.

    [main]
    {{ if eq .Values.ingress.main.enabled true }}
    basepath = "{{ (index (index .Values.ingress.main.hosts 0).paths 0).path }}"
    {{ end }}

    {{- range $key, $val := .Values.config.main }}
    {{ $key }}= {{ $val | toJson }}
    {{- end }}

    [expire]
    {{- range $key, $val := .Values.config.expire }}
    {{ $key }}= {{ $val | toJson }}
    {{- end }}

    [expire_options]
    {{- range $key, $val := .Values.config.expire_options }}
    {{ $key }}= {{ $val | toJson }}
    {{- end }}

    [formatter_options]
    {{- range $key, $val := .Values.config.formatter_options }}
    {{ $key }}= {{ $val | toJson }}
    {{- end }}

    [traffic]
    {{- range $key, $val := .Values.config.traffic }}
    {{ $key }}= {{ $val | toJson }}
    {{- end }}
    header = "X_FORWARDED_FOR"

    [purge]
    ; minimum time limit between two purgings of expired pastes, it is only
    ; triggered when pastes are created
    ; Set this to 0 to run a purge every time a paste is created.
    limit = 300

    ; maximum amount of expired pastes to delete in one purge
    ; Set this to 0 to disable purging. Set it higher, if you are running a large
    ; site
    batchsize = 10

    {{- if and (eq .Values.persistence.data.enabled true) (eq .Values.postgresql.enabled true) }}
    [model]
    class = Filesystem

    [model_options]
    dir = {{ .Values.persistence.data.mountPath }}

    [model]
    class = Database

    [model_options]
    dsn = "pgsql:host={{ .Release.Name }}-postgresql;dbname={{ .Values.postgresql.postgresqlDatabase }}"
    tbl = "privatebin_"
    usr = "{{ .Values.postgresql.postgresqlUsername }}"
    pwd = "{{ .Values.postgresql.postgresqlPassword }}"
    opt[12] = true
    {{- else if and (eq .Values.persistence.data.enabled true) (eq .Values.postgresql.enabled false) }}
    [model]
    class = Filesystem

    [model_options]
    dir = {{ .Values.persistence.data.mountPath }}
    {{ end }}
