-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial commit on branch * removing mongoDB from docker-compose for now * serve participants credentials * tidy up by removing some comments * tweaks in response to code review * tweaks * remove duplicate text in README * adjust local run command to include mongo * update README to reflect CLI command * change find query to find_one, and exclude _id from result Co-authored-by: David <[email protected]>
- Loading branch information
1 parent
4cde61e
commit f1c6079
Showing
10 changed files
with
205 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,5 @@ requirements.txt | |
.nox | ||
|
||
# Possible remnants of local dev | ||
/api/docs | ||
/api/docs | ||
/dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import os | ||
from typing import Optional | ||
|
||
from dotenv import load_dotenv | ||
from pydantic.dataclasses import dataclass | ||
from pymongo import MongoClient | ||
|
||
load_dotenv() | ||
|
||
# setup mongodb connection | ||
myclient = MongoClient( | ||
host=[f"{os.getenv('_MONGO_HOST')}:27017"], | ||
username=os.getenv("_MONGO_INITDB_ROOT_USERNAME"), | ||
password=os.getenv("_MONGO_INITDB_ROOT_PASSWORD"), | ||
) | ||
mydb = myclient[os.getenv("_MONGO_INITDB_DATABASE")] | ||
mycol = mydb[os.getenv("_MONGO_INITDB_COLLECTION")] | ||
|
||
|
||
@dataclass | ||
class PatientsCredentials: | ||
"""Patient credentials""" | ||
|
||
patient_id: str | ||
dreem_email: str | ||
dreem_password: str | ||
wildkeys_email: str | ||
wildkeys_password: str | ||
tfa_email: str | ||
tfa_password: str | ||
|
||
|
||
def get_patients_credentials(the_id: str) -> Optional[PatientsCredentials]: | ||
"""Get credentials for one patient based on the ID""" | ||
myquery = {"patient_id": the_id} | ||
payload = mycol.find_one(myquery, {"_id": 0}) # exclude _id from result | ||
if payload: | ||
patient_credentials = PatientsCredentials(**payload) | ||
return patient_credentials | ||
else: | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
set -e | ||
|
||
mongo <<EOF | ||
use $MONGO_INITDB_DATABASE | ||
db.createUser({ | ||
user: '$MONGO_INITDB_ROOT_USERNAME', | ||
pwd: '$MONGO_INITDB_ROOT_PASSWORD', | ||
roles: [{ | ||
role: 'readWrite', | ||
db: '$MONGO_INITDB_DATABASE' | ||
}] | ||
}) | ||
EOF |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters