gs-node-service icon indicating copy to clipboard operation
gs-node-service copied to clipboard

Grouping events configurations with overrides

Open mastersilv3r opened this issue 1 year ago • 0 comments

The Problem

Sometimes we need to keep multiple versions of the same API in a codebase. This typically involved a different base path for each api like /v1/user/:userid, /v2/user/:userid etc. Currently this is possible in Godspeed via adding this base path in each endpoint separately. It should be able to be done at level of a group of events kept in a folder. this can be done by a custom base_url in each folder. Similarly, one should be able to setup custom authz, validation_error handlers, middleware per event group stored in a separate folder in src/events

The Solution

  • In eventsource yaml file, allow the event source settings per folder as well.
  • Default values will float in this sequence - Eventsource -> Event group -> Event
#common to all events and event groups
type: express
port: 9009

# Settings common to all events and event groups but customizable at event group and event level
file_size_limit: 50000000
request_body_limit: 20000000
base_url: /http2
middlewares: #Each middleware type can be a string[], string or JSONTask[]
  inputs:
    native: &original_native # will run before input validation 
      - com.biz.express.google_oauth2
      - com.biz.express.file_upload
      - com.biz.express.set_multiple_custom_middlewares
    generic: #will run after input validation
      - id: fetch_user_details
        summary: call a database and get more details of user
        fn: com.biz.enrich_user_details
      - id: fetch_policies
        summary: call a policy engine to get ACLs for RBAC or ABAC, and enrich the inputs.data object
        fn: com.biz.fetch_policies
  outputs: # output data validation will run after all the output middlewares
    native: | #will run after generic middlewares
      # can run a JS to evaluate a dynamically calculated list of middlewares
      <%
        middlewares.com_biz_express_some_middlewares_list
        .concat(middlewares.com_biz_express_other_middlewares_list)
      %>
    generic: #will run before native middlewares
      - id: kafka_publish
        summary: send an event to kafka
        fn: datasource.kafka.<topic_name>.producer
        args:
          topic: api_called
          message: <% outputs.body.message%>
authz:
  - fn: com.gs.transform
    id: http_default_authz
    args:
      success: false
      message: "EventSource authz failed"
on_request_validation_error:
  - fn: com.gs.transform
    id: x
    args: {success: false, code: 400, message: "shit", data: {req: true}}
on_response_validation_error:
  - fn: com.gs.transform
    id: x
    args: {success: false, code: 500, message: "shit", data: {res: true}}
event_groups:
  v1_events:
    file_size_limit: 50000000
    request_body_limit: 20000000
    base_url: /http2
    middlewares: #Each middleware type can be a string[], string or JSONTask[]
    inputs:
      native: # will run before input validation 
        - *original_native
        - com.biz.express.some_other
      generic: null # In this ex. we remove generic. If was set - will run after input validation
        # - id: fetch_user_details
        #   summary: call a database and get more details of user
        #   fn: com.biz.enrich_user_details
        # - id: fetch_policies
        #   summary: call a policy engine to get ACLs for RBAC or ABAC, and enrich the inputs.data object
        #   fn: com.biz.fetch_policies
    outputs: # output data validation will run after all the output middlewares
      native: | #will run after generic middlewares
        # can run a JS to evaluate a dynamically calculated list of middlewares
        <%
          middlewares.com_biz_express_some_middlewares_list
          .concat(middlewares.com_biz_express_other_middlewares_list)
        %>
      generic: #will run before native middlewares
        - id: kafka_publish
          summary: send an event to kafka
          fn: datasource.kafka.<topic_name>.producer
          args:
            topic: api_called
            message: <% outputs.body.message%>
    authz:
      - fn: com.gs.transform
        id: http_default_authz
        args:
          success: false
          message: "EventSource authz failed"
    on_request_validation_error:
      - fn: com.gs.transform
        id: x
        args: {success: false, code: 400, message: "shit", data: {req: true}}
    # on_response_validation_error: #If not explicitly overriden the eventsource config will be used

How will we solve

mastersilv3r avatar Jan 23 '24 04:01 mastersilv3r