apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
  name: {{ $.Values.externalSecrets.trembitaRegistriesSecrets.name }}
spec:
  refreshInterval: {{ $.Values.externalSecrets.trembitaRegistriesSecrets.refreshInterval }}
  secretStoreRef:
    name: {{ $.Values.externalSecrets.trembitaRegistriesSecrets.secretStoreRef.name }}
    kind: SecretStore
  target:
    name: {{ $.Values.externalSecrets.trembitaRegistriesSecrets.target.name }}
  dataFrom:
  {{- if $.Values.trembita.registries -}}
  {{- range $k,$v := $.Values.trembita.registries }}
  {{- if $v.auth }}{{- if $v.auth.type }}
  {{- if ne $v.auth.type "NO_AUTH" }}
    - extract:
        {{- $vaultPath := split ":" $v.auth.secret }}
        key: {{ print $vaultPath._1 }}
  {{- end -}}
  {{- end }}{{- end -}}
  {{- end -}}
  {{- end -}}
