Use shared access for synthetic breast follow-up
This commit is contained in:
+1
-12
@@ -1,23 +1,12 @@
|
||||
"""Configure the breast cohort using the shared persistence settings."""
|
||||
|
||||
import hmac
|
||||
import os
|
||||
import re
|
||||
|
||||
from persistance.db import get_cama_session
|
||||
from webapi.cama_cohort import CamaCohort
|
||||
|
||||
|
||||
def configure_cama_cohort(app):
|
||||
token = os.environ.get('CAMA_COHORT_ACCESS_TOKEN', '')
|
||||
|
||||
def read(cutoff):
|
||||
with get_cama_session() as session:
|
||||
return CamaCohort(session).rows(cutoff)
|
||||
|
||||
def access(req):
|
||||
supplied = req.headers.get('X-Cama-Cohort-Token', '')
|
||||
return bool(re.fullmatch(r'[A-Za-z0-9_-]{32,}', token)) and hmac.compare_digest(
|
||||
supplied.encode('utf-8'), token.encode('utf-8'))
|
||||
|
||||
app.config.update(CAMA_COHORT_READER=read, CAMA_COHORT_ACCESS=access)
|
||||
app.config['CAMA_COHORT_READER'] = read
|
||||
|
||||
Reference in New Issue
Block a user