From bacd0f15463b677190166a7dc0377254d51b60c6 Mon Sep 17 00:00:00 2001 From: Mihai Todor Date: Thu, 19 Dec 2024 17:05:34 +0000 Subject: [PATCH] Use env var to read MongoDB password Signed-off-by: Mihai Todor --- .github/workflows/cicd.yml | 2 ++ .gitignore | 1 + app/common.py | 20 ++++++++++++-------- run.py | 2 ++ tests/conftest.py | 5 +++++ utilities/common.py | 6 ++++-- 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 1527e6c94..0aa0c8c23 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -29,6 +29,8 @@ jobs: - name: Run Tests run: ./fetch_utilities_data.sh && python -m pytest + env: + MONGODB_READONLY_PASSWORD: ${{ secrets.MONGODB_READONLY_PASSWORD }} deploy: name: Deploy to dev diff --git a/.gitignore b/.gitignore index d54ff8b0a..daba48198 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ __pycache__ utilities/FASTA utilities/mongo_utilities.py /data +secrets.env diff --git a/app/common.py b/app/common.py index f52c60581..418d56172 100644 --- a/app/common.py +++ b/app/common.py @@ -1,17 +1,19 @@ +import os +import re from collections import OrderedDict +from datetime import datetime +from itertools import groupby from threading import Lock from uuid import uuid4 + import pyliftover -import requests -from datetime import datetime import pymongo +import requests from flask import abort -from itertools import groupby -import re # MongoDB Client URIs -FHIR_genomics_data_client_uri = "mongodb+srv://download:download@cluster0.8ianr.mongodb.net/FHIRGenomicsData" -utilities_data_client_uri = "mongodb+srv://download:download@cluster0.8ianr.mongodb.net/UtilitiesData" +FHIR_genomics_data_client_uri = f"mongodb+srv://readonly:{os.getenv('MONGODB_READONLY_PASSWORD')}@cluster0.8ianr.mongodb.net/FHIRGenomicsData" +utilities_data_client_uri = f"mongodb+srv://readonly:{os.getenv('MONGODB_READONLY_PASSWORD')}@cluster0.8ianr.mongodb.net/UtilitiesData" # MongoDB Clients client = pymongo.MongoClient(FHIR_genomics_data_client_uri) @@ -620,9 +622,11 @@ def create_fhir_variant_resource(record, ref_seq, subject): inner_end = record['END'] - abs(record['CIEND'][0]) outer_end = record['END'] + abs(record['CIEND'][1]) - resource["component"].append({"code": {"coding": [{"system": "http://loinc.org", "code": "81301-4", "display": "Variant outer start-end"}]}, "valueRange": {"low": {"value": outer_start}, "high": {"value": outer_end}}}) + resource["component"].append({"code": {"coding": [{"system": "http://loinc.org", "code": "81301-4", "display": "Variant outer start-end"}]}, + "valueRange": {"low": {"value": outer_start}, "high": {"value": outer_end}}}) - resource["component"].append({"code": {"coding": [{"system": "http://loinc.org", "code": "81302-2", "display": "Variant inner start-end"}]}, "valueRange": {"low": {"value": inner_start}, "high": {"value": inner_end}}}) + resource["component"].append({"code": {"coding": [{"system": "http://loinc.org", "code": "81302-2", "display": "Variant inner start-end"}]}, + "valueRange": {"low": {"value": inner_start}, "high": {"value": inner_end}}}) # Variant population allele frequency if 'popAlleleFreq' in record: diff --git a/run.py b/run.py index 35d01fb4a..710ba62b8 100644 --- a/run.py +++ b/run.py @@ -3,6 +3,8 @@ from app import create_app load_dotenv() +# Load secrets from secrets.env file if available +load_dotenv("secrets.env") app = create_app() diff --git a/tests/conftest.py b/tests/conftest.py index ccfa7e8e9..2eafd8e38 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,7 +1,12 @@ import pytest +from dotenv import load_dotenv from app import create_app +load_dotenv() +# Load secrets from secrets.env file if available +load_dotenv("secrets.env") + @pytest.fixture(scope='module') def client(): diff --git a/utilities/common.py b/utilities/common.py index a27b837c6..1e32ad1cb 100644 --- a/utilities/common.py +++ b/utilities/common.py @@ -1,9 +1,11 @@ -from enum import Enum +import os import re +from enum import Enum + import pandas as pd import pymongo -utilities_data_client_uri = "mongodb+srv://download:download@cluster0.8ianr.mongodb.net/UtilitiesData" +utilities_data_client_uri = f"mongodb+srv://readonly:{os.getenv('MONGODB_READONLY_PASSWORD')}@cluster0.8ianr.mongodb.net/UtilitiesData" utilities_client = pymongo.MongoClient(utilities_data_client_uri) utilities_db = utilities_client.UtilitiesData transcript_data = utilities_db.Transcripts