apiVersion: v1
kind: Secret
metadata:
  name: {{ template "rocketchat.fullname" . }}
  labels:
    app.kubernetes.io/name: {{ include "rocketchat.name" . }}
    helm.sh/chart: {{ include "rocketchat.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
type: Opaque
data:
{{- if .Values.smtp.enabled }}
  mail-url: {{ printf "smtp://%s:%s@%s:%.0f" .Values.smtp.username .Values.smtp.password .Values.smtp.host .Values.smtp.port | b64enc | quote }}
{{- end }}
{{- if .Values.externalMongodbUrl }}
  mongo-uri: {{ .Values.externalMongodbUrl | b64enc | quote }}
  mongo-oplog-uri: {{ required "Please specify the external MongoDB OpLog URL" .Values.externalMongodbOplogUrl | b64enc | quote }}
{{- else }}
  {{- $fullname := include "rocketchat.mongodb.fullname" . -}}
  {{- $username := required "Please specify a MongoDB username" .Values.mongodb.mongodbUsername }}
  {{- $password := required "Please specify a MongoDB password" .Values.mongodb.mongodbPassword }}
  {{- $rootPassword := required "Please specify a MongoDB password" .Values.mongodb.mongodbRootPassword }}
  {{- $rsName := .Values.mongodb.replicaSet.name }}
  {{- $port := .Values.mongodb.service.port }}
  {{- $dbname := required "Please specify a MongoDB database" .Values.mongodb.mongodbDatabase }}
  mongo-uri: {{ printf "mongodb://%s:%s@%s:%.0f/%s" $username $password $fullname $port $dbname | b64enc | quote }}
  mongo-oplog-uri: {{ printf "mongodb://root:%s@%s:%.0f/local?replicaSet=%s&authSource=admin" $rootPassword $fullname $port $rsName | b64enc | quote }}
{{- end }}
