Skip to content

Commit 7f4433b

Browse files
sacca97copernico
authored andcommitted
added redis to config.yaml
1 parent 05c5376 commit 7f4433b

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

prospector/api/routers/jobs.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
from api.routers.nvd_feed_update import main
99
from git.git import do_clone
1010
from log.logger import logger
11+
from util.config_parser import parse_config_file
1112

12-
redis_url = os.environ["REDIS_URL"]
13+
config = parse_config_file()
14+
15+
16+
redis_url = config.redis_url
1317

1418
router = APIRouter(
1519
prefix="/jobs",

prospector/commitdb/postgres.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,31 @@ class PostgresCommitDB(CommitDB):
2828
"""
2929

3030
def __init__(self, user, password, host, port, dbname):
31-
self.connect_string = "postgresql://{}:{}@{}:{}/{}".format(
32-
user, password, host, port, dbname
33-
).lower()
31+
self.user = user
32+
self.password = password
33+
self.host = host
34+
self.port = port
35+
self.dbname = dbname
3436
self.connection = None
3537

3638
def connect(self):
37-
self.connection = psycopg2.connect(self.connect_string)
39+
try:
40+
self.connection = psycopg2.connect(
41+
database=self.dbname,
42+
user=self.user,
43+
password=self.password,
44+
host=self.host,
45+
port=self.port,
46+
)
47+
except Exception:
48+
self.host = "localhost"
49+
self.connection = psycopg2.connect(
50+
database=self.dbname,
51+
user=self.user,
52+
password=self.password,
53+
host=self.host,
54+
port=self.port,
55+
)
3856

3957
def lookup(self, repository: str, commit_id: str = None) -> List[Dict[str, Any]]:
4058
if not self.connection:

prospector/config-sample.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ database:
2727
port: 5432
2828
dbname: postgres
2929

30+
redis_url: redis://localhost:6379/0
31+
3032
# Report file format: "html", "json", "console" or "all"
3133
# and the file name
3234
report:

0 commit comments

Comments
 (0)