A service backed by Ktor, writing incoming HTTP requests to one or serveral topics of one or more message brokers (Kafka, Redis or Cloud Pub/Sub).
Sometimes a call to a webhook is only received once. Writing a HTTP request to a semi-permanent message broker log allows for repeated processing.
Defining a route with the same syntax used for Ktor routing
Example
title = "My routes config"
[[routes]]
path = "/status/mail"
topic = "mail"
verify = false
format = "proto"
methods = [ "POST", "PUT", "HEAD", "GET" ]
[[routes]]
path = "/api/{id}"
topic = "api_calls"
format = "raw_body"
verify = true
validateJson = true
jsonSchema = """
<put your JSON schema here>
"""
Routing is saved in files with .toml
extension, and their location is set with the environment varaiable CONFIG_DIRECTORY
. If this is not set it will default to /etc/config/
.
Configuration consists of few tables:
Configuration is loaded on startup and then refreshed every 1 minute.
It can be retrieved either from a file or from kubernetes custom resources. Configuration from kubernetes currently does not support auth providers.
Configuration in a file is stored in TOML file format. See example configuration here. You can have several configuration files stored in /etc/config/
or in path defined in CONFIG_DIRECTORY
environment variable.
Configuration in kubernetes requires creating custom resource defitnions first:
kubectl create -f leiaroute_crd.yaml
kubectl create -f leiasinkprov_crd.yaml
Then add your objects:
kubectl create -f object1.yaml
...
Custom resource definitions and sample object definitions YAML files can be found here.
Route defines where given request should be sent to.
path
- is mandatory, HTTP URL path to matchtopic
- is mandatory, topic where the message will be sentsink
- is optional, name of sink where message will be sent, if not provided uses default sink.verify
- is optional, default isfalse
. Decides whether only request with a verified json web token is allowed. Requires ktor-jwt.format
- is optional, default isproto
a format using protobuf defined in zensum/webhook-proto. Also available israw_body
- writes HTTP body as is.methods
- is optional, default is all seven HTTP verbs.response
- is optional, HTTP response code which should be sent to the sender on success, default is204
.validateJson
- is optional, wether to validate body of the request as JSON before sending, default isfalse
.204
code is returned on success,400
code on error.jsonSchema
- is optional, validates request body against this JSON schema ifvalidateJson
is set totrue
cors
- is optional, list of hosts to check incoming request's origin against for CORS. By default all traffic is allowed. If contains*
then all hosts are allowed. When non empty,OPTIONS
method is allowed implicitly.authenticateUsing
- is optional, list of auth providers to verify request against
Leia needs at least one sink configured and marked as default.
name
- is mandatory, name to identify the sink in routes configurationsink
fieldtype
- is optional, one of these types:kafka
,redis
,gpubsub
,null
, default iskafka
isDefault
- is optional, must be set totrue
for one sink, default isfalse
options
- is optional, additional options to configure sink provider, it is a list of key/value pairs
For testing purposes you can use null
sink type which does not forward messages and only logs them.
To set kafka hostname and port use following option in configuration:
host = "<hostname>:<port>"
To set up hostname and port for redis Pub/Sub use following options in configuration:
host = "<hostname>"
port = "<port>"
To use other project than the default for Cloud Pub/Sub one use following option in configuration:
projectId = "<your-project-id>"
Before writing to sinks in Cloud Pub/Sub you need to create them first:
gcloud pubsub topics list-subscriptions --project <your-project-id> <topic>
GOOGLE_APPLICATION_CREDENTIALS
environment variable needs to point to your cloud service account key in json file. Create service account key.
This table is optional in configuration.
name
- is mandatory, name to identify the auth provider in routes configurationauthenticateUsing
fieldtype
- is optional, one of these types:jwk
,basic_auth
,no_auth
, default isno_auth
options
- is optional, additional options to configure auth provider, it is a list of key/value pairs
Option basic_auth_users
is a map of users and passwords.
Option jwk_config
is mandatory, it is a map of key/values. The map must contain jwk_url
and jwk_issuer
keys.
CONFIG_DIRECTORY
- location of toml files (default/etc/config/
)PORT
- port on which leia listens for requests (default80
)KUBERNETES_SERVICE_HOST
- hostname of kubernetes API (defaultlocalhost
)KUBERNETES_SERVICE_PORT
- port of kubernetes API (default8080
)KUBERNETES_ENABLE
- wether to read configuration from Kubernetes custom resources (defaulttrue
). To disable set it tofalse
.