-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
57 lines (45 loc) · 1.54 KB
/
app.py
File metadata and controls
57 lines (45 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from textwrap import dedent
from jwt import PyJWKClient
from motor.motor_asyncio import AsyncIOMotorClient
from sanic import Blueprint, Sanic
from api.auth import attach_uid
from blueprints.auth import blueprint as auth
from blueprints.notes import blueprint as notes
from blueprints.search import blueprint as search
from blueprints.status import blueprint as status
from config import config
app = Sanic(__name__)
app.config.update(config)
app.ext.openapi.describe(
'notesreview-api',
version='0.1.0',
description=dedent(
"""\
# Information
This API is still subject to change, especially the behavior of the `query` parameter might change in the future,
because right now the possibilities are still a little bit limited.
"""
),
)
app.ext.openapi.add_security_scheme(
'token',
'http',
scheme='bearer',
bearer_format='JWT',
description='OpenID Connect Token issued by OpenStreetMap',
)
@app.before_server_start
async def setup(app, loop):
client = AsyncIOMotorClient(
f'mongodb://{app.config.DB_USER}:{app.config.DB_PASSWORD}@{app.config.DB_HOST}:27017?authSource=notesreview',
io_loop=loop,
)
jwks_client = PyJWKClient(app.config.OPENSTREETMAP_OAUTH_JWKS_URI)
app.ctx.client = client
app.ctx.db = client.notesreview
app.ctx.jwks_client = jwks_client
@app.before_server_stop
async def shutdown(app, loop):
app.ctx.client.close()
app.blueprint(Blueprint.group(auth, status, search, url_prefix='/api'))
app.register_middleware(attach_uid, 'request')