Skip to content

Commit

Permalink
Merge pull request #5 from Health-RI/main
Browse files Browse the repository at this point in the history
Add Support for mongo+srv Connection String in MongoDB Configuration
  • Loading branch information
costero-e authored Oct 25, 2024
2 parents 73f872b + b93d334 commit 7c1ded6
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 42 deletions.
23 changes: 15 additions & 8 deletions beacon/connections/mongo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
from beacon.connections.mongo import conf
import os

uri = "mongodb://{}:{}@{}:{}/{}?authSource={}".format(
conf.database_user,
conf.database_password,
conf.database_host,
conf.database_port,
conf.database_name,
conf.database_auth_source
)
if conf.database_cluster:
uri = "mongodb+srv://{}:{}@{}/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000".format(
conf.database_user,
conf.database_password,
conf.database_host
)
else:
uri = "mongodb://{}:{}@{}:{}/{}?authSource={}".format(
conf.database_user,
conf.database_password,
conf.database_host,
conf.database_port,
conf.database_name,
conf.database_auth_source
)

if os.path.isfile(conf.database_certificate):
uri += '&tls=true&tlsCertificateKeyFile={}'.format(conf.database_certificate)
Expand Down
3 changes: 2 additions & 1 deletion beacon/connections/mongo/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
database_name = 'beacon'
database_auth_source = 'admin'
database_certificate = ''
database_cafile = ''
database_cafile = ''
database_cluster = False
23 changes: 15 additions & 8 deletions beacon/connections/mongo/extract_filtering_terms.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,21 @@
ICD_REGEX = re.compile(r"(ICD[_A-Za-z0-9]+):([_A-Za-z0-9^\./-]+)")


uri = "mongodb://{}:{}@{}:{}/{}?authSource={}".format(
conf.database_user,
conf.database_password,
conf.database_host,
conf.database_port,
conf.database_name,
conf.database_auth_source
)
if conf.database_cluster:
uri = "mongodb+srv://{}:{}@{}/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000".format(
conf.database_user,
conf.database_password,
conf.database_host
)
else:
uri = "mongodb://{}:{}@{}:{}/{}?authSource={}".format(
conf.database_user,
conf.database_password,
conf.database_host,
conf.database_port,
conf.database_name,
conf.database_auth_source
)

if os.path.isfile(conf.database_certificate):
uri += '&tls=true&tlsCertificateKeyFile={}'.format(conf.database_certificate)
Expand Down
23 changes: 15 additions & 8 deletions beacon/connections/mongo/get_descendants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@
import conf


uri = "mongodb://{}:{}@{}:{}/{}?authSource={}".format(
conf.database_user,
conf.database_password,
conf.database_host,
conf.database_port,
conf.database_name,
conf.database_auth_source
)
if conf.database_cluster:
uri = "mongodb+srv://{}:{}@{}/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000".format(
conf.database_user,
conf.database_password,
conf.database_host
)
else:
uri = "mongodb://{}:{}@{}:{}/{}?authSource={}".format(
conf.database_user,
conf.database_password,
conf.database_host,
conf.database_port,
conf.database_name,
conf.database_auth_source
)

if os.path.isfile(conf.database_certificate):
uri += '&tls=true&tlsCertificateKeyFile={}'.format(conf.database_certificate)
Expand Down
23 changes: 15 additions & 8 deletions beacon/connections/mongo/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@
from beacon.logs.logs import LOG


uri = "mongodb://{}:{}@{}:{}/{}?authSource={}".format(
conf.database_user,
conf.database_password,
conf.database_host,
conf.database_port,
conf.database_name,
conf.database_auth_source
)
if conf.database_cluster:
uri = "mongodb+srv://{}:{}@{}/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000".format(
conf.database_user,
conf.database_password,
conf.database_host
)
else:
uri = "mongodb://{}:{}@{}:{}/{}?authSource={}".format(
conf.database_user,
conf.database_password,
conf.database_host,
conf.database_port,
conf.database_name,
conf.database_auth_source
)

if os.path.isfile(conf.database_certificate):
uri += '&tls=true&tlsCertificateKeyFile={}'.format(conf.database_certificate)
Expand Down
23 changes: 15 additions & 8 deletions beacon/connections/mongo/reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
import os


uri = "mongodb://{}:{}@{}:{}/{}?authSource={}".format(
conf.database_user,
conf.database_password,
conf.database_host,
conf.database_port,
conf.database_name,
conf.database_auth_source
)
if conf.database_cluster:
uri = "mongodb+srv://{}:{}@{}/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000".format(
conf.database_user,
conf.database_password,
conf.database_host
)
else:
uri = "mongodb://{}:{}@{}:{}/{}?authSource={}".format(
conf.database_user,
conf.database_password,
conf.database_host,
conf.database_port,
conf.database_name,
conf.database_auth_source
)

if os.path.isfile(conf.database_certificate):
uri += '&tls=true&tlsCertificateKeyFile={}'.format(conf.database_certificate)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jsonschema-specifications==2023.12.1
loguru==0.7.2
pyyaml==6.0.1
dataclasses-json==0.5.6
pymongo==4.0.1
pymongo[srv]==4.0.1
coverage==7.6.0
requests==2.25.1
pydantic==2.6.2
Expand Down

0 comments on commit 7c1ded6

Please sign in to comment.