From f507a6a58f970e6ab049cd47a81721436c8777ac Mon Sep 17 00:00:00 2001 From: kkaris Date: Fri, 12 Jul 2024 18:49:49 -0700 Subject: [PATCH 1/4] Update flask_jwt_extended decorator --- indra_db_service/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indra_db_service/config.py b/indra_db_service/config.py index 511e2415..474e8763 100644 --- a/indra_db_service/config.py +++ b/indra_db_service/config.py @@ -12,7 +12,7 @@ from os import environ from pathlib import Path -from flask_jwt_extended import jwt_optional +from flask_jwt_extended import jwt_required TITLE = "The INDRA Database" DEPLOYMENT = environ.get("INDRA_DB_API_DEPLOYMENT") @@ -39,4 +39,4 @@ def jwt_nontest_optional(func): if TESTING["status"]: return func else: - return jwt_optional(func) + return jwt_required(optional=True)(func) From 19a7cca9fd8d50a0e1bad6c2d0c32decf7fbc872 Mon Sep 17 00:00:00 2001 From: kkaris Date: Mon, 15 Jul 2024 13:57:31 -0700 Subject: [PATCH 2/4] Make cli runnable as module --- indra_db_service/cli/__main__.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 indra_db_service/cli/__main__.py diff --git a/indra_db_service/cli/__main__.py b/indra_db_service/cli/__main__.py new file mode 100644 index 00000000..daf55090 --- /dev/null +++ b/indra_db_service/cli/__main__.py @@ -0,0 +1,5 @@ +from . import main + + +if __name__ == '__main__': + main() From 0935e6f12f15db9c3058f4f869be7ebf001c8449 Mon Sep 17 00:00:00 2001 From: kkaris Date: Mon, 15 Jul 2024 13:58:11 -0700 Subject: [PATCH 3/4] Provide zappa settings as function argument --- indra_db_service/cli/__init__.py | 17 ++++++++++++----- indra_db_service/cli/zappa_tools.py | 17 +---------------- 2 files changed, 13 insertions(+), 21 deletions(-) mode change 100755 => 100644 indra_db_service/cli/zappa_tools.py diff --git a/indra_db_service/cli/__init__.py b/indra_db_service/cli/__init__.py index 303fed67..d42f35ed 100644 --- a/indra_db_service/cli/__init__.py +++ b/indra_db_service/cli/__init__.py @@ -10,15 +10,22 @@ def main(): @main.command() @click.argument('deployment', nargs=1) -def push(deployment): +@click.option('-s', '--settings', 'zappa_settings_file', + default='zappa_settings.json', + help="Specify the zappa settings file to use. Default is " + "'zappa_settings.json'.") +def push(deployment, zappa_settings_file): """Push a new deployment to the remote lambdas using zappa.""" - from indra_db_service.cli.zappa_tools import fix_permissions, ZAPPA_CONFIG + import json + from pathlib import Path + from indra_db_service.cli.zappa_tools import fix_permissions click.echo(f"Updating {deployment} deployment.") - if ZAPPA_CONFIG not in os.listdir('.'): - click.echo(f"Please run in directory with {ZAPPA_CONFIG}.") + if not Path(zappa_settings_file).exists(): + click.echo(f"Zappa settings file not found: {zappa_settings_file}") return + zappa_settings = json.load(open(zappa_settings_file, 'r')) os.system(f'zappa update {deployment}') - fix_permissions(deployment) + fix_permissions(deployment, zappa_settings=zappa_settings) @main.command() diff --git a/indra_db_service/cli/zappa_tools.py b/indra_db_service/cli/zappa_tools.py old mode 100755 new mode 100644 index 0ee4d42b..980c201e --- a/indra_db_service/cli/zappa_tools.py +++ b/indra_db_service/cli/zappa_tools.py @@ -1,5 +1,3 @@ -import os -import json import boto3 from indra_db.config import CONFIG @@ -10,20 +8,8 @@ aws_role = CONFIG['lambda']['role'] aws_primary_function = 'indra-db-api-ROOT' -# Load the Zappa config file. -ZAPPA_CONFIG = 'zappa_settings.json' - -def load_zappa_settings() -> dict: - if not os.path.exists(ZAPPA_CONFIG): - raise Exception(f"No valid zappa config file present. " - f"Expecting: {ZAPPA_CONFIG}") - with open('zappa_settings.json', 'r') as f: - zappa_settings = json.load(f) - return zappa_settings - - -def fix_permissions(deployment) -> None: +def fix_permissions(deployment, zappa_settings) -> None: """Add permissions to the lambda function to allow access from API Gateway. When Zappa runs, it removes permission for the primary endpoint to call @@ -31,7 +17,6 @@ def fix_permissions(deployment) -> None: permissions, and is intended to be run after a zappa update. """ # Get relevant settings from the zappa config. - zappa_settings = load_zappa_settings() project_name = zappa_settings[deployment]['project_name'] region = zappa_settings[deployment]['aws_region'] if zappa_settings[deployment]['profile_name'].lower() != aws_role.lower(): From c1ba3a684c2e5c99fd1f892ea5fd1b3c69c526ed Mon Sep 17 00:00:00 2001 From: kkaris Date: Tue, 16 Jul 2024 16:43:06 -0700 Subject: [PATCH 4/4] Add jwt wrapper for expand endpoint --- indra_db_service/api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/indra_db_service/api.py b/indra_db_service/api.py index 28867e42..2945e4dc 100644 --- a/indra_db_service/api.py +++ b/indra_db_service/api.py @@ -371,6 +371,7 @@ def get_statements(result_type, method): @app.route("/expand", methods=["POST"]) +@jwt_nontest_optional def expand_meta_row(): start_time = datetime.now()