{{- define "minio.configuration" -}}

  {{/* Validation */}}
  {{ include "minio.validation" $ }}

  {{ $config := fromJson (include "minio.prepare.config" $) }}

{{/* Secrets */}}
secret:
  minio-creds:
    enabled: true
    data:
      MINIO_ROOT_USER: {{ .Values.minioCreds.rootUser }}
      MINIO_ROOT_PASSWORD: {{ .Values.minioCreds.rootPass }}
      MINIO_VOLUMES: {{ $config.volumes }}
      {{ with .Values.minioNetwork.serverUrl }}
      MINIO_SERVER_URL: {{ . | quote }}
      {{ end }}
      {{ with .Values.minioNetwork.consoleUrl }}
      MINIO_BROWSER_REDIRECT_URL: {{ . | quote }}
      {{ end }}
      {{ if .Values.minioLogging.logsearch.enabled }}
      MINIO_AUDIT_WEBHOOK_ENABLE_ix_logsearch: "on"
      MINIO_AUDIT_WEBHOOK_ENDPOINT_ix_logsearch: {{ $config.webhookURL }}
      MINIO_LOG_QUERY_AUTH_TOKEN: {{ $config.queryToken }}
      MINIO_LOG_QUERY_URL: {{ $config.logQueryURL }}
      {{ end }}

  # Always create the logsearch and postgres secret, even if logsearch is disabled.
  # Because autogenerated passwords are stored in the secret, and disabling logsearch after
  # the secret is created will cause the passwords to be lost (if the secret is conditionally rendered).
  logsearch-creds:
    enabled: true
    data:
      LOGSEARCH_PG_CONN_STR: {{ $config.postgresURL }}
      LOGSEARCH_AUDIT_AUTH_TOKEN: {{ $config.auditToken }}
      MINIO_LOG_QUERY_AUTH_TOKEN: {{ $config.queryToken }}
      {{ if .Values.minioLogging.logsearch.enabled }}
      LOGSEARCH_DISK_CAPACITY_GB: {{ $config.diskCapacity | quote }}
      {{ end }}

  postgres-creds:
    enabled: true
    data:
      POSTGRES_PASSWORD: {{ $config.dbPass }}
      POSTGRES_USER: {{ $config.dbUser }}
      POSTGRES_DB: {{ $config.dbName }}
      POSTGRES_HOST: {{ $config.dbHost }}
      POSTGRES_URL: {{ $config.postgresURL }}

{{/* MinIO Certificate */}}
{{ if .Values.minioNetwork.certificateID }}
scaleCertificate:
  minio-cert:
    enabled: true
    labels: {}
    annotations: {}
    id: {{ .Values.minioNetwork.certificateID }}
{{ end }}

{{- end -}}
