Skip to content

Conversation

@gctucker
Copy link
Collaborator

Add basic pub/sub interface to the API using CloudEvents.

@gctucker gctucker requested a review from a team October 19, 2021 08:56
Add redis container to docker-compose with a local data directory in
docker/redis/data mounted into the container.

Signed-off-by: Guillaume Tucker <guillaume.tucker@collabora.com>
Add the aioredis package to requirements.txt.  This will be used to
perform async i/o with Redis.

Signed-off-by: Guillaume Tucker <guillaume.tucker@collabora.com>
Rename the get_current_active_user() function with a shorter name
get_user() to make it easier to use it in authenticated queries.

Signed-off-by: Guillaume Tucker <guillaume.tucker@collabora.com>
Add api.pubsub.PubSub class to subscribe / listen / unsubscribe /
publish plain text events via the Redis pub/sub mechanism.  Add
authenticated query handlers in api.main to keep track of which
channels each user has subscribed to.

Here's an example, in a first terminal:

  $ curl -H 'Authorization: Bearer <token>' -X POST http://localhost:8001/subscribe/hey
  $ curl -H 'Authorization: Bearer <token>' http://localhost:8001/listen/hey

Then in a second one, to send a message "Hello":

  $ curl -H 'Authorization: Bearer <token>' -X POST http://localhost:8001/publish/hey/Hello

The first terminal will then receive this:

  {"type":"message","pattern":null,"channel":"hey","data":"Hello"}

Signed-off-by: Guillaume Tucker <guillaume.tucker@collabora.com>
Add the cloudevents package to requirements.txt.  This will be used to
wrap messages used in the Pub/Sub mechanism.  See more details here:

  https://cloudevents.io/

Signed-off-by: Guillaume Tucker <guillaume.tucker@collabora.com>
Use CloudEvents to format the messages published to the pub/sub.  They
get converted to JSON in plain text, so no changes are required on the
listening end.

Signed-off-by: Guillaume Tucker <guillaume.tucker@collabora.com>
Add api.client as a module which can be run as a command-line tool to
send and receive CloudEvents via the pub/sub API.

Signed-off-by: Guillaume Tucker <guillaume.tucker@collabora.com>
Add a section to README.md about the pub/sub part of the API and the
reference client script.

Signed-off-by: Guillaume Tucker <guillaume.tucker@collabora.com>
@gctucker gctucker merged commit aac1e71 into kernelci:main Oct 22, 2021
@gctucker gctucker deleted the T30699-pubsub branch October 22, 2021 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant