Skip to content

Commit ea65804

Browse files
Merge branch 'main' into feature/issue-469-opencre-mapanalysis
Signed-off-by: Bornunique911 <69379200+Bornunique911@users.noreply.github.com>
2 parents 445cbbd + 997c172 commit ea65804

130 files changed

Lines changed: 14077 additions & 1450 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ LOGIN_ALLOWED_DOMAINS=example.com
3838
# GCP
3939

4040
GCP_NATIVE=false
41+
GEMINI_API_KEY=your-gemini-api-key
42+
VERTEX_CHAT_MODEL=gemini-2.0-flash
43+
VERTEX_EMBED_CONTENT_MODEL=embedding-001
4144

4245
# Spreadsheet Auth
4346

.github/workflows/linter.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,29 @@ name: Lint Code Base
33

44
on: [push, pull_request]
55
jobs:
6+
frontend:
7+
name: Frontend Lint
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout Code
11+
uses: actions/checkout@v4
12+
- name: Setup Node
13+
uses: actions/setup-node@v4
14+
with:
15+
node-version: '20'
16+
cache: 'yarn'
17+
- name: Install frontend dependencies
18+
run: |
19+
for i in 1 2 3; do
20+
yarn install --frozen-lockfile --network-timeout 120000 && exit 0
21+
echo "yarn install failed (attempt $i/3), retrying..."
22+
sleep $((i * 10))
23+
done
24+
echo "yarn install failed after 3 attempts"
25+
exit 1
26+
- name: Check frontend formatting
27+
run: yarn prettier --check "application/frontend/src/**/*.{ts,tsx,js}"
28+
629
build:
730
name: Lint Code Base
831
runs-on: ubuntu-latest

.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,10 @@ yarn-error.log
66
cypress/videos
77
cypress/screenshots
88
venv/
9+
.venv/
10+
.mypy_cache/
11+
.pytest_cache/
12+
.cursor/
13+
tmp/
914
static/
1015
vendor/

Makefile

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ prod-run:
88
docker-neo4j-rm:
99
docker stop cre-neo4j
1010
docker rm -f cre-neo4j
11+
docker volume inspect cre_neo4j_data >/dev/null 2>&1 || docker volume create cre_neo4j_data
12+
docker volume inspect cre_neo4j_logs >/dev/null 2>&1 || docker volume create cre_neo4j_logs
1113
docker volume rm cre_neo4j_data
1214
docker volume rm cre_neo4j_logs
1315
# rm -rf .neo4j
@@ -23,6 +25,10 @@ docker-redis:
2325
docker start cre-redis-stack 2>/dev/null ||\
2426
docker run -d --name cre-redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack:latest
2527

28+
docker-postgres:
29+
docker start cre-postgres 2>/dev/null ||\
30+
docker run -d --name cre-postgres -e POSTGRES_PASSWORD=password -e POSTGRES_USER=cre -e POSTGRES_DB=cre -p 5432:5432 postgres
31+
2632
start-containers: docker-neo4j docker-redis
2733

2834
start-worker:
@@ -55,7 +61,7 @@ e2e:
5561
test:
5662
[ -d "./venv" ] && . ./venv/bin/activate &&\
5763
export FLASK_APP="$(CURDIR)/cre.py" &&\
58-
flask routes && flask test
64+
flask routes && python -m unittest discover -s application/tests -p "*_test.py"
5965

6066
cover:
6167
. ./venv/bin/activate && FLASK_APP=cre.py FLASK_CONFIG=testing flask test --cover
@@ -127,7 +133,35 @@ import-neo4j:
127133
[ -d "./venv" ] && . ./venv/bin/activate &&\
128134
export FLASK_APP="$(CURDIR)/cre.py" && python cre.py --populate_neo4j_db
129135

130-
preload-map-analysis:
131-
$(shell RUN_COUNT=5 bash ./scripts/preload_gap_analysis.sh)
136+
backfill-gap-analysis:
137+
RUN_COUNT=8 bash ./scripts/backfill_gap_analysis.sh
138+
139+
sync-gap-analysis-table-local:
140+
[ -d "./venv" ] && . ./venv/bin/activate &&\
141+
python scripts/sync_gap_analysis_table.py \
142+
--from-sqlite "$(CURDIR)/standards_cache.sqlite" \
143+
--to-postgres "postgresql://cre:password@127.0.0.1:5432/cre" \
144+
--require-local-destination
145+
146+
verify-ga-complete-prod:
147+
[ -d "./venv" ] && . ./venv/bin/activate &&\
148+
python scripts/verify_ga_completeness.py \
149+
--base-url "https://opencre.org" \
150+
--output-json "$(CURDIR)/tmp/prod-ga-completeness.json"
151+
152+
verify-ga-parity-local:
153+
@[ -d "./.venv" ] && . ./.venv/bin/activate || ([ -d "./venv" ] && . ./venv/bin/activate); \
154+
export CRE_CACHE_FILE="$${CRE_CACHE_FILE:-postgresql://cre:password@127.0.0.1:5432/cre}"; \
155+
export NEO4J_URL="$${NEO4J_URL:-bolt://neo4j:password@127.0.0.1:7687}"; \
156+
export PYTHONPATH="$(CURDIR)"; \
157+
python scripts/verify_ga_postgres_neo_parity.py --output-json "$(CURDIR)/tmp/local-ga-parity.json"
158+
159+
backfill-gap-analysis-sync:
160+
@[ -d "./.venv" ] && . ./.venv/bin/activate || ([ -d "./venv" ] && . ./venv/bin/activate); \
161+
export FLASK_APP="$(CURDIR)/cre.py"; \
162+
export CRE_CACHE_FILE="$${CRE_CACHE_FILE:-postgresql://cre:password@127.0.0.1:5432/cre}"; \
163+
export NEO4J_URL="$${NEO4J_URL:-bolt://neo4j:password@127.0.0.1:7687}"; \
164+
python cre.py --cache_file "$$CRE_CACHE_FILE" --populate_neo4j_db && \
165+
python cre.py --cache_file "$$CRE_CACHE_FILE" --ga_backfill_missing --ga_backfill_no_queue
132166

133167
all: clean lint test dev dev-run

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ Download the latest CRE graph from upstream by running:
6868
make upstream-sync
6969
```
7070

71-
Keep in mind that until [Issue #534](https://github.com/OWASP/OpenCRE/issues/534) is fixed you won't have access to gap analysis results locally.
71+
You can precompute local gap-analysis cache after imports with:
72+
73+
```bash
74+
make backfill-gap-analysis
75+
```
7276

7377
To run CRE locally then you can do:
7478

@@ -116,6 +120,21 @@ Some features like Gap Analysis require a neo4j DB running, you can start this w
116120
make docker-neo4j
117121
```
118122

123+
To run only missing gap-analysis pair backfill (without starting Flask), use:
124+
125+
```bash
126+
RUN_COUNT=8 bash scripts/backfill_gap_analysis.sh
127+
```
128+
129+
To sync local Postgres data into a Heroku app (staging or prod), use:
130+
131+
```bash
132+
APP_NAME=stagingopencreorg \
133+
SOURCE_DB_URL="postgresql://cre:password@127.0.0.1:5432/cre" \
134+
SYNC_TABLES=gap_analysis \
135+
bash scripts/push-local-postgres-to-heroku.sh --gap_analysis
136+
```
137+
119138
Environment variables for app to connect to neo4jDB (default):
120139

121140
* `NEO4J_URL` (neo4j//neo4j:password@localhost:7687)

application/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def create_app(mode: str = "production", conf: any = None) -> Any:
3131
app.config.from_object(config[mode])
3232
else:
3333
app.config.from_object(conf)
34+
if os.environ.get("SQLALCHEMY_DATABASE_URI"):
35+
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get(
36+
"SQLALCHEMY_DATABASE_URI"
37+
)
3438
GOOGLE_CLIENT_SECRET = os.environ.get("GOOGLE_CLIENT_SECRET")
3539
app.secret_key = GOOGLE_CLIENT_SECRET
3640
if os.environ.get("NO_LOGIN"):

0 commit comments

Comments
 (0)