Skip to content

Commit

Permalink
Use env var to read MongoDB password
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Todor <todormihai@gmail.com>
  • Loading branch information
mihaitodor committed Dec 19, 2024
1 parent 82bfda5 commit bacd0f1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ __pycache__
utilities/FASTA
utilities/mongo_utilities.py
/data
secrets.env
20 changes: 12 additions & 8 deletions app/common.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down
6 changes: 4 additions & 2 deletions utilities/common.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit bacd0f1

Please sign in to comment.