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

{{- if and .Values.tde.enabled ( .Values.tde.secretsStoreProvider.enabled ) }}
apiVersion: secrets-store.csi.x-k8s.io/v1
kind: SecretProviderClass
metadata:
  name: {{ include "mariadb.tde.secretProviderClassName" . | quote }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/part-of: mariadb
    app.kubernetes.io/component: mariadb
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
spec:
  provider: {{ .Values.tde.secretsStoreProvider.provider }}
  parameters:
    roleName: {{ .Values.tde.secretsStoreProvider.vault.roleName | quote }}
    {{- if .Values.tde.secretsStoreProvider.vault.address }}
    vaultAddress: {{ .Values.tde.secretsStoreProvider.vault.address | quote }}
    {{- end }}
    {{- if .Values.tde.secretsStoreProvider.vault.authMountPath }}
    vaultAuthMountPath: {{ .Values.tde.secretsStoreProvider.vault.authMountPath | quote }}
    {{- end }}
    objects: |
      - objectName: {{ .Values.tde.randomKeyFilename | quote }}
        secretPath: {{ .Values.tde.secretsStoreProvider.vault.randomKeySecretPath | quote }}
        secretKey: {{ .Values.tde.secretsStoreProvider.vault.randomKeySecretKey | quote }}
        encoding: "base64"
      - objectName: {{ .Values.tde.encryptedKeyFilename | quote }}
        secretPath: {{ .Values.tde.secretsStoreProvider.vault.encryptedKeySecretPath | quote }}
        secretKey: {{ .Values.tde.secretsStoreProvider.vault.encryptedKeySecretKey | quote }}
        encoding: "base64"
{{- end }}
