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

{{- if not .Values.registry.existingSecret }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "harbor.registry" . }}
  namespace: {{ include "common.names.namespace" . | quote }}
  {{- $versionLabel := dict "app.kubernetes.io/version" ( include "common.images.version" ( dict "imageRoot" .Values.registry.server.image "chart" .Chart ) ) }}
  {{- $labels := include "common.tplvalues.merge" ( dict "values" ( list .Values.commonLabels $versionLabel ) "context" . ) }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" $labels "context" $ ) | nindent 4 }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
type: Opaque
data:
  REGISTRY_HTPASSWD: {{ .Values.registry.credentials.htpasswd | b64enc | quote }}
  REGISTRY_HTTP_SECRET: {{ include "common.secrets.passwords.manage" (dict "secret" (include "harbor.registry" .) "key" "REGISTRY_HTTP_SECRET" "length" 16 "providedValues" (list "registry.secret") "context" $) }}
  REGISTRY_REDIS_PASSWORD: {{ (include "harbor.redis.rawPassword" ( dict "context" . "component" "registry" ) ) | b64enc | quote }}
  {{- if eq .Values.persistence.imageChartStorage.type "azure" }}
  REGISTRY_STORAGE_AZURE_ACCOUNTKEY: {{ .Values.persistence.imageChartStorage.azure.accountkey | b64enc | quote }}
  {{- else if eq .Values.persistence.imageChartStorage.type "gcs" }}
  {{- if .Values.persistence.imageChartStorage.gcs.encodedkey }}
  GCS_KEY_DATA: {{ .Values.persistence.imageChartStorage.gcs.encodedkey | quote }}
  {{- end }}
  {{- else if eq .Values.persistence.imageChartStorage.type "s3" }}
  {{- if .Values.persistence.imageChartStorage.s3.accesskey }}
  REGISTRY_STORAGE_S3_ACCESSKEY: {{ .Values.persistence.imageChartStorage.s3.accesskey | b64enc | quote }}
  {{- end }}
  {{- if .Values.persistence.imageChartStorage.s3.secretkey }}
  REGISTRY_STORAGE_S3_SECRETKEY: {{ .Values.persistence.imageChartStorage.s3.secretkey | b64enc | quote }}
  {{- end }}
  {{- else if eq .Values.persistence.imageChartStorage.type "swift" }}
  REGISTRY_STORAGE_SWIFT_PASSWORD: {{ .Values.persistence.imageChartStorage.swift.password | b64enc | quote }}
  {{- if .Values.persistence.imageChartStorage.swift.secretkey }}
  REGISTRY_STORAGE_SWIFT_SECRETKEY: {{ .Values.persistence.imageChartStorage.swift.secretkey | b64enc | quote }}
  {{- end }}
  {{- if .Values.persistence.imageChartStorage.swift.accesskey }}
  REGISTRY_STORAGE_SWIFT_ACCESSKEY: {{ .Values.persistence.imageChartStorage.swift.accesskey | b64enc | quote }}
  {{- end }}
  {{- else if eq .Values.persistence.imageChartStorage.type "oss" }}
  REGISTRY_STORAGE_OSS_ACCESSKEYSECRET: {{ .Values.persistence.imageChartStorage.oss.accesskeysecret | b64enc | quote }}
  {{- end }}
{{- end }}
