Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grouping events configurations with overrides #931

Open
mastersilv3r opened this issue Jan 23, 2024 · 0 comments
Open

Grouping events configurations with overrides #931

mastersilv3r opened this issue Jan 23, 2024 · 0 comments
Assignees
Labels
feature new feature P2 Low priority

Comments

@mastersilv3r
Copy link
Contributor

mastersilv3r commented Jan 23, 2024

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 mastersilv3r added the feature new feature label Jan 23, 2024
@mastersilv3r mastersilv3r self-assigned this Jan 23, 2024
@mastersilv3r mastersilv3r added the P2 Low priority label Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature new feature P2 Low priority
Projects
None yet
Development

No branches or pull requests

1 participant