{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if not .Values.existingSecret }}
apiVersion: v1
kind: Secret
metadata:
  {{- $secretName := printf "%s-default" (include "common.names.fullname" .) }}
  name: {{ $secretName }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/part-of: mastodon
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
data:
  {{- if .Values.adminPassword }}
  MASTODON_ADMIN_PASSWORD: {{ .Values.adminPassword | b64enc | quote }}
  {{- end }}
  {{- if .Values.secretKeyBase }}
  SECRET_KEY_BASE: {{ .Values.secretKeyBase | b64enc | quote }}
  {{- end }}
  {{- if .Values.otpSecret }}
  OTP_SECRET: {{ .Values.otpSecret | b64enc | quote }}
  {{- end }}
  {{- if .Values.vapidPrivateKey }}
  VAPID_PRIVATE_KEY: {{ .Values.vapidPrivateKey | b64enc | quote }}
  {{- end }}
  {{- if .Values.vapidPublicKey }}
  VAPID_PUBLIC_KEY: {{ .Values.vapidPublicKey | b64enc | quote }}
  {{- end }}
  {{- if .Values.smtp.server }}
  SMTP_SERVER: {{ .Values.smtp.server | b64enc | quote }}
  {{- end }}
  ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY: {{ include "common.secrets.passwords.manage" (dict "secret" $secretName "key" "controller-password" "providedValues" (list "activeRecordEncryptionDeterministicKey") "failOnNew" false "context" $) }}
  ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT: {{ include "common.secrets.passwords.manage" (dict "secret" $secretName "key" "controller-password" "providedValues" (list "activeRecordEncryptionKeyDerivationSalt") "failOnNew" false "context" $) }}
  ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY: {{ include "common.secrets.passwords.manage" (dict "secret" $secretName "key" "controller-password" "providedValues" (list "activeRecordEncryptionPrimaryKey") "failOnNew" false "context" $) }}
  {{- if not (include "mastodon.elasticsearch.auth.enabled" .) }}
  # HACK: Even though Elasticsearch has authentication disabled. The rake chewy command always requires a password
  MASTODON_ELASTICSEARCH_PASSWORD: {{ print "value_not_used" | b64enc | quote }}
  {{- end }}
{{- end }}
