{{- if (include "thanos.createHttpConfigSecret" .) }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "common.names.fullname" . }}-http-config-secret
  namespace: {{ .Release.Namespace | quote }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
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 }}
    {{- end }}
    {{- if .Values.auth.basicAuthUsers }}
    basic_auth_users:
      {{- range $user, $password := .Values.auth.basicAuthUsers }}
      {{ $user }}: {{ (split ":" (htpasswd $user $password))._1 }}
      {{- end }}
    {{- end }}
{{- end }}
{{- end }}
