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

{{- if $.Values.snapshots.enabled -}}
apiVersion: v1
kind: ConfigMap
metadata:
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: snapshots
  name: {{ include "opensearch.snapshots.repoDataConfigMap" . }}
  namespace: {{ include "common.names.namespace" . | quote }}
data:
  {{- range $name, $repo := $.Values.snapshots.repositories }}
  {{- if (eq $repo.type "fs") -}}
    {{- $location := $repo.settings.location -}}
    {{- if not (eq $location $.Values.snapshotRepoPath) -}}
      {{- fail (printf "Location `%s` for repo `%s` must be allowed via .snapshotRepoPath" $location $name) -}}
    {{- end -}}
  {{- end -}}
  {{ $name | nindent 2 }}: |
    {{- $repo | mustToPrettyJson | nindent 4 }}
  {{- end -}}
{{- end -}}
