{{- if and .Values.auth.enabled (not .Values.auth.existingSecret) }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "gohoarder.fullname" . }}-auth
  labels:
    {{- include "gohoarder.labels" . | nindent 4 }}
type: Opaque
data:
  {{- if .Values.auth.adminApiKey }}
  {{ .Values.auth.secretKey }}: {{ .Values.auth.adminApiKey | b64enc | quote }}
  {{- else }}
  {{ .Values.auth.secretKey }}: {{ include "gohoarder.adminApiKey" . | b64enc | quote }}
  {{- end }}
{{- end }}
---
{{- if and (eq .Values.storage.backend "s3") (not .Values.storage.s3.existingSecret) .Values.storage.s3.accessKeyId }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "gohoarder.fullname" . }}-s3
  labels:
    {{- include "gohoarder.labels" . | nindent 4 }}
type: Opaque
data:
  access-key-id: {{ .Values.storage.s3.accessKeyId | b64enc | quote }}
  secret-access-key: {{ .Values.storage.s3.secretAccessKey | b64enc | quote }}
{{- end }}
---
{{- if and (eq .Values.storage.backend "smb") (not .Values.storage.smb.existingSecret) .Values.storage.smb.username }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "gohoarder.fullname" . }}-smb
  labels:
    {{- include "gohoarder.labels" . | nindent 4 }}
type: Opaque
data:
  username: {{ .Values.storage.smb.username | b64enc | quote }}
  password: {{ .Values.storage.smb.password | b64enc | quote }}
{{- end }}
---
{{- if and (eq .Values.metadata.backend "postgresql") (not .Values.metadata.postgresql.existingSecret) .Values.metadata.postgresql.username }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "gohoarder.fullname" . }}-postgresql
  labels:
    {{- include "gohoarder.labels" . | nindent 4 }}
type: Opaque
data:
  username: {{ .Values.metadata.postgresql.username | b64enc | quote }}
  password: {{ .Values.metadata.postgresql.password | b64enc | quote }}
{{- end }}
---
{{- if and (or (eq .Values.metadata.backend "mysql") (eq .Values.metadata.backend "mariadb")) (not .Values.metadata.mysql.existingSecret) .Values.metadata.mysql.username }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "gohoarder.fullname" . }}-mysql
  labels:
    {{- include "gohoarder.labels" . | nindent 4 }}
type: Opaque
data:
  username: {{ .Values.metadata.mysql.username | b64enc | quote }}
  password: {{ .Values.metadata.mysql.password | b64enc | quote }}
{{- end }}
---
{{- if and .Values.security.scanners.ghsa.enabled (not .Values.security.scanners.ghsa.existingSecret) .Values.security.scanners.ghsa.token }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "gohoarder.fullname" . }}-ghsa
  labels:
    {{- include "gohoarder.labels" . | nindent 4 }}
type: Opaque
data:
  token: {{ .Values.security.scanners.ghsa.token | b64enc | quote }}
{{- end }}
