---
apiVersion: v1
kind: Secret
metadata:
  name: backend-auth
  namespace: {{ .Release.Namespace }}

type: Opaque
stringData:
  PASSWORD_SECRET: "{{ .Values.backend_password_secret }}"

  EMAIL_SMTP_PORT: "{{ .Values.email.smtp_port }}"
  EMAIL_SMTP_HOST: "{{ .Values.email.smtp_host }}"
  EMAIL_SENDER: "{{ .Values.email.sender_email }}"
  EMAIL_REPLY_TO: "{{ .Values.email.reply_to }}"
  EMAIL_PASSWORD: "{{ .Values.email.password }}"
  EMAIL_SMTP_USE_TLS: "{{ .Values.email.use_tls }}"
  EMAIL_SUPPORT: "{{ .Values.email.support_email }}"

  SUPERUSER_EMAIL: "{{ .Values.superuser.email }}"
  SUPERUSER_PASSWORD: "{{ .Values.superuser.password }}"


---
apiVersion: v1
kind: Secret
metadata:
  name: ops-configs
  namespace: {{ .Release.Namespace }}

type: Opaque
data:
  storages.json: {{ .Values.storages | toJson | b64enc | quote }}
  crawler_channels.json: {{ .Values.crawler_channels | toJson | b64enc | quote }}


{{- range $storage := .Values.storages }}
---
apiVersion: v1
kind: Secret
metadata:
  name: storage-{{ $storage.name }}
  namespace: {{ $.Values.crawler_namespace }}

type: Opaque
stringData:
  TYPE: "s3"
  STORE_ACCESS_KEY: "{{ $storage.access_key }}"
  STORE_SECRET_KEY: "{{ $storage.secret_key }}"

  {{- if $storage.bucket_name }}
  STORE_ENDPOINT_URL: "{{ $storage.endpoint_url }}{{ $storage.bucket_name }}/"
  {{- else }}
  STORE_ENDPOINT_URL: "{{ $storage.endpoint_url }}"
  {{- end }}
  STORE_ENDPOINT_NO_BUCKET_URL: "{{ $storage.endpoint_url }}"

  STORE_REGION: "{{ $storage.region }}"

  STORE_S3_PROVIDER: {{ $storage.s3_provider | default "Other" }}

{{- end }}
