https://github.com/xmidt-org/wrp-listener
This library makes listening to WRP events from Xmidt easier to do.
https://github.com/xmidt-org/wrp-listener
Last synced: about 2 months ago
JSON representation
This library makes listening to WRP events from Xmidt easier to do.
- Host: GitHub
- URL: https://github.com/xmidt-org/wrp-listener
- Owner: xmidt-org
- License: apache-2.0
- Created: 2019-07-17T18:39:00.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T12:53:26.000Z (7 months ago)
- Last Synced: 2024-10-29T15:20:44.733Z (7 months ago)
- Language: Go
- Size: 8.13 MB
- Stars: 1
- Watchers: 14
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# wrp-listener
wrp-listener is a library that provides a webhook registerer and a validation
function to be used for authentication.[](https://github.com/xmidt-org/wrp-listener/actions/workflows/ci.yml)
[](http://codecov.io/github/xmidt-org/wrp-listener?branch=main)
[](https://goreportcard.com/report/github.com/xmidt-org/wrp-listener)
[](https://github.com/xmidt-org/wrp-listener/blob/main/LICENSE)
[](https://github.com/xmidt-org/wrp-listener/releases)
[](https://pkg.go.dev/github.com/xmidt-org/wrp-listener)## Summary
`wrp-listener`` provides a package to help a consumer register to a webhook and
authenticate messages received. Registering to a webhook can be done directly
or set up to run at an interval.## Details
The below code snippet gets you registered to the webhook and events flowing to you.
```golang
l, err := listener.New("https://example.com",
&webhook.Registration{
Config: webhook.DeliveryConfig{
ReceiverURL: receiverURL,
ContentType: contentType,
},
Events: []string{events},
Duration: webhook.CustomDuration(5 * time.Minute),
},
listener.AcceptSHA1(),
listener.Interval(1 * time.Minute),
listener.AcceptedSecrets(sharedSecrets...),
)
if err != nil {
panic(err)
}err = l.Register(context.Background(), sharedSecrets[0])
if err != nil {
panic(err)
}
```Authorization that the information from the webhook likstener provider is also
pretty simple.```golang
func (el *eventListener) ServeHTTP(w http.ResponseWriter, r *http.Request) {
token, err := el.l.Tokenize(r)
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
return
}err = el.l.Authorize(r, token)
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
return
}// ... do more stuff ...
w.WriteHeader(http.StatusOK)
}
```The full example found in [cmd/bearerListener/main.go](https://github.com/xmidt-org/wrp-listener/blob/main/cmd/bearerListener/main.go) is a working command line example that shows how to use the library from end to end.
Additional examples can be found in the `example_test.go` file.
Functional tests are found in `functional_test.go`
## Code of Conduct
This project and everyone participating in it are governed by the [XMiDT Code Of Conduct](https://xmidt.io/code_of_conduct/).
By participating, you agree to this Code.## Contributing
Refer to [CONTRIBUTING.md](CONTRIBUTING.md).