-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
44 lines (39 loc) · 1.27 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from pydantic import BaseModel, AnyUrl
from typing import List
from pymongo import MongoClient
import os
def connect_db():
'''
This function connects to the database and returns the collection
'''
# Connect to the database
# variables come from .env file
mongoHost = os.getenv('MONGO_HOST', default='localhost')
mongoPort = os.getenv('MONGO_PORT', default='27017')
mongoUser = os.getenv('MONGO_USER')
mongoPass = os.getenv('MONGO_PWD')
mongoAuthSrc = os.getenv('MONGO_AUTH_SRC')
mongoDb = os.getenv('MONGO_DB')
mongoCollection = os.getenv('MONGO_COLLECTION',)
# Connect to MongoDB
mongoClient = MongoClient(
host=mongoHost,
port=int(mongoPort),
username=mongoUser,
password=mongoPass,
authSource=mongoAuthSrc,
)
db = mongoClient[mongoDb]
collection = db[mongoCollection]
print(f"Connected to MongoDB at {mongoHost}:{mongoPort} as {mongoUser} on database {mongoDb} and collection {mongoCollection}")
return collection
class License(BaseModel):
# from SPDX model https://spdx.org/licenses/:
reference: AnyUrl
licenseId: str
name: str
isOsiApproved: bool
isDeprecatedLicenseId: bool
seeAlso: List[AnyUrl]
# custom fields:
synonyms: List[str] = []