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

{{- if (include "thanos.createHttpConfigSecret" .) }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "common.names.fullname" . }}-http-config-secret
  namespace: {{ include "common.names.namespace" . }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
stringData:
  http-config.yml: |-
{{- if .Values.httpConfig }}
    {{- include "common.tplvalues.render" (dict "value" .Values.httpConfig "context" $) | nindent 4 }}
{{- else }}
    {{- if .Values.https.enabled }}
    tls_server_config:
      cert_file: /certs/{{ .Values.https.certFilename }}
      key_file: /certs/{{ .Values.https.keyFilename }}
      {{- if .Values.https.clientAuthType }}
      client_auth_type: {{ .Values.https.clientAuthType }}
      # CA certificate for client certificate authentication to the server.
      client_ca_file: /certs/{{ .Values.https.caFilename }}
      {{- end }}
      {{- if .Values.https.extraTlsServerConfig }}
      {{- include "common.tplvalues.render" (dict "value" .Values.https.extraTlsServerConfig "context" $) | nindent 6 }}
      {{- end }}
    {{- end }}
    {{- if .Values.auth.basicAuthUsers }}
    basic_auth_users:
      {{- range $user, $password := .Values.auth.basicAuthUsers }}
      {{ $user }}: {{ (split ":" (htpasswd $user $password))._1 }}
      {{- end }}
    {{- end }}
{{- end }}
{{- end }}
