apiVersion: v1
kind: ConfigMap
metadata:
  name: api-gateway-ntrada-config
  labels:
    app: api-gateway-service
data:
  ntrada-async.kube.yml: |
    auth:
      enabled: true
      global: false
      claims:
        role: http://schemas.microsoft.com/ws/2008/06/identity/claims/role
        
    http:
      retries: 3
      interval: 2.0
      exponential: true
      
    useForwardedHeaders: true
    passQueryString: true
    forwardRequestHeaders: true
    forwardResponseHeaders: true
    generateRequestId: true
    generateTraceId: true
    useLocalUrl: false
    
    loadBalancer:
      enabled: false
      url: localhost:9999
      
    extensions:
      customErrors:
        includeExceptionMessage: true
      cors:
        allowCredentials: true
        allowedOrigins:
          - '*'
        allowedMethods:
          - post
          - put
          - delete
        allowedHeaders:
          - '*'
        exposedHeaders:
          - Request-ID
          - Resource-ID
          - Trace-ID
          - Total-Count
          
      jwt:
        issuerSigningKey: eiquief5phee9pazo0Faegaez9gohThailiur5woy2befiech1oarai4aiLi6ahVecah3ie9Aiz6Peij
        validIssuer: pacco
        validateAudience: false
        validateIssuer: true
        validateLifetime: true
      swagger:
        name: Pacco
        reDocEnabled: false
        title: Pacco API
        version: v1
        routePrefix: docs
        includeSecurity: true
        
      rabbitmq:
        enabled: true
        connectionName: api-gateway
        hostnames:
          - rabbitmq-rabbitmq-ha
        port: 5672
        virtualHost: /
        username: guest
        password: guest
        requestedConnectionTimeout: 10000
        socketReadTimeout: 10000
        socketWriteTimeout: 10000
        requestedHeartbeat: 60
        exchange:
          declareExchange: true
          durable: true
          autoDelete: false
          type: topic
        messageContext:
          enabled: true
          header: message_context
        logger:
          enabled: true
        spanContextHeader: span_context
        
      tracing:
        serviceName: api-gateway
        udpHost: jaeger-tracing-agent
        udpPort: 6831
        maxPacketSize: 0
        sampler: const
        useEmptyTracer: false
        
    modules:
      home:
        routes:
          - upstream: /
            method: GET
            use: return_value
            returnValue: Welcome to Pacco API [async]!
            
            
      availability:
        path: availability
        routes:
          - upstream: /resources
            method: GET
            use: downstream
            downstream: availability-service/resources
            auth: true
            
          - upstream: /resources/{resourceId}
            method: GET
            use: downstream
            downstream: availability-service/resources/{resourceId}
            auth: true
        
          - upstream: /resources
            method: POST
            auth: true
            use: rabbitmq
            config:
              exchange: availability
              routing_key: add_resource
        
          - upstream: /resources/{resourceId}/reservations/{dateTime}
            method: POST
            auth: true
            use: rabbitmq
            config:
              exchange: availability
              routing_key: reserve_resource
            bind:
              - resourceId:{resourceId}
              - customerId:@user_id
              - dateTime:{dateTime}
        
          - upstream: /resources/{resourceId}/reservations/{dateTime}
            method: DELETE
            auth: true
            use: rabbitmq
            config:
              exchange: availability
              routing_key: release_resource
            bind:
              - resourceId:{resourceId}
              - dateTime:{dateTime}
        
          - upstream: /resources/{resourceId}
            method: DELETE
            auth: true
            use: rabbitmq
            config:
              exchange: availability
              routing_key: delete_resource
            bind:
              - resourceId:{resourceId}
              
        services:
          availability-service:
            localUrl: localhost:5001
            url: availability-service
            
            
      customers:
        path: customers
        routes:
          - upstream: /
            method: GET
            use: downstream
            downstream: customers-service/customers
            auth: true
            claims:
              role: admin
        
          - upstream: /me
            method: GET
            use: downstream
            downstream: customers-service/customers/@user_id
            auth: true
        
          - upstream: /{customerId}
            method: GET
            use: downstream
            downstream: customers-service/customers/{customerId}
            auth: true
            claims:
              role: admin
        
          - upstream: /{customerId}/state
            method: GET
            use: downstream
            downstream: customers-service/customers/{customerId}/state
            auth: true
            claims:
              role: admin
        
          - upstream: /
            method: POST
            auth: true
            use: rabbitmq
            config:
              exchange: customers
              routing_key: complete_customer_registration
            bind:
              - customerId:@user_id
            payload: complete_customer_registration
            schema: complete_customer_registration.schema
        
          - upstream: /{customerId}/state/{state}
            method: PUT
            auth: true
            use: rabbitmq
            config:
              exchange: customers
              routing_key: change_customer_state
            bind:
              - customerId:{customerId}
              - state:{state}
            claims:
              role: admin
              
        services:
          customers-service:
            localUrl: localhost:5002
            url: customers-service
            
            
      deliveries:
        path: deliveries
        routes:
          - upstream: /{deliveryId}
            method: GET
            use: downstream
            downstream: deliveries-service/deliveries/{deliveryId}
            auth: true
        
          - upstream: /
            method: POST
            auth: true
            resourceId:
              property: deliveryId
              generate: true
            use: rabbitmq
            config:
              exchange: deliveries
              routing_key: start_delivery
        
          - upstream: /{deliveryId}/fail
            method: POST
            auth: true
            use: rabbitmq
            config:
              exchange: deliveries
              routing_key: fail_delivery
            bind:
              - deliveryId:{deliveryId}
        
          - upstream: /{deliveryId}/complete
            method: POST
            auth: true
            use: rabbitmq
            config:
              exchange: deliveries
              routing_key: complete_delivery
            bind:
              - deliveryId:{deliveryId}
        
          - upstream: /{deliveryId}/registrations
            method: POST
            auth: true
            use: rabbitmq
            config:
              exchange: deliveries
              routing_key: add_delivery_registration
            bind:
              - deliveryId:{deliveryId}
              
        services:
          deliveries-service:
            localUrl: localhost:5003
            url: deliveries-service
            
            
      identity:
        path: identity
        routes:
          - upstream: /users/{userId}
            method: GET
            use: downstream
            downstream: identity-service/users/{userId}
            auth: true
            claims:
              role: admin
        
          - upstream: /me
            method: GET
            use: downstream
            downstream: identity-service/me
            auth: true
            
          - upstream: /sign-up
            method: POST
            use: downstream
            downstream: identity-service/sign-up
            auth: false
            resourceId:
              property: userId
              generate: true
        
          - upstream: /sign-in
            method: POST
            auth: false
            use: downstream
            downstream: identity-service/sign-in
            responseHeaders:
              content-type: application/json
              
        services:
          identity-service:
            localUrl: localhost:5004
            url: identity-service
            
            
      operations:
        path: operations
        routes:
          - upstream: /{operationId}
            method: GET
            use: downstream
            downstream: operations-service/operations/{operationId}
            auth: false
            
        services:
          operations-service:
            localUrl: localhost:5005
            url: operations-service
            
            
      orders:
        path: orders
        routes:
          - upstream: /
            method: GET
            use: downstream
            downstream: orders-service/orders?customerId=@user_id
            auth: true
        
          - upstream: /{orderId}
            method: GET
            use: downstream
            downstream: orders-service/orders/{orderId}
            auth: true
        
          - upstream: /
            method: POST
            auth: true
            resourceId:
              property: orderId
              generate: true
            use: rabbitmq
            config:
              exchange: orders
              routing_key: create_order
            bind:
              - customerId:@user_id
        
          - upstream: /{orderId}
            method: DELETE
            auth: true
            use: rabbitmq
            config:
              exchange: orders
              routing_key: delete_order
            bind:
              - orderId:{orderId}
              - customerId:@user_id
        
          - upstream: /{orderId}/parcels/{parcelId}
            method: POST
            auth: true
            use: rabbitmq
            config:
              exchange: orders
              routing_key: add_parcel_to_order
            bind:
              - orderId:{orderId}
              - parcelId:{parcelId}
              - customerId:@user_id
        
          - upstream: /{orderId}/parcels/{parcelId}
            method: DELETE
            auth: true
            use: rabbitmq
            config:
              exchange: orders
              routing_key: delete_parcel_from_order
            bind:
              - orderId:{orderId}
              - parcelId:{parcelId}
              - customerId:@user_id
        
          - upstream: /{orderId}/vehicles/{vehicleId}
            method: POST
            auth: true
            use: rabbitmq
            config:
              exchange: orders
              routing_key: assign_vehicle_to_order
            bind:
              - orderId:{orderId}
              - vehicleId:{vehicleId}
              - customerId:@user_id
              
        services:
          orders-service:
            localUrl: localhost:5006
            url: orders-service
            
            
      parcels:
        path: parcels
        routes:
          - upstream: /
            method: GET
            use: downstream
            downstream: parcels-service/parcels?customerId=@user_id
            auth: true
        
          - upstream: /{parcelId}
            method: GET
            use: downstream
            downstream: parcels-service/parcels/{parcelId}
            auth: true
        
          - upstream: /volume
            method: GET
            use: downstream
            downstream: parcels-service/parcels/volume
            auth: true
        
          - upstream: /
            method: POST
            auth: true
            resourceId:
              property: parcelId
              generate: true
            use: rabbitmq
            config:
              exchange: parcels
              routing_key: add_parcel
            bind:
              - customerId:@user_id
        
          - upstream: /{parcelId}
            method: DELETE
            auth: true
            use: rabbitmq
            config:
              exchange: parcels
              routing_key: delete_parcel
            bind:
              - parcelId:{parcelId}
              - customerId:@user_id
              
        services:
          parcels-service:
            localUrl: localhost:5007
            url: parcels-service
            
            
      pricing:
        path: pricing
        routes:
          - upstream: /
            method: GET
            use: downstream
            downstream: pricing-service/pricing?customerId=@user_id
            auth: true
            
        services:
          pricing-service:
            localUrl: localhost:5008
            url: pricing-service
            
            
      vehicles:
        path: vehicles
        routes:
          - upstream: /
            method: GET
            use: downstream
            downstream: vehicles-service/vehicles
            auth: true
            onSuccess:
              data: response.data.items
        
          - upstream: /{vehicleId}
            method: GET
            use: downstream
            downstream: vehicles-service/vehicles/{vehicleId}
            auth: true
        
          - upstream: /
            method: POST
            auth: true
            resourceId:
              property: vehicleId
              generate: true
            use: rabbitmq
            config:
              exchange: vehicles
              routing_key: add_vehicle
        
          - upstream: /{vehicleId}
            method: PUT
            auth: true
            use: rabbitmq
            config:
              exchange: vehicles
              routing_key: update_vehicle
            bind:
              - vehicleId:{vehicleId}
        
          - upstream: /{vehicleId}
            method: DELETE
            auth: true
            use: rabbitmq
            config:
              exchange: vehicles
              routing_key: delete_vehicle
            bind:
              - vehicleId:{vehicleId}
              
        services:
          vehicles-service:
            localUrl: localhost:5009
            url: vehicles-service
