Skip to content

Commit

Permalink
Merge pull request #222 from gyorilab/flask3
Browse files Browse the repository at this point in the history
Update Flask-JWT-Extended, Flask
  • Loading branch information
bgyori authored Jul 19, 2024
2 parents 8eefc3f + c1ba3a6 commit 64830f4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
1 change: 1 addition & 0 deletions indra_db_service/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
17 changes: 12 additions & 5 deletions indra_db_service/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions indra_db_service/cli/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import main


if __name__ == '__main__':
main()
17 changes: 1 addition & 16 deletions indra_db_service/cli/zappa_tools.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os
import json
import boto3

from indra_db.config import CONFIG
Expand All @@ -10,28 +8,15 @@
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
the lambda functions it creates. This function goes in and fixes those
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():
Expand Down
4 changes: 2 additions & 2 deletions indra_db_service/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)

0 comments on commit 64830f4

Please sign in to comment.