Categorygithub.com/myhops/cewrap
modulepackage
0.0.0-20231128061820-6573be100342
Repository: https://github.com/myhops/cewrap.git
Documentation: pkg.go.dev

# README

cewrap

CE Wrapper is a wrapper to generate CloudEvents events for services that do not emit events themselves. It will initially work for RESTful APIs.

It is a completely stateless proxy that passes the request unmodified to the downstream service, and emits an event for requests that are of interest.

Default these are requests that change state, like POST, PUT, PATCH and DELETE, but other methods can be added.

The mandatory cloud event context attributes are set using the information of the incoming http request, or with values set by the user. This way ample information is available for filtering and subscribing.

Context Attributes

  • id, will be set with an autogenerated UUID
  • source, needs to be configured
  • subject, the path of the request
  • type, this value will be a configured prefix follow by the methodname and the suffix _handled
  • time, the time the forwarded request finished
  • datacontenttype, the content type of the response from the downstream service
  • dataschema, can be configured

The data will contain a json struct with the response body the downstream service returned.

Example

Assume the downstream service is on service.example.com and it returns json formatted responses with person information.

A successful post request to http://service.example.com/persons/id12345 resource that contains persons will result in an event with the following attributes.

  • subject: /persons/id12345
  • type: com.example.persons.post_handled
  • source: http://service.example.com/

Command line parameters and env vars

parameterenv vardescription
-sinkK_SINK, CWE_SINKThe url of the event sink.
-sourceCEW_SOURCEThe source of the event.
-typeCEW_TYPE_PREFIXThe prefix for the type.
-dataschemaCEW_DATASCHEMAThe URL for the dataschema of the event data.
-downstreamCEW_DOWNSTREAMDownstream service.
-portPORTListening port of the wrapper, defaults to 8080.
-extra-methodsCEW_EXTRA_METHODSExtra methods to add to the standard state changing methods

Test setup

Run go-httpbin on port 9090.

podman run --rm -p 9090:8080 docker.io/mccutchen/go-httpbin:v2.11.1

Run cesourcewrap on port 8080.

podman run --rm \
    -p 8080:8080 \
    -e CEW_SINK=http://192.168.0.202:10000 \
    -e CEW_DOWNSTREAM=http://192.168.0.202:9090 \
    -e CEW_EXTRA_METHODS=GET \
    docker.io/peterzandbergen/cesourcewrap:v0.0.1

Run event display on port 10000

podman run --rm \
    -p 10000:80 \
    gcr.io/knative-releases/knative.dev/eventing/cmd/event_display

# Packages

No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author

# Structs

No description provided by the author

# Interfaces

No description provided by the author