From b23926ffb66c3579ad7bc15262ace98215e9a9f0 Mon Sep 17 00:00:00 2001 From: Mackenzie Grimes - NOAA Affiliate Date: Thu, 19 Dec 2024 11:52:08 -0700 Subject: [PATCH] store GSL_KEY in app.config --- python/nwsc_dummy_service/ncd_web_service.py | 3 +-- python/nwsc_dummy_service/test/test_ncd_web_service.py | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/nwsc_dummy_service/ncd_web_service.py b/python/nwsc_dummy_service/ncd_web_service.py index b79bab6..e94e81a 100644 --- a/python/nwsc_dummy_service/ncd_web_service.py +++ b/python/nwsc_dummy_service/ncd_web_service.py @@ -53,7 +53,7 @@ def __init__(self, base_dir: str): def handler(self): """Logic for requests to /all-events""" # check that this request has proper key to get or add data - if request.headers.get('X-Api-Key') != GSL_KEY: + if request.headers.get('X-Api-Key') != current_app.config['GSL_KEY']: return jsonify({'message': 'ERROR: Unauthorized'}), 401 if request.method == 'POST': @@ -99,7 +99,6 @@ def handler(self): return jsonify({'profiles': profiles, 'errors': []}), 200 - class AppWrapper: """Web server class wrapping Flask operations""" def __init__(self, base_dir: str): diff --git a/python/nwsc_dummy_service/test/test_ncd_web_service.py b/python/nwsc_dummy_service/test/test_ncd_web_service.py index a326798..ee69ed5 100644 --- a/python/nwsc_dummy_service/test/test_ncd_web_service.py +++ b/python/nwsc_dummy_service/test/test_ncd_web_service.py @@ -58,6 +58,7 @@ def mock_current_app(monkeypatch: MonkeyPatch) -> Mock: mock_obj = Mock(name='MockCurrentApp', spec=Flask) mock_obj.logger.info.return_value = None mock_obj.logger.error.return_value = None + mock_obj.config = MultiDict({'GSL_KEY': GSL_KEY}) monkeypatch.setattr('python.nwsc_dummy_service.ncd_web_service.current_app', mock_obj) return mock_obj