apiVersion: dodo.cloud.dodo.cloud/v1
kind: ResourceRenderer
metadata:
  name: config-renderer
  namespace: {{ .Release.Namespace }}
  annotations:
    helm.sh/hook: pre-install
    helm.sh/hook-weight: "-10"
spec:
  secretName: {{ .Values.oauth2.secretName }}
  resourceTemplate: |
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: {{ .Values.configMerge.configName }}
      namespace: {{ .Release.Namespace }}
    data:
      {{ .Values.configMerge.fileName }}: |
        public_baseurl: https://{{ .Values.subdomain }}.{{ .Values.domain }}/
        enable_registration: false
        database:
         name: psycopg2
         txn_limit: 10000
         args:
           host: {{ .Values.postgresql.host }}
           port: {{ .Values.postgresql.port }}
           database: {{ .Values.postgresql.database }}
           user: {{ .Values.postgresql.user }}
           password: {{ .Values.postgresql.password }}
           cp_min: 5
           cp_max: 10
        oidc_providers:
          - idp_id: pcloud
            idp_name: "PCloud"
            skip_verification: true
            issuer: {{ .Values.oauth2.issuer }}
            client_id: "{{`{{ .client_id }}`}}"
            client_secret: "{{`{{ .client_secret }}`}}"
            scopes: ["openid", "profile"]
            allow_existing_users: true
            user_mapping_provider:
              config:
                localpart_template: "{{ cat "{{" "\"" "{{user.username}}" "\"" "}}" | nospace}}"
                display_name_template: "{{ cat "{{" "\"" "{{user.username}}" "\"" "}}" | nospace}}"
