# SPDX-FileCopyrightText: 2021-present Open Networking Foundation <info@opennetworking.org>
#
# SPDX-License-Identifier: Apache-2.0

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "aether-enterprise-portal.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
data:
  server-block.conf: |-
    server {
        listen {{.Values.Nginx.port}};
        ssl_certificate /usr/share/certs/aether-enterprise-portal.crt;
        ssl_certificate_key /usr/share/certs/aether-enterprise-portal.key;
        {{- if .Values.websocket.proxyEnabled }}
        location /ws {
            proxy_pass {{ .Values.websocket.protocol }}://{{ .Values.websocket.service }}:{{ .Values.websocket.port }}/ws;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_set_header Host $host;
        }{{end}}
        {{- if .Values.grafana.proxyEnabled }}
        location /grafana/ {
            proxy_pass {{ .Values.grafana.protocol }}://{{ .Values.grafana.service }}:{{ .Values.grafana.port }}/;
            proxy_http_version 1.1;
            proxy_redirect off;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;
            proxy_hide_header 'X-Frame-Options';
            add_header X-Frame-Options SAMEORIGIN;
        }{{end}}
        {{- if .Values.prometheus.proxyEnabled }}
        location /prometheus/ {
            proxy_pass {{ .Values.prometheus.protocol }}://{{ .Values.prometheus.service }}:{{ .Values.prometheus.port }}/;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            add_header X-Frame-Options SAMEORIGIN;
        }{{end}}
        location / {
          root /usr/share/nginx/html;
        }
        {{- range $key, $value := .Values.aetherservices }}
        location /{{ $key }}/ {
            proxy_pass {{ $value.protocol}}://{{$key}}:{{ $value.http }}/;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_connect_timeout       {{ $value.streamTimeout }};
            proxy_send_timeout          {{ $value.streamTimeout }};
            proxy_read_timeout          {{ $value.streamTimeout }};
            send_timeout                {{ $value.streamTimeout }};
        }
        {{ end }}
    }

