{{ if .Values.logsearchapi.enabled }}
{{ $logSearchValues := (. | mustDeepCopy) }}
{{ $_ := set $logSearchValues "common" (dict "nameSuffix" (include "logsearchapi.nameSuffix" .)) }}

{{ $auditToken := randAlphaNum 32 | b64enc }}
{{ $queryToken := randAlphaNum 32 | b64enc }}

apiVersion: v1
kind: Secret
metadata:
  name: {{ include "logsearchapi.secretName" . }}
data:
  {{ with (lookup "v1" "Secret" .Release.Namespace (include "logsearchapi.secretName" .)) }}
  {{ $auditToken = (index .data "auditToken") }}
  {{ end }}
  auditToken: {{ $auditToken }}

  {{ with (lookup "v1" "Secret" .Release.Namespace (include "logsearchapi.secretName" .)) }}
  {{ $queryToken = (index .data "queryToken") }}
  {{ end }}
  queryToken: {{ $queryToken }}

  logQueryURL: {{ (printf "http://%v:8080" (include "common.names.fullname" $logSearchValues)) | b64enc }}
  webhookURL: {{ (printf "http://%v:8080/api/ingest?token=%v" (include "common.names.fullname" $logSearchValues) ($auditToken | b64dec)) | b64enc }}
{{ end }}
