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

{{- if and (include "opensearch.dashboards.enabled" .) (include "opensearch.dashboards.createTlsSecret" .) }}
{{- $ca := genCA "opensearch-ca" 365 }}
{{- $releaseNamespace := include "common.names.namespace" . }}
{{- $clusterDomain := .Values.clusterDomain }}
{{- $dashboardsFullname := include "opensearch.dashboards.fullname" . }}
{{- $cert := genSignedCert $dashboardsFullname nil nil 365 $ca }}
{{- $secretDashboardsName := printf "%s-crt" (include "opensearch.dashboards.fullname" .) }}
---
apiVersion: v1
kind: Secret
metadata:
  name: {{ $secretDashboardsName }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
    {{- end }}
type: Opaque
data:
  tls.crt: {{ include "common.secrets.lookup" (dict "secret" $secretDashboardsName "key" "tls.crt" "defaultValue" $cert.Cert "context" $) }}
  tls.key: {{ include "common.secrets.lookup" (dict "secret" $secretDashboardsName "key" "tls.key" "defaultValue" $cert.Key "context" $) }}
  ca.crt: {{ include "common.secrets.lookup" (dict "secret" $secretDashboardsName "key" "ca.crt" "defaultValue" $ca.Cert "context" $) }}
{{- end }}
