{{- if and .Values.redis.enabled .Values.redis.auth.createSecret -}}
{{- $redisPassword := coalesce .Values.redis.password (randAlphaNum 32 | b64enc) }}
{{- $databrokerSecretData := (lookup "v1" "Secret" .Release.Namespace (include "pomerium.databroker.storage.secret" .) ).data }}
{{- if and $databrokerSecretData (not .Values.config.forceGenerateServiceSecrets) }}
{{- $redisPassword = (index $databrokerSecretData "password" | b64dec) }}
{{- end }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "pomerium.databroker.storage.secret" . }}
  labels:
    app.kubernetes.io/name: {{ template "pomerium.name" . }}
    helm.sh/chart: {{ template "pomerium.chart" . }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    app.kubernetes.io/instance: {{ .Release.Name }}
type: Opaque
data:
  password: {{ $redisPassword | b64enc }}
  DATABROKER_STORAGE_CONNECTION_STRING: {{ default (printf "%s://:%s@%s-master.%s.svc.cluster.local:6379" (include "pomerium.redis.scheme" . ) ($redisPassword) (include "pomerium.redis.name" . ) .Release.Namespace ) .Values.databroker.storage.connectionString | b64enc}}
{{- end -}}
