From bf234e29ddfb92de32b73d7d22d020ea7b873ff9 Mon Sep 17 00:00:00 2001 From: Vincent LaGrassa Date: Mon, 3 Jun 2024 12:53:18 -0500 Subject: [PATCH 1/2] Add override version of public bucket name env var --- env/development/global.env | 3 ++- env/qa/global.env | 3 ++- src/modules/site-v2/config.py | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/env/development/global.env b/env/development/global.env index 2219258e2..e9f7942cc 100644 --- a/env/development/global.env +++ b/env/development/global.env @@ -54,9 +54,10 @@ MODULE_SITE_CLOUDRUN_SA_NAME=caendr-dev-cloudrun-site MODULE_SITE_BUCKET_PHOTOS_NAME=caendr-dev-site-photos MODULE_SITE_BUCKET_ASSETS_NAME=caendr-dev-site-static MODULE_SITE_BUCKET_PRIVATE_NAME=caendr-dev-site-private +MODULE_SITE_BUCKET_PUBLIC_NAME=caendr-dev-site-public-bucket # Main environment bucket(s) -MODULE_SITE_BUCKET_PUBLIC_NAME=caendr-site-public-bucket +MODULE_SITE_BUCKET_PUBLIC_NAME_OVERRIDE=caendr-site-public-bucket # Override for accessing dataset release files # If not provided, defaults to MODULE_SITE_BUCKET_PUBLIC_NAME diff --git a/env/qa/global.env b/env/qa/global.env index 7fce2dd28..80b045563 100644 --- a/env/qa/global.env +++ b/env/qa/global.env @@ -54,9 +54,10 @@ MODULE_SITE_CLOUDRUN_SA_NAME=caendr-qa-cloudrun-site MODULE_SITE_BUCKET_PHOTOS_NAME=caendr-qa-site-photos-bucket MODULE_SITE_BUCKET_ASSETS_NAME=caendr-qa-site-static-bucket MODULE_SITE_BUCKET_PRIVATE_NAME=caendr-qa-site-private-bucket +MODULE_SITE_BUCKET_PUBLIC_NAME=caendr-qa-site-public-bucket # Main environment bucket(s) -MODULE_SITE_BUCKET_PUBLIC_NAME=caendr-site-public-bucket +MODULE_SITE_BUCKET_PUBLIC_NAME_OVERRIDE=caendr-site-public-bucket # Override for accessing dataset release files # If not provided, defaults to MODULE_SITE_BUCKET_PUBLIC_NAME diff --git a/src/modules/site-v2/config.py b/src/modules/site-v2/config.py index 45a502ac2..727755151 100755 --- a/src/modules/site-v2/config.py +++ b/src/modules/site-v2/config.py @@ -48,6 +48,7 @@ 'MODULE_SITE_BUCKET_PHOTOS_NAME', 'MODULE_SITE_BUCKET_ASSETS_NAME', 'MODULE_SITE_BUCKET_PUBLIC_NAME', + 'MODULE_SITE_BUCKET_PUBLIC_NAME_OVERRIDE', 'MODULE_SITE_BUCKET_PRIVATE_NAME', 'MODULE_SITE_BUCKET_DATASET_RELEASE_NAME', 'MODULE_SITE_SENTRY_NAME', From 725b603ffd0789edb42f16a7b2ef9bacc90b81b1 Mon Sep 17 00:00:00 2001 From: Vincent LaGrassa Date: Mon, 3 Jun 2024 12:54:21 -0500 Subject: [PATCH 2/2] Check for public bucket override version before original version Using `get_env_var_with_fallback` --- src/modules/site-v2/base/utils/markdown.py | 4 +++- src/modules/site-v2/base/views/data/releases.py | 2 +- src/pkg/caendr/caendr/models/datastore/dataset_release.py | 2 +- src/pkg/caendr/caendr/models/datastore/indel_primer.py | 4 ++-- src/pkg/caendr/caendr/models/datastore/profile.py | 4 +++- src/pkg/caendr/caendr/models/datastore/protocol.py | 4 +++- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/modules/site-v2/base/utils/markdown.py b/src/modules/site-v2/base/utils/markdown.py index b0cd689da..36719765c 100644 --- a/src/modules/site-v2/base/utils/markdown.py +++ b/src/modules/site-v2/base/utils/markdown.py @@ -3,12 +3,14 @@ import markdown import requests +from caendr.utils.env import get_env_var_with_fallback + from caendr.services.logger import logger from caendr.models.error import ExternalMarkdownRenderError from flask import Markup, render_template_string -MODULE_SITE_BUCKET_PUBLIC_NAME = os.environ.get('MODULE_SITE_BUCKET_PUBLIC_NAME') +MODULE_SITE_BUCKET_PUBLIC_NAME = get_env_var_with_fallback('MODULE_SITE_BUCKET_PUBLIC_NAME_OVERRIDE', 'MODULE_SITE_BUCKET_PUBLIC_NAME') diff --git a/src/modules/site-v2/base/views/data/releases.py b/src/modules/site-v2/base/views/data/releases.py index c66e0326d..afa8d2621 100644 --- a/src/modules/site-v2/base/views/data/releases.py +++ b/src/modules/site-v2/base/views/data/releases.py @@ -138,7 +138,7 @@ def data_v01(params, files): vcf_summary = None return { - 'site_bucket_public_name': config.get('MODULE_SITE_BUCKET_DATASET_RELEASE_NAME', config.get('MODULE_SITE_BUCKET_PUBLIC_NAME', 'NONE')), + 'site_bucket_public_name': config.get('MODULE_SITE_BUCKET_DATASET_RELEASE_NAME', config.get('MODULE_SITE_BUCKET_PUBLIC_NAME_OVERRIDE', config.get('MODULE_SITE_BUCKET_PUBLIC_NAME', 'NONE'))), 'browser_tracks_path': get_browser_tracks_path().get_string_safe(), 'vcf_summary_url': vcf_summary_url, 'vcf_summary': vcf_summary, diff --git a/src/pkg/caendr/caendr/models/datastore/dataset_release.py b/src/pkg/caendr/caendr/models/datastore/dataset_release.py index 8b2a89ff5..b0e8c8384 100644 --- a/src/pkg/caendr/caendr/models/datastore/dataset_release.py +++ b/src/pkg/caendr/caendr/models/datastore/dataset_release.py @@ -14,7 +14,7 @@ V1_V2_Cutoff_Date = 20200101 -DATASET_RELEASE_BUCKET_NAME = get_env_var_with_fallback('MODULE_SITE_BUCKET_DATASET_RELEASE_NAME', 'MODULE_SITE_BUCKET_PUBLIC_NAME') +DATASET_RELEASE_BUCKET_NAME = get_env_var_with_fallback('MODULE_SITE_BUCKET_DATASET_RELEASE_NAME', 'MODULE_SITE_BUCKET_PUBLIC_NAME_OVERRIDE', 'MODULE_SITE_BUCKET_PUBLIC_NAME') FASTA_FILENAME_TEMPLATE = get_env_var('FASTA_FILENAME_TEMPLATE', as_template=True) FASTA_EXTENSION_FILE = get_env_var('FASTA_EXTENSION_FILE') diff --git a/src/pkg/caendr/caendr/models/datastore/indel_primer.py b/src/pkg/caendr/caendr/models/datastore/indel_primer.py index 8d66758c9..de9eecfe8 100644 --- a/src/pkg/caendr/caendr/models/datastore/indel_primer.py +++ b/src/pkg/caendr/caendr/models/datastore/indel_primer.py @@ -1,7 +1,7 @@ import os from caendr.services.logger import logger -from caendr.utils.env import get_env_var +from caendr.utils.env import get_env_var, get_env_var_with_fallback from caendr.models.datastore import ReportEntity, HashableEntity, Species from caendr.services.dataset_release import get_dataset_release @@ -9,7 +9,7 @@ # Get environment variables -MODULE_SITE_BUCKET_PUBLIC_NAME = get_env_var('MODULE_SITE_BUCKET_PUBLIC_NAME') +MODULE_SITE_BUCKET_PUBLIC_NAME = get_env_var_with_fallback('MODULE_SITE_BUCKET_PUBLIC_NAME_OVERRIDE', 'MODULE_SITE_BUCKET_PUBLIC_NAME') SOURCE_FILENAME = get_env_var('INDEL_PRIMER_SOURCE_FILENAME', as_template=True) diff --git a/src/pkg/caendr/caendr/models/datastore/profile.py b/src/pkg/caendr/caendr/models/datastore/profile.py index 547dc592c..17f5d5807 100644 --- a/src/pkg/caendr/caendr/models/datastore/profile.py +++ b/src/pkg/caendr/caendr/models/datastore/profile.py @@ -2,10 +2,12 @@ from caendr.services.logger import logger +from caendr.utils.env import get_env_var, get_env_var_with_fallback + from caendr.models.datastore import Entity from caendr.services.cloud.storage import BlobURISchema, generate_blob_uri -MODULE_SITE_BUCKET_PUBLIC_NAME = os.environ.get('MODULE_SITE_BUCKET_PUBLIC_NAME') +MODULE_SITE_BUCKET_PUBLIC_NAME = get_env_var_with_fallback('MODULE_SITE_BUCKET_PUBLIC_NAME_OVERRIDE', 'MODULE_SITE_BUCKET_PUBLIC_NAME') PROFILE_PHOTO_PATH_PREFIX = 'profile/photos' diff --git a/src/pkg/caendr/caendr/models/datastore/protocol.py b/src/pkg/caendr/caendr/models/datastore/protocol.py index 98279d786..d341d10c3 100644 --- a/src/pkg/caendr/caendr/models/datastore/protocol.py +++ b/src/pkg/caendr/caendr/models/datastore/protocol.py @@ -1,8 +1,10 @@ import os +from caendr.utils.env import get_env_var_with_fallback + from caendr.models.datastore import Entity -MODULE_SITE_BUCKET_PUBLIC_NAME = os.environ.get('MODULE_SITE_BUCKET_PUBLIC_NAME') +MODULE_SITE_BUCKET_PUBLIC_NAME = get_env_var_with_fallback('MODULE_SITE_BUCKET_PUBLIC_NAME_OVERRIDE', 'MODULE_SITE_BUCKET_PUBLIC_NAME') PROTOCOL_PDF_PATH_PREFIX = 'protocol/pdf'