From a7fbce242f6683d66452ff02e541aa9b28908f39 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 14 Oct 2021 07:19:32 +0300 Subject: Allow CORS_ORIGINS to be configurable via the environment Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/non-clustered-heatmaps-and-flipping.gmi * gn3/app.py: setup CORS after all the configuration sources are loaded. * gn3/settings.py: Parse CORS_ORIGINS from the environment variables. Enable the CORS_ORIGINS configuration to be set in the environment variables to give the application some flexibility when launching. --- gn3/settings.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'gn3/settings.py') diff --git a/gn3/settings.py b/gn3/settings.py index 150d96d..56ddaba 100644 --- a/gn3/settings.py +++ b/gn3/settings.py @@ -35,10 +35,17 @@ GENOTYPE_FILES = os.environ.get( "GENOTYPE_FILES", "{}/genotype_files/genotype".format(os.environ.get("HOME"))) # CROSS-ORIGIN SETUP -CORS_ORIGINS = [ +def parse_env_cors(default): + origins_str = os.environ.get("CORS_ORIGINS", None) + if origins_str: + return [ + origin.strip() for origin in origins_str.split(",") if origin != ""] + return default + +CORS_ORIGINS = parse_env_cors([ "http://localhost:*", "http://127.0.0.1:*" -] +]) CORS_HEADERS = [ "Content-Type", -- cgit v1.2.3 From 546b37e77c11c5268aa9510b9756f2ed4d60241d Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 14 Oct 2021 07:31:41 +0300 Subject: Fix some linting issues --- gn3/heatmaps.py | 6 +++--- gn3/settings.py | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'gn3/settings.py') diff --git a/gn3/heatmaps.py b/gn3/heatmaps.py index ff65652..2dd9d07 100644 --- a/gn3/heatmaps.py +++ b/gn3/heatmaps.py @@ -374,8 +374,8 @@ def clustered_heatmap( fig = make_subplots( rows=num_plots if vertical else 1, cols=1 if vertical else num_plots, - shared_xaxes = "columns" if vertical else False, - shared_yaxes = False if vertical else "rows", + shared_xaxes="columns" if vertical else False, + shared_yaxes=False if vertical else "rows", vertical_spacing=0.010, horizontal_spacing=0.001, subplot_titles=["" if vertical else x_axis["label"]] + [ @@ -407,7 +407,7 @@ def clustered_heatmap( "mirror": False, "showticklabels": i == 0, "ticks": "outside" if i == 0 else "" - } + } for i in range(num_plots)} print("vertical?: {} ==> {}".format("T" if vertical else "F", axes_layouts)) diff --git a/gn3/settings.py b/gn3/settings.py index 56ddaba..d5f1d3c 100644 --- a/gn3/settings.py +++ b/gn3/settings.py @@ -36,6 +36,7 @@ GENOTYPE_FILES = os.environ.get( # CROSS-ORIGIN SETUP def parse_env_cors(default): + """Parse comma-separated configuration into list of strings.""" origins_str = os.environ.get("CORS_ORIGINS", None) if origins_str: return [ -- cgit v1.2.3