reddit edge request context baggage
Project description
edgecontext.py
Documentation: https://reddit-edgecontext.readthedocs.io/en/latest/
Services deep within the backend often need to know information about the client that originated the request, such as what user is authenticated or what country they're in. Baseplate services can get this information from the edge context which is automatically propagated along with calls between services.
This library provides a Thrift specification of an edge context payload and a
corresponding implementation of the EdgeContextFactory
interface from
Baseplate.py.
Usage
Add the EdgeContextFactory
to application startup:
from baseplate import Baseplate
from baseplate.lib.secrets import secrets_store_from_config
from reddit_edgecontext import EdgeContextFactory
def make_processor(app_config):
secrets = secrets_store_from_config(app_config, timeout=60)
edgecontext_factory = EdgeContextFactory(secrets)
# pass edgecontext_factory to your framework's integration
# for Thrift: baseplate.frameworks.thrift.baseplateify_processor
# for Pyramid: baseplate.frameworks.pyramid.BaseplateConfigurator
Then read fields while handling requests:
def my_view(request):
return request.edgecontext.user.id
See the documentation for all the available fields.
Development
A Dockerfile is provided to get a development environment running. To use it, build the base Docker image:
$ docker build -t edgecontext .
And then fire up the environment and use the provided Makefile targets to do common tasks:
$ docker run -it -v $PWD:/src -w /src edgecontext
$ make fmt
The following make targets are provided:
fmt
: Apply automatic formatting to the source code.thrift
: Generate code from the Thrift IDL. Runfmt
after doing this.lint
: Run linters on the code.test
: Run the test suite.docs
: Build the docs. Output can be found inbuild/html/
.
The generated Thrift code is committed to the Git repo, so if you change
reddit_edgecontext/edgecontext.thrift
make sure to run make thrift fmt
and
commit those changes as well.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for reddit_edgecontext-1.0.0a2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebaa089549375c9ff5fa45479da01565afaa2e1074df02c814e2a92f3df1a016 |
|
MD5 | 1573a26d9e8167c1eb8ca626b141f1a7 |
|
BLAKE2b-256 | f44683e1dcd87bd2886ca6dab000f1286f86055a65b9fd7f1a9146eb7b0e8ab8 |
Hashes for reddit_edgecontext-1.0.0a2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dd7c11983674678b1b19cbdfb4261ce2d5a240101484fcd8e1a04b6f4abc8e5 |
|
MD5 | 32c433a9243150b088516e44c30ebd78 |
|
BLAKE2b-256 | e0a0dbe7d996e41f1cf23afa358ea5de51236a37c8cc023227b15562531a817d |