Skip to content

Commit f146321

Browse files
sacca97copernico
authored andcommitted
updated backend to fully use config.yaml
1 parent eba85f5 commit f146321

File tree

11 files changed

+58
-35
lines changed

11 files changed

+58
-35
lines changed

prospector/.env-sample

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ POSTGRES_PASSWORD=example
1919
REDIS_URL=redis://localhost:6379/0
2020
NVD_API_KEY=yourNvdApiKey
2121
PYTHONPATH=.
22-
GITHUB_TOKEN=yourGithubApiToken

prospector/Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ docker-clean:
3131
@docker-compose down --rmi all -v 2>/dev/null
3232
@echo "$(DONE) Stopped and removed all container and images"
3333

34-
# @echo "$(PROGRESS) Cleaning volumes"
35-
# @docker volume prune -f
36-
# @echo "$(DONE) Cleaned volumes"
34+
@echo "$(PROGRESS) Cleaning volumes"
35+
@docker volume prune -f
36+
@echo "$(DONE) Cleaned volumes"
3737

38-
# @echo "$(PROGRESS) Cleaning residue"
39-
# @docker system prune -a -f
40-
# @echo "$(DONE) Cleaned residue"
38+
@echo "$(PROGRESS) Cleaning residue"
39+
@docker system prune -a -f
40+
@echo "$(DONE) Cleaned residue"
4141

4242

4343
clean:

prospector/api/routers/preprocessed.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
from fastapi.responses import JSONResponse
55

66
from commitdb.postgres import PostgresCommitDB
7+
from util.config_parser import parse_config_file
8+
9+
config = parse_config_file()
10+
711

812
router = APIRouter(
913
prefix="/commits",
@@ -18,7 +22,13 @@ async def get_commits(
1822
repository_url: str,
1923
commit_id: Optional[str] = None,
2024
):
21-
db = PostgresCommitDB()
25+
db = PostgresCommitDB(
26+
config.database.user,
27+
config.database.password,
28+
config.database.host,
29+
config.database.port,
30+
config.database.dbname,
31+
)
2232
db.connect()
2333
data = db.lookup(repository_url, commit_id)
2434

@@ -32,7 +42,13 @@ async def get_commits(
3242
@router.post("/")
3343
async def upload_preprocessed_commit(payload: List[Dict[str, Any]]):
3444

35-
db = PostgresCommitDB()
45+
db = PostgresCommitDB(
46+
config.database.user,
47+
config.database.password,
48+
config.database.host,
49+
config.database.port,
50+
config.database.dbname,
51+
)
3652
db.connect()
3753

3854
for commit in payload:

prospector/client/cli/prospector_client_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import pytest
44

5-
from commitdb.postgres import PostgresCommitDB
6-
75
from .prospector_client import prospector
86

97
OPENCAST_CVE = "CVE-2021-21318"

prospector/commitdb/commitdb_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
@pytest.fixture
88
def setupdb():
9-
db = PostgresCommitDB()
9+
db = PostgresCommitDB("postgres", "example", "localhost", "5432", "postgres")
1010
db.connect()
1111
# db.reset()
1212
return db

prospector/commitdb/postgres.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
from commitdb import CommitDB
1313
from log.logger import logger
1414

15-
DB_CONNECT_STRING = "postgresql://{}:{}@{}:{}/{}".format(
16-
os.getenv("POSTGRES_USER", "postgres"),
17-
os.getenv("POSTGRES_PASSWORD", "example"),
18-
os.getenv("POSTGRES_HOST", "localhost"),
19-
os.getenv("POSTGRES_PORT", "5432"),
20-
os.getenv("POSTGRES_DBNAME", "postgres"),
21-
).lower()
15+
# DB_CONNECT_STRING = "postgresql://{}:{}@{}:{}/{}".format(
16+
# os.getenv("POSTGRES_USER", "postgres"),
17+
# os.getenv("POSTGRES_PASSWORD", "example"),
18+
# os.getenv("POSTGRES_HOST", "localhost"),
19+
# os.getenv("POSTGRES_PORT", "5432"),
20+
# os.getenv("POSTGRES_DBNAME", "postgres"),
21+
# ).lower()
2222

2323

2424
class PostgresCommitDB(CommitDB):
@@ -27,12 +27,14 @@ class PostgresCommitDB(CommitDB):
2727
for PostgreSQL
2828
"""
2929

30-
def __init__(self):
31-
self.connect_string = ""
30+
def __init__(self, user, password, host, port, dbname):
31+
self.connect_string = "postgresql://{}:{}@{}:{}/{}".format(
32+
user, password, host, port, dbname
33+
).lower()
3234
self.connection = None
3335

34-
def connect(self, connect_string=DB_CONNECT_STRING):
35-
self.connection = psycopg2.connect(connect_string)
36+
def connect(self):
37+
self.connection = psycopg2.connect(self.connect_string)
3638

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

prospector/config-sample.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ use_backend: optional
2020
# Optional backend info to save/use already preprocessed data
2121
backend: http://localhost:8000
2222

23+
database:
24+
user: postgres
25+
password: example
26+
host: db
27+
port: 5432
28+
dbname: postgres
29+
2330
# Report file format: "html", "json", "console" or "all"
2431
# and the file name
2532
report:

prospector/docker-compose.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ services:
1111
- redis
1212
- db
1313
environment:
14-
GIT_CACHE: /tmp
14+
GIT_CACHE: /tmp/gitcache
1515
CVE_DATA_PATH: /app/cve_data
1616
REDIS_URL: redis://redis:6379/0
17-
POSTGRES_HOST: db
18-
POSTGRES_PORT: 5432
19-
POSTGRES_USER: postgres
20-
POSTGRES_PASSWORD: example
21-
POSTGRES_DBNAME: postgres
22-
NVD_API_KEY: ${NVD_API_KEY}
17+
#POSTGRES_HOST: db
18+
#POSTGRES_PORT: 5432
19+
#POSTGRES_USER: postgres
20+
#POSTGRES_PASSWORD: example
21+
#POSTGRES_DBNAME: postgres
22+
#NVD_API_KEY: ${NVD_API_KEY}
2323

2424
worker:
2525
build:
@@ -41,7 +41,7 @@ services:
4141
ports:
4242
- "5432:5432"
4343
environment:
44-
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
44+
POSTGRES_PASSWORD: example #${POSTGRES_PASSWORD}
4545
volumes:
4646
- ./ddl:/docker-entrypoint-initdb.d
4747

prospector/docker/api/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ ENV PYTHONPATH .
1414
RUN rm -rf /app/rules
1515
RUN mkdir /app/cve_data
1616

17-
CMD ["./start.sh"]
17+
CMD ["python","./main.py"]

prospector/docker/api/start.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /usr/bin/env sh
22

3-
python api/routers/nvd_feed_update.py
4-
echo "NVD feed download complete"
3+
# python api/routers/nvd_feed_update.py
4+
# echo "NVD feed download complete"
55

6-
python main.py
6+
python main.py

0 commit comments

Comments
 (0)