Skip to content

Commit d114ec9

Browse files
authored
Add FastAPI for SsvcObjectRegistry, including docker container. Also convert package management to uv (#893)
2 parents 328620a + dfafbe2 commit d114ec9

Some content is hidden

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

60 files changed

+12391
-6069
lines changed

.github/workflows/link_checker.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,14 @@ jobs:
2929

3030
- name: Install dependencies
3131
run: |
32-
python -m pip install --upgrade pip
33-
python -m pip install -r requirements.txt
34-
python -m pip install linkchecker
35-
36-
- name: Install our python stuff
37-
run: |
38-
python -m pip install -e src
32+
python -m pip install --upgrade pip uv
33+
uv sync --dev --project src
3934
4035
- name: Build Site
4136
run: |
42-
mkdocs build --verbose --clean --config-file mkdocs.yml
37+
uv run --project=src mkdocs build --verbose --clean --config-file mkdocs.yml
4338
4439
- name: Check links
4540
run: |
46-
linkchecker site/index.html
41+
uv run --project=src linkchecker site/index.html
4742

.github/workflows/python-app.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@ jobs:
2727
python-version: "3.12"
2828
- name: Install dependencies
2929
run: |
30-
python -m pip install --upgrade pip
31-
pip install pytest build
32-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
30+
python -m pip install --upgrade pip uv
31+
uv sync --project=src --dev --frozen
32+
# pip install pytest build
33+
# if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
3334
# - uses: psf/black@stable
3435
- name: Test with pytest
3536
run: |
36-
pytest
37+
uv run --project=src pytest
3738
- name: Build
3839
run: |
39-
python -m build src
40+
uv build --project=src
4041
- name: Upload Artifacts
4142
uses: actions/upload-artifact@v4
4243
with:

Makefile

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,56 @@
11
# Project-specific vars
22
MKDOCS_PORT=8765
33
DOCKER_DIR=docker
4+
PROJECT_DIR = ./src
5+
DOCKER_COMPOSE=docker-compose --project-directory $(DOCKER_DIR)
6+
UV_RUN=uv run --project $(PROJECT_DIR)
47

58
# Targets
6-
.PHONY: all test docs docker_test clean help mdlint_fix up down regenerate_json
9+
.PHONY: all test docs api docker_test clean help mdlint_fix up down regenerate_json
10+
711

812
all: help
913

14+
dev:
15+
@echo "Set up dev environment..."
16+
uv sync --dev --project $(PROJECT_DIR)
17+
1018
mdlint_fix:
1119
@echo "Running markdownlint..."
1220
markdownlint --config .markdownlint.yml --fix .
1321

1422
test:
1523
@echo "Running tests locally..."
16-
pytest -v src/test
24+
uv run --project $(PROJECT_DIR) pytest -v
1725

1826
docker_test:
1927
@echo "Building the latest test image..."
20-
pushd $(DOCKER_DIR) && docker-compose build test
28+
$(DOCKER_COMPOSE) build test
2129
@echo "Running tests in Docker..."
22-
pushd $(DOCKER_DIR) && docker-compose run --rm test
30+
$(DOCKER_COMPOSE) run --rm test
31+
32+
docs_local:
33+
@echo "Building and running docs locally..."
34+
$(UV_RUN) mkdocs serve
2335

2436
docs:
2537
@echo "Building and running docs in Docker..."
26-
pushd $(DOCKER_DIR) && docker-compose up docs
38+
$(DOCKER_COMPOSE) up docs
39+
40+
api:
41+
@echo "Building and running API in Docker..."
42+
$(DOCKER_COMPOSE) up api
43+
44+
api_dev:
45+
$(UV_RUN) uvicorn ssvc.api.main:app --reload
2746

2847
up:
2948
@echo "Starting Docker services..."
30-
pushd $(DOCKER_DIR) && docker-compose up -d
49+
$(DOCKER_COMPOSE) up -d
3150

3251
down:
3352
@echo "Stopping Docker services..."
34-
pushd $(DOCKER_DIR) && docker-compose down
53+
$(DOCKER_COMPOSE) down
3554

3655
regenerate_json:
3756
@echo "Regenerating JSON files..."
@@ -40,20 +59,30 @@ regenerate_json:
4059

4160
clean:
4261
@echo "Cleaning up Docker resources..."
43-
pushd $(DOCKER_DIR) && docker-compose down --rmi local || true
44-
62+
$(DOCKER_COMPOSE) down --rmi local || true
63+
rm -rf $(PROJECT_DIR)/.venv $(PROJECT_DIR)/uv.lock
4564
help:
4665
@echo "Usage: make [target]"
4766
@echo ""
4867
@echo "Targets:"
4968
@echo " all - Display this help message"
69+
70+
@echo " dev - Set up development environment"
5071
@echo " mdlint_fix - Run markdownlint with fix"
5172
@echo " test - Run tests locally"
5273
@echo " docker_test - Run tests in Docker"
74+
5375
@echo " docs - Build and run documentation in Docker"
76+
@echo " docs_local - Build and run documentation locally"
77+
78+
@echo " api - Build and run API in Docker"
79+
@echo " api_dev - Run API locally with auto-reload"
80+
5481
@echo " up - Start Docker services"
5582
@echo " down - Stop Docker services"
83+
5684
@echo " regenerate_json - Regenerate JSON files from python modules"
85+
5786
@echo " clean - Clean up Docker resources"
5887
@echo " help - Display this help message"
5988

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"namespace": "x_com.yahooinc#prioritized-risk-remediation",
3+
"key": "PARANOIDS",
4+
"version": "1.0.0",
5+
"name": "theParanoids",
6+
"description": "PrioritizedRiskRemediation outcome group based on TheParanoids.",
7+
"schemaVersion": "2.0.0",
8+
"values": [
9+
{
10+
"key": "5",
11+
"name": "Track 5",
12+
"description": "Track"
13+
},
14+
{
15+
"key": "4",
16+
"name": "Track Closely 4",
17+
"description": "Track Closely"
18+
},
19+
{
20+
"key": "3",
21+
"name": "Attend 3",
22+
"description": "Attend"
23+
},
24+
{
25+
"key": "2",
26+
"name": "Attend 2",
27+
"description": "Attend"
28+
},
29+
{
30+
"key": "1",
31+
"name": "Act 1",
32+
"description": "Act"
33+
},
34+
{
35+
"key": "0",
36+
"name": "Act ASAP 0",
37+
"description": "Act ASAP"
38+
}
39+
]
40+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"namespace": "ssvc",
3+
"key": "DT_PSI",
4+
"version": "1.0.0",
5+
"name": "Public Safety Impact",
6+
"description": "Public Safety Impact Decision Table",
7+
"schemaVersion": "2.0.0",
8+
"decision_points": {
9+
"ssvc:SI:2.0.0": {
10+
"namespace": "ssvc",
11+
"key": "SI",
12+
"version": "2.0.0",
13+
"name": "Safety Impact",
14+
"description": "The safety impact of the vulnerability. (based on IEC 61508)",
15+
"schemaVersion": "2.0.0",
16+
"values": [
17+
{
18+
"key": "N",
19+
"name": "Negligible",
20+
"description": "Any one or more of these conditions hold.<br/><br/>- *Physical harm*: Minor injuries at worst (IEC 61508 Negligible).<br/>- *Operator resiliency*: Requires action by system operator to maintain safe system state as a result of exploitation of the vulnerability where operator actions would be well within expected operator abilities; OR causes a minor occupational safety hazard.<br/>- *System resiliency*: Small reduction in built-in system safety margins; OR small reduction in system functional capabilities that support safe operation.<br/>- *Environment*: Minor externalities (property damage, environmental damage, etc.) imposed on other parties.<br/>- *Financial*: Financial losses, which are not readily absorbable, to multiple persons.<br/>- *Psychological*: Emotional or psychological harm, sufficient to be cause for counselling or therapy, to multiple persons."
21+
},
22+
{
23+
"key": "M",
24+
"name": "Marginal",
25+
"description": "Any one or more of these conditions hold.<br/><br/>- *Physical harm*: Major injuries to one or more persons (IEC 61508 Marginal).<br/>- *Operator resiliency*: Requires action by system operator to maintain safe system state as a result of exploitation of the vulnerability where operator actions would be within their capabilities but the actions require their full attention and effort; OR significant distraction or discomfort to operators; OR causes significant occupational safety hazard.<br/>- *System resiliency*: System safety margin effectively eliminated but no actual harm; OR failure of system functional capabilities that support safe operation.<br/>- *Environment*: Major externalities (property damage, environmental damage, etc.) imposed on other parties.<br/>- *Financial*: Financial losses that likely lead to bankruptcy of multiple persons.<br/>- *Psychological*: Widespread emotional or psychological harm, sufficient to be cause for counselling or therapy, to populations of people."
26+
},
27+
{
28+
"key": "R",
29+
"name": "Critical",
30+
"description": "Any one or more of these conditions hold.<br/><br/>- *Physical harm*: Loss of life (IEC 61508 Critical).<br/>- *Operator resiliency*: Actions that would keep the system in a safe state are beyond system operator capabilities, resulting in adverse conditions; OR great physical distress to system operators such that they cannot be expected to operate the system properly.<br/>- *System resiliency*: Parts of the cyber-physical system break; system’s ability to recover lost functionality remains intact.<br/>- *Environment*: Serious externalities (threat to life as well as property, widespread environmental damage, measurable public health risks, etc.) imposed on other parties.<br/>- *Financial*: Socio-technical system (elections, financial grid, etc.) of which the affected component is a part is actively destabilized and enters unsafe state.<br/>- *Psychological*: N/A."
31+
},
32+
{
33+
"key": "C",
34+
"name": "Catastrophic",
35+
"description": "Any one or more of these conditions hold.<br/><br/>- *Physical harm*: Multiple loss of life (IEC 61508 Catastrophic).<br/>- *Operator resiliency*: Operator incapacitated (includes fatality or otherwise incapacitated).<br/>- *System resiliency*: Total loss of whole cyber-physical system, of which the software is a part.<br/>- *Environment*: Extreme externalities (immediate public health threat, environmental damage leading to small ecosystem collapse, etc.) imposed on other parties.<br/>- *Financial*: Social systems (elections, financial grid, etc.) supported by the software collapse.<br/>- *Psychological*: N/A."
36+
}
37+
]
38+
},
39+
"ssvc:PSI:2.0.1": {
40+
"namespace": "ssvc",
41+
"key": "PSI",
42+
"version": "2.0.1",
43+
"name": "Public Safety Impact",
44+
"description": "A coarse-grained representation of impact to public safety.",
45+
"schemaVersion": "2.0.0",
46+
"values": [
47+
{
48+
"key": "M",
49+
"name": "Minimal",
50+
"description": "Safety Impact:Negligible"
51+
},
52+
{
53+
"key": "S",
54+
"name": "Significant",
55+
"description": "Safety Impact:(Marginal OR Critical OR Catastrophic)"
56+
}
57+
]
58+
}
59+
},
60+
"outcome": "ssvc:PSI:2.0.1",
61+
"mapping": [
62+
{
63+
"ssvc:SI:2.0.0": "N",
64+
"ssvc:PSI:2.0.1": "M"
65+
},
66+
{
67+
"ssvc:SI:2.0.0": "M",
68+
"ssvc:PSI:2.0.1": "S"
69+
},
70+
{
71+
"ssvc:SI:2.0.0": "R",
72+
"ssvc:PSI:2.0.1": "S"
73+
},
74+
{
75+
"ssvc:SI:2.0.0": "C",
76+
"ssvc:PSI:2.0.1": "S"
77+
}
78+
]
79+
}

0 commit comments

Comments
 (0)