apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: central-dashboard
  labels:
    helm.sh/chart: {{ include "deploykf-dashboard.labels.chart" . }}
    app.kubernetes.io/name: {{ include "deploykf-dashboard.labels.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    app.kubernetes.io/component: central-dashboard
spec:
  gateways:
    - {{ .Values.deployKF.gateway.namespace }}/{{ .Values.deployKF.gateway.name }}
  hosts:
    - {{ .Values.deployKF.gateway.hostname | quote }}
  http:
    ## deny adding profile contributors
    - match:
        - ignoreUriCase: true
          uri:
            prefix: /api/workgroup/add-contributor
          method:
            exact: POST
      directResponse:
        status: 403
        body:
          string: |-
            { "error": "deployKF does not support adding profile contributors with the dashboard." }
      headers:
        response:
          set:
            content-type: application/json

    ## deny removing profile contributors
    - match:
        - ignoreUriCase: true
          uri:
            prefix: /api/workgroup/remove-contributor
          method:
            exact: DELETE
      directResponse:
        status: 403
        body:
          string: |-
            { "error": "deployKF does not support removing profile contributors with the dashboard." }
      headers:
        response:
          set:
            content-type: application/json

    ## deny creating profiles
    - match:
        - ignoreUriCase: true
          uri:
            prefix: /api/workgroup/create
          method:
            exact: POST
      directResponse:
        status: 403
        body:
          string: |-
            { "error": "deployKF does not support creating profiles with the dashboard." }
      headers:
        response:
          set:
            content-type: application/json

    ## deny deleting profiles
    - match:
        - ignoreUriCase: true
          uri:
            prefix: /api/workgroup/nuke-self
          method:
            exact: DELETE
      directResponse:
        status: 403
        body:
          string: |-
            { "error": "deployKF does not support deleting profiles with the dashboard." }
      headers:
        response:
          set:
            content-type: application/json

    ## route all other requests to the central-dashboard service
    - match:
        - uri:
            prefix: /
      route:
        - destination:
            host: central-dashboard.{{ .Release.Namespace }}.svc.{{ .Values.deployKF.clusterDomain }}
            port:
              number: 80