Use shared access for synthetic breast follow-up

This commit is contained in:
Angel Capetillo Zavala
2026-11-13 17:54:56 -06:00
parent 9c0e03f947
commit 46eb3dfc31
9 changed files with 35 additions and 71 deletions
+1 -9
View File
@@ -1,6 +1,5 @@
"""Run the cohort endpoints locally against an explicitly supplied synthetic SQLite file."""
import hmac
import os
from pathlib import Path
import sqlite3
@@ -24,9 +23,6 @@ if os.name == 'nt':
path = Path(os.environ['CAMA_SYNTHETIC_SQLITE']).resolve(strict=True)
token = os.environ['CAMA_COHORT_ACCESS_TOKEN']
if len(token) < 32:
raise ValueError('The access token must be at least 32 characters')
if not path.is_file():
raise ValueError('The synthetic SQLite database must already exist')
@@ -49,11 +45,7 @@ def read(cutoff):
return CamaCohort(session).rows(cutoff)
def authorized(request):
return hmac.compare_digest(request.headers.get('X-Cama-Cohort-Token', ''), token)
app.config.update(CAMA_COHORT_READER=read, CAMA_COHORT_ACCESS=authorized)
app.config['CAMA_COHORT_READER'] = read
if __name__ == '__main__':
app.run(host='127.0.0.1', port=int(os.environ.get('CAMA_COHORT_PORT', '5059')), debug=False)
+2 -11
View File
@@ -3,7 +3,6 @@
import argparse
import os
from pathlib import Path
import secrets
import sys
import types
@@ -14,9 +13,8 @@ args = parser.parse_args()
database = Path(args.database).resolve(strict=True)
if not database.is_file():
raise ValueError('The synthetic database must be an existing file')
token = secrets.token_hex(32)
os.environ.update(CAMA_DATABASE_URL='sqlite:///' + database.as_posix(),
CAMA_COHORT_ACCESS_TOKEN=token, MLFLOW_DISABLE_AGENT_HINT='1',
MLFLOW_DISABLE_AGENT_HINT='1',
MLFLOW_DISABLE_TELEMETRY='true')
for domain in ('CACU', 'TEA', 'GOVERNANCE'):
os.environ[domain + '_DATABASE_URL'] = 'sqlite:///:memory:'
@@ -32,12 +30,5 @@ from webapi import create_app
from werkzeug.serving import make_server
app = create_app()
application = app.wsgi_app
def test_proxy(environ, start_response):
# The harness is loopback-only and replaces any caller-supplied test token.
environ['HTTP_X_CAMA_COHORT_TOKEN'] = token
return application(environ, start_response)
print(f'Isolated synthetic test proxy: http://127.0.0.1:{args.port}', flush=True)
make_server('127.0.0.1', args.port, test_proxy, threaded=True).serve_forever()
make_server('127.0.0.1', args.port, app, threaded=True).serve_forever()