{{- $enabled := eq (include "osdu-developer-service.isEnabled" .) "1" -}}
{{- $namespace := .Release.Namespace }}
{{- $subset := .Values.subset}}
{{- range .Values.configuration }}
{{- if and $enabled .service .hosts .gateways }}
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: {{ .service }}
spec:
  hosts: {{ toYaml .hosts | nindent 4 }}
  gateways: {{ toYaml .gateways | nindent 4 }}
  http:
    - match:
        - uri:
            prefix: {{ .path }}
      route:
        - destination:
            host: {{ .service }}.{{ $namespace }}.svc.cluster.local
            subset: {{ $subset }}
      {{- if .cors }}
      corsPolicy:
        allowCredentials: true
        allowHeaders:
        - Authorization
        - Content-Type
        allowMethods:
        - GET
        - PUT
        - POST
        - DELETE
        - OPTIONS
        allowOrigins:
        {{- range .cors }}
        - exact: {{ . }}
        {{- end }}
        maxAge: 24h
      {{- end }}
{{- end }}
{{- end }}