elstat/elstat/blueprints/decorators.py
Luna Mendes ecf6234cfe elstat.adapters: add latency to db spec
Since this is a change to the table schema for all services using the
ping adapter, you will have to delete the tables relating to them.

 - elstat.blueprints: add incidents blueprint (WIP)
 - elstat.blueprints: add decorators.py
 - elstat.blueprints: add errors.py
 - elstat.manager: add incidents & incident_stages tables
 - run: add handler for ApiError
2018-07-13 23:20:09 -03:00

22 lines
577 B
Python

import hashlib
from .errors import ApiError
def auth_route(handler):
"""Declare an authenticated route."""
async def _handler(request, *args, **kwargs):
try:
pwhash = request.headers['Authorization']
except KeyError:
raise ApiError('no password provided', 403)
correct = request.app.cfg.PASSWORD
hashed = hashlib.sha256(correct.encode()).hexdigest()
if pwhash != hashed:
raise ApiError('invalid password', 403)
return await handler(request, *args, **kwargs)
return _handler