apiVersion: v1
kind: ConfigMap
metadata:
  name: bitwardenconfig
  labels:
  {{- include "common.labels" . | nindent 4 }}
data:
  ROCKET_PORT: "8080"
  SIGNUPS_ALLOWED: {{ .Values.bitwardenrs.allowSignups | quote }}
  {{- if .Values.bitwardenrs.signupDomains }}
  SIGNUPS_DOMAINS_WHITELIST: {{ join "," .Values.bitwardenrs.signupDomains | quote }}
  {{- end }}
  {{- if and (eq .Values.bitwardenrs.verifySignup true) (eq .Values.bitwardenrs.smtp.enabled false) }}{{ required "Signup verification requires SMTP to be enabled" nil}}{{end}}
  SIGNUPS_VERIFY: {{ .Values.bitwardenrs.verifySignup | quote }}
  {{- if and (eq .Values.bitwardenrs.requireEmail true) (eq .Values.bitwardenrs.smtp.enabled false) }}{{ required "Requiring emails for login depends on SMTP" nil}}{{end}}
  REQUIRE_DEVICE_EMAIL: {{ .Values.bitwardenrs.requireEmail | quote }}
  {{- if .Values.bitwardenrs.emailAttempts }}
  EMAIL_ATTEMPTS_LIMIT: {{ .Values.bitwardenrs.emailAttempts | quote }}
  {{- end }}
  {{- if .Values.bitwardenrs.emailTokenExpiration }}
  EMAIL_EXPIRATION_TIME: {{ .Values.bitwardenrs.emailTokenExpiration | quote }}
  {{- end }}
  INVITATIONS_ALLOWED: {{ .Values.bitwardenrs.allowInvitation | quote }}
  {{- if .Values.bitwardenrs.defaultInviteName }}
  INVITATION_ORG_NAME: {{ .Values.bitwardenrs.defaultInviteName | quote }}
  {{- end }}
  SHOW_PASSWORD_HINT: {{ .Values.bitwardenrs.showPasswordHint | quote }}
  WEBSOCKET_ENABLED: {{ .Values.bitwardenrs.enableWebsockets | quote }}
  WEB_VAULT_ENABLED: {{ .Values.bitwardenrs.enableWebVault | quote }}
  ORG_CREATION_USERS: {{ .Values.bitwardenrs.orgCreationUsers | quote }}
  {{- if .Values.bitwardenrs.attachmentLimitOrg }}
  ORG_ATTACHMENT_LIMIT: {{ .Values.bitwardenrs.attachmentLimitOrg | quote }}
  {{- end }}
  {{- if .Values.bitwardenrs.attachmentLimitUser }}
  USER_ATTACHMENT_LIMIT: {{ .Values.bitwardenrs.attachmentLimitUser | quote }}
  {{- end }}
  {{- if .Values.bitwardenrs.hibpApiKey }}
  HIBP_API_KEY: {{ .Values.bitwardenrs.hibpApiKey | quote }}
  {{- end }}
  {{- include "bitwardenrs.dbTypeValid" . }}
  {{- if .Values.database.retries }}
  DB_CONNECTION_RETRIES: {{ .Values.database.retries | quote }}
  {{- end }}
  {{- if .Values.database.maxConnections }}
  DATABASE_MAX_CONNS: {{ .Values.database.maxConnections | quote }}
  {{- end }}
  {{- if eq .Values.bitwardenrs.smtp.enabled true }}
  SMTP_HOST: {{ required "SMTP host is required to enable SMTP" .Values.bitwardenrs.smtp.host | quote }}
  SMTP_FROM: {{ required "SMTP sender address ('from') is required to enable SMTP" .Values.bitwardenrs.smtp.from | quote }}
  {{- if .Values.bitwardenrs.smtp.fromName }}
  SMTP_FROM_NAME: {{ .Values.bitwardenrs.smtp.fromName | quote }}
  {{- end }}
  {{- if .Values.bitwardenrs.smtp.ssl }}
  SMTP_SSL: {{ .Values.bitwardenrs.smtp.ssl | quote }}
  {{- end }}
  {{- if .Values.bitwardenrs.smtp.port }}
  SMTP_PORT: {{ .Values.bitwardenrs.smtp.port | quote }}
  {{- end }}
  {{- if .Values.bitwardenrs.smtp.authMechanism }}
  SMTP_AUTH_MECHANISM: {{ .Values.bitwardenrs.smtp.authMechanism | quote }}
  {{- end }}
  {{- if .Values.bitwardenrs.smtp.heloName }}
  HELO_NAME: {{ .Values.bitwardenrs.smtp.heloName | quote }}
  {{- end }}
  {{- if .Values.bitwardenrs.smtp.timeout }}
  SMTP_TIMEOUT: {{ .Values.bitwardenrs.smtp.timeout | quote }}
  {{- end }}
  {{- if .Values.bitwardenrs.smtp.invalidHostname }}
  SMTP_ACCEPT_INVALID_HOSTNAMES: {{ .Values.bitwardenrs.smtp.invalidHostname | quote }}
  {{- end }}
  {{- if .Values.bitwardenrs.smtp.invalidCertificate }}
  SMTP_ACCEPT_INVALID_CERTS: {{ .Values.bitwardenrs.smtp.invalidCertificate | quote }}
  {{- end }}
  {{- end }}
  {{- if .Values.bitwardenrs.log.file }}
  LOG_FILE: {{ .Values.bitwardenrs.log.file | quote }}
  {{- end }}
  {{- if or .Values.bitwardenrs.log.level .Values.bitwardenrs.log.timeFormat }}
  EXTENDED_LOGGING: "true"
  {{- end }}
  {{- if .Values.bitwardenrs.log.level }}
  {{- include "bitwardenrs.logLevelValid" . }}
  LOG_LEVEL: {{ .Values.bitwardenrs.log.level | quote }}
  {{- end }}
  {{- if .Values.bitwardenrs.log.timeFormat }}
  LOG_TIMESTAMP_FORMAT: {{ .Values.bitwardenrs.log.timeFormat | quote }}
  {{- end }}
  {{- if .Values.bitwardenrs.icons.disableDownload }}
  DISABLE_ICON_DOWNLOAD: {{ .Values.bitwardenrs.icons.disableDownload | quote }}
  {{- if and (not .Values.bitwardenrs.icons.cache) (eq .Values.bitwardenrs.icons.disableDownload "true") }}
  ICON_CACHE_TTL: "0"
  {{- end }}
  {{- end }}
  {{- if .Values.bitwardenrs.icons.cache }}
  ICON_CACHE_TTL: {{ .Values.bitwardenrs.icons.cache | quote }}
  {{- end }}
  {{- if .Values.bitwardenrs.icons.cacheFailed }}
  ICON_CACHE_NEGTTL: {{ .Values.bitwardenrs.icons.cacheFailed | quote }}
  {{- end }}
  {{- if eq .Values.bitwardenrs.admin.enabled true }}
  {{- if eq .Values.bitwardenrs.admin.disableAdminToken true }}
  DISABLE_ADMIN_TOKEN: "true"
  {{- end }}
  {{- end }}
  {{- if eq .Values.bitwardenrs.yubico.enabled true }}
  {{- if .Values.bitwardenrs.yubico.server }}
  YUBICO_SERVER: {{ .Values.bitwardenrs.yubico.server | quote }}
  {{- end }}
  {{- end }}
  {{- if eq .Values.database.type "sqlite" }}
  ENABLE_DB_WAL: {{ .Values.database.wal | quote }}
  {{- else }}
  ENABLE_DB_WAL: "false"
  {{- end }}
