{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if (include "external-dns.createSecret" .) }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ template "common.names.fullname" . }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
  {{- if or .Values.secretAnnotations .Values.commonAnnotations }}
  {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.secretAnnotations .Values.commonAnnotations ) "context" . ) }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
  {{- end }}
type: Opaque
data:
  {{- if eq .Values.provider "akamai" }}
  akamai_client_secret: {{ .Values.akamai.clientSecret | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "alibabacloud" }}
  alibaba-cloud.json: {{ include "external-dns.alibabacloud-credentials" . | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "aws" }}
  credentials: {{ include "external-dns.aws-credentials" . | b64enc | quote }}
  {{- if .Values.aws.region }}
  config: {{ include "external-dns.aws-config" . | b64enc | quote }}
  {{- end }}
  {{- end }}
  {{- if or (eq .Values.provider "azure") (eq .Values.provider "azure-private-dns") }}
  azure.json: {{ include "external-dns.azure-credentials" . | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "google" }}
  credentials.json: {{ .Values.google.serviceAccountKey | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "civo" }}
  apiToken: {{ .Values.civo.apiToken | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "cloudflare" }}
  {{- if .Values.cloudflare.apiToken }}
  cloudflare_api_token: {{ .Values.cloudflare.apiToken | b64enc | quote }}
  {{- else }}
  cloudflare_api_key: {{ required "cloudflare.apiKey is required if cloudflare.apiToken is not provided" .Values.cloudflare.apiKey | b64enc | quote }}
  {{- end }}
  {{- end }}
  {{- if eq .Values.provider "digitalocean" }}
  digitalocean_api_token: {{ .Values.digitalocean.apiToken | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "exoscale" }}
  exoscale_api_key: {{ .Values.exoscale.apiKey | b64enc | quote }}
  exoscale_api_token: {{ .Values.exoscale.apiToken | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "linode" }}
  linode_api_token: {{ .Values.linode.apiToken | b64enc | quote }}
  {{- end }}
  {{- if and (eq .Values.provider "oci") (not .Values.useInstancePrincipal) }}
  oci.yaml: {{ include "external-dns.oci-credentials" . | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "pdns" }}
  pdns_api_key: {{ .Values.pdns.apiKey | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "rfc2136" }}
  rfc2136_tsig_secret: {{ .Values.rfc2136.tsigSecret | b64enc | quote }}
  rfc2136_kerberos_username: {{ .Values.rfc2136.kerberosUsername | b64enc | quote }}
  rfc2136_kerberos_password: {{ .Values.rfc2136.kerberosPassword | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "transip" }}
  transip-api-key: {{ .Values.transip.apiKey | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "ovh" }}
  ovh_consumer_key: {{ .Values.ovh.consumerKey | b64enc | quote }}
  ovh_application_key: {{ .Values.ovh.applicationKey | b64enc | quote }}
  ovh_application_secret: {{ .Values.ovh.applicationSecret | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "scaleway" }}
  scw_access_key: {{ .Values.scaleway.scwAccessKey | b64enc | quote }}
  scw_secret_key: {{ .Values.scaleway.scwSecretKey | b64enc | quote }}
  {{- end }}
  {{- if eq .Values.provider "ns1" }}
  ns1-api-key: {{ .Values.ns1.apiKey | b64enc | quote }}
  {{- end }}
  {{- if .Values.pihole.password }}
  pihole_password: {{ .Values.pihole.password | b64enc | quote }}
  {{- end }}
  {{- if .Values.txtEncrypt.enabled }}
  txt_aes_encryption_key: {{ .Values.txtEncrypt.aesKey | default (randAlphaNum 32 | replace "+" "-" | replace "/" "_") | b64enc | quote }}
  {{- end }}
{{- end }}
