{{- $existingSecret := lookup "v1" "Secret" .Release.Namespace .Values.bucketName }}
{{- $bucketInfo := fromJson (b64dec (index $existingSecret.data "BucketInfo")) }}
{{- $accessKeyID := index $bucketInfo.spec.secretS3 "accessKeyID" }}
{{- $accessSecretKey := index $bucketInfo.spec.secretS3 "accessSecretKey" }}
{{- $endpoint := index $bucketInfo.spec.secretS3 "endpoint" }}

apiVersion: v1
kind: Secret
metadata:
  name: {{ .Values.bucketName }}-credentials
type: Opaque
stringData:
  accessKey: {{ $accessKeyID | quote }}
  secretKey: {{ $accessSecretKey | quote }}
  endpoint: {{ trimPrefix "https://" $endpoint }}
---
apiVersion: v1
kind: Secret
metadata:
  name: {{ .Values.bucketName }}-ui-auth
data:
  auth: {{ htpasswd $accessKeyID $accessSecretKey | b64enc | quote }}
