{{/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/}}

{{- if .Values.manifests.configmap_etc }}
{{- $envAll := . }}

{{- if empty .Values.conf.ceilometer.cache.memcache_servers -}}
{{- $_ := tuple "oslo_cache" "internal" "memcache" . | include "helm-toolkit.endpoints.host_and_port_endpoint_uri_lookup" | set .Values.conf.ceilometer.cache "memcache_servers" -}}
{{- end -}}

{{- if empty .Values.conf.ceilometer.DEFAULT.transport_url -}}
{{- $_ := tuple "oslo_messaging" "internal" "ceilometer" "amqp" . | include "helm-toolkit.endpoints.authenticated_transport_endpoint_uri_lookup" | set .Values.conf.ceilometer.DEFAULT "transport_url" -}}
{{- end -}}

{{- if empty .Values.conf.ceilometer.oslo_messaging_notifications.transport_url -}}
{{- $_ := tuple "oslo_messaging" "internal" "ceilometer" "amqp" . | include "helm-toolkit.endpoints.authenticated_transport_endpoint_uri_lookup" | set .Values.conf.ceilometer.oslo_messaging_notifications "transport_url" -}}
{{- end -}}

{{- if empty .Values.conf.ceilometer.notification.messaging_urls -}}
{{- $_ := tuple "oslo_messaging" "internal" "ceilometer" "amqp" . | include "helm-toolkit.endpoints.authenticated_transport_endpoint_uri_lookup" | set .Values.conf.ceilometer.notification "messaging_urls" -}}
{{- end -}}

{{- if empty .Values.conf.ceilometer.service_credentials.auth_url -}}
{{- $_ := tuple "identity" "internal" "api" . | include "helm-toolkit.endpoints.keystone_endpoint_uri_lookup"| set .Values.conf.ceilometer.service_credentials "auth_url" -}}
{{- end -}}
{{- if empty .Values.conf.ceilometer.service_credentials.region_name -}}
{{- $_ := set .Values.conf.ceilometer.service_credentials "region_name" .Values.endpoints.identity.auth.ceilometer.region_name -}}
{{- end -}}
{{- if empty .Values.conf.ceilometer.service_credentials.project_name -}}
{{- $_ := set .Values.conf.ceilometer.service_credentials "project_name" .Values.endpoints.identity.auth.ceilometer.project_name -}}
{{- end -}}
{{- if empty .Values.conf.ceilometer.service_credentials.project_domain_name -}}
{{- $_ := set .Values.conf.ceilometer.service_credentials "project_domain_name" .Values.endpoints.identity.auth.ceilometer.project_domain_name -}}
{{- end -}}
{{- if empty .Values.conf.ceilometer.service_credentials.user_domain_name -}}
{{- $_ := set .Values.conf.ceilometer.service_credentials "user_domain_name" .Values.endpoints.identity.auth.ceilometer.user_domain_name -}}
{{- end -}}
{{- if empty .Values.conf.ceilometer.service_credentials.username -}}
{{- $_ := set .Values.conf.ceilometer.service_credentials "username" .Values.endpoints.identity.auth.ceilometer.username -}}
{{- end -}}
{{- if empty .Values.conf.ceilometer.service_credentials.password -}}
{{- $_ := set .Values.conf.ceilometer.service_credentials "password" .Values.endpoints.identity.auth.ceilometer.password -}}
{{- end -}}

{{- if empty .Values.conf.ceilometer.dispatcher_gnocchi.url -}}
{{- $_ := tuple "metric" "internal" "api" . | include "helm-toolkit.endpoints.keystone_endpoint_uri_lookup"| set .Values.conf.ceilometer.dispatcher_gnocchi "url" -}}
{{- end -}}

---
apiVersion: v1
kind: Secret
metadata:
  name: ceilometer-etc
type: Opaque
data:
  rally_tests.yaml: {{ toYaml .Values.conf.rally_tests | b64enc }}
  ceilometer.conf: {{ include "helm-toolkit.utils.to_oslo_conf" .Values.conf.ceilometer | b64enc }}
  event_pipeline.yaml: {{ toYaml .Values.conf.event_pipeline | b64enc }}
  pipeline.yaml: {{ toYaml .Values.conf.pipeline | b64enc }}
  event_definitions.yaml: {{ toYaml .Values.conf.event_definitions | b64enc }}
  gnocchi_resources.yaml: {{ toYaml .Values.conf.gnocchi_resources | b64enc }}
  meters.yaml: {{ toYaml .Values.conf.meters | b64enc }}
  polling.yaml: {{ toYaml .Values.conf.polling | b64enc }}
{{- if .Values.conf.security }}
{{- include "helm-toolkit.snippets.values_template_renderer" (dict "envAll" $envAll "template" .Values.conf.security "key" "security.conf" "format" "Secret" ) | indent 2 }}
{{- end}}
{{ include "helm-toolkit.snippets.values_template_renderer" (dict "envAll" $envAll "template" .Values.conf.wsgi_ceilometer "key" "wsgi-ceilometer.conf" "format" "Secret" ) | indent 2 }}
{{- end }}
