Skip to content

Commit fc8acb8

Browse files
committed
delete ThreatImpact
1 parent ba98252 commit fc8acb8

File tree

10 files changed

+80
-90
lines changed

10 files changed

+80
-90
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""delete_threat_impact
2+
3+
Revision ID: 4912bc5835e5
4+
Revises: 884b692bb1e6
5+
Create Date: 2024-12-13 01:01:34.420806
6+
7+
"""
8+
9+
import sqlalchemy as sa
10+
from alembic import op
11+
12+
# revision identifiers, used by Alembic.
13+
revision = "4912bc5835e5"
14+
down_revision = "884b692bb1e6"
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade() -> None:
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.drop_column("topic", "threat_impact")
22+
# ### end Alembic commands ###
23+
24+
25+
def downgrade() -> None:
26+
# ### commands auto generated by Alembic - please adjust! ###
27+
op.add_column(
28+
"topic",
29+
sa.Column(
30+
"threat_impact",
31+
sa.INTEGER(),
32+
server_default=sa.text("3"),
33+
autoincrement=False,
34+
nullable=False,
35+
),
36+
)
37+
op.alter_column("topic", "threat_impact", server_default=None)
38+
# ### end Alembic commands ###

api/app/business/ssvc_business.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ def _sum_ssvc_priority_count(topic_ids: list[str], topic_ids_dict: dict, count_k
88
out_of_cycle = models.SSVCDeployerPriorityEnum.OUT_OF_CYCLE.value
99
scheduled = models.SSVCDeployerPriorityEnum.SCHEDULED.value
1010
defer = models.SSVCDeployerPriorityEnum.DEFER.value
11-
sum_threat_impact_count = {immediate: 0, out_of_cycle: 0, scheduled: 0, defer: 0}
11+
sum_ssvc_priority_count = {immediate: 0, out_of_cycle: 0, scheduled: 0, defer: 0}
1212
for topic_id in topic_ids:
1313
current_count = topic_ids_dict[topic_id][count_key]
14-
sum_threat_impact_count[immediate] += current_count[immediate]
15-
sum_threat_impact_count[out_of_cycle] += current_count[out_of_cycle]
16-
sum_threat_impact_count[scheduled] += current_count[scheduled]
17-
sum_threat_impact_count[defer] += current_count[defer]
18-
return sum_threat_impact_count
14+
sum_ssvc_priority_count[immediate] += current_count[immediate]
15+
sum_ssvc_priority_count[out_of_cycle] += current_count[out_of_cycle]
16+
sum_ssvc_priority_count[scheduled] += current_count[scheduled]
17+
sum_ssvc_priority_count[defer] += current_count[defer]
18+
return sum_ssvc_priority_count
1919

2020

2121
def get_topic_ids_summary_by_service_id_and_tag_id(
@@ -64,7 +64,7 @@ def get_topic_ids_summary_by_service_id_and_tag_id(
6464
tmp_topic_ids_dict["unsolved_ssvc_priority_count"][ssvc_priority.value] += 1
6565
tmp_topic_ids_dict["is_solved"] = False
6666

67-
# Sort topic_id according to threat_impact and updated_at
67+
# Sort topic_id according to highest_ssvc_priority and updated_at
6868
topic_ids_sorted = sorted(
6969
topic_ids_dict.values(),
7070
key=lambda x: (

api/app/command.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def search_topics_internal(
9595
offset: int = 0,
9696
limit: int = 10,
9797
sort_key: schemas.TopicSortKey = schemas.TopicSortKey.CVSS_V3_SCORE_DESC,
98-
threat_impacts: list[int] | None = None,
98+
cvss_v3_scores: list[float] | None = None,
9999
title_words: list[str | None] | None = None,
100100
abstract_words: list[str | None] | None = None,
101101
tag_ids: list[str | None] | None = None,
@@ -109,10 +109,10 @@ def search_topics_internal(
109109
pteam_id: UUID | None = None,
110110
) -> dict:
111111
# search conditions
112-
search_by_threat_impacts_stmt = (
112+
search_by_cvss_v3_scores_stmt = (
113113
true()
114-
if threat_impacts is None # do not filter by threat_impact
115-
else models.Topic.threat_impact.in_(threat_impacts)
114+
if cvss_v3_scores is None # do not filter by cvss_v3_score
115+
else models.Topic.cvss_v3_score.in_(cvss_v3_scores)
116116
)
117117
search_by_tag_ids_stmt = (
118118
true()
@@ -206,7 +206,7 @@ def search_topics_internal(
206206
)
207207

208208
search_conditions = [
209-
search_by_threat_impacts_stmt,
209+
search_by_cvss_v3_scores_stmt,
210210
search_by_tag_ids_stmt,
211211
search_by_misp_tag_ids_stmt,
212212
search_by_topic_ids_stmt,

api/app/models.py

-1
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,6 @@ def __init__(self, *args, **kwargs) -> None:
579579
topic_id: Mapped[StrUUID] = mapped_column(primary_key=True)
580580
title: Mapped[Str255]
581581
abstract: Mapped[str]
582-
threat_impact: Mapped[int]
583582
created_by: Mapped[StrUUID] = mapped_column(ForeignKey("account.user_id"), index=True)
584583
created_at: Mapped[datetime] = mapped_column(server_default=current_timestamp())
585584
updated_at: Mapped[datetime] = mapped_column(server_default=current_timestamp())

api/app/routers/topics.py

+9-19
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def search_topics(
5252
offset: int = Query(0, ge=0),
5353
limit: int = Query(10, ge=1, le=100), # 10 is default in web/src/pages/TopicManagement.jsx
5454
sort_key: schemas.TopicSortKey = Query(schemas.TopicSortKey.CVSS_V3_SCORE_DESC),
55-
threat_impacts: list[int] | None = Query(None),
55+
cvss_v3_scores: list[float] | None = Query(None),
5656
topic_ids: list[str] | None = Query(None),
5757
title_words: list[str] | None = Query(None),
5858
abstract_words: list[str] | None = Query(None),
@@ -70,7 +70,7 @@ def search_topics(
7070
"""
7171
Search topics by following parameters with sort and pagination.
7272
73-
- threat_impacts
73+
- cvss_v3_scores
7474
- title_words
7575
- abstract_words
7676
- tag_names
@@ -149,13 +149,13 @@ def search_topics(
149149
continue
150150
fixed_abstract_words.add(abstract_word)
151151

152-
fixed_threat_impacts: set[int] = set()
153-
if threat_impacts is not None:
154-
for threat_impact in threat_impacts:
152+
fixed_cvss_v3_scores: set[float] = set()
153+
if cvss_v3_scores is not None:
154+
for cvss_v3_score in cvss_v3_scores:
155155
try:
156-
int_val = int(threat_impact)
157-
if int_val in {1, 2, 3, 4}:
158-
fixed_threat_impacts.add(int_val)
156+
float_val = float(cvss_v3_score)
157+
if float_val <= 10.0 and float_val >= 0:
158+
fixed_cvss_v3_scores.add(float_val)
159159
except ValueError:
160160
pass
161161

@@ -164,7 +164,7 @@ def search_topics(
164164
offset=offset,
165165
limit=limit,
166166
sort_key=sort_key,
167-
threat_impacts=None if threat_impacts is None else list(fixed_threat_impacts),
167+
cvss_v3_scores=None if cvss_v3_scores is None else list(fixed_cvss_v3_scores),
168168
title_words=None if title_words is None else list(fixed_title_words),
169169
abstract_words=None if abstract_words is None else list(fixed_abstract_words),
170170
tag_ids=None if tag_names is None else list(fixed_tag_ids),
@@ -203,8 +203,6 @@ def create_topic(
203203
):
204204
"""
205205
Create a topic.
206-
- `threat_impact` : The value is in 1, 2, 3, 4.
207-
(immediate: 1, off-cycle: 2, acceptable: 3, none: 4)
208206
- `tags` : Optional. The default is an empty list.
209207
- `misp_tags` : Optional. The default is an empty list.
210208
- `actions` : Optional. The default is an empty list.
@@ -270,7 +268,6 @@ def create_topic(
270268
topic_id=str(topic_id),
271269
title=data.title,
272270
abstract=data.abstract,
273-
threat_impact=data.threat_impact,
274271
created_by=current_user.user_id,
275272
created_at=now,
276273
updated_at=now,
@@ -348,11 +345,6 @@ def update_topic(
348345
status_code=status.HTTP_400_BAD_REQUEST,
349346
detail="Cannot specify None for abstract",
350347
)
351-
if "threat_impact" in update_data.keys() and data.threat_impact is None:
352-
raise HTTPException(
353-
status_code=status.HTTP_400_BAD_REQUEST,
354-
detail="Cannot specify None for threat_impact",
355-
)
356348
if "tags" in update_data.keys() and data.tags is None:
357349
raise HTTPException(
358350
status_code=status.HTTP_400_BAD_REQUEST,
@@ -389,8 +381,6 @@ def update_topic(
389381
topic.title = data.title
390382
if data.abstract is not None:
391383
topic.abstract = data.abstract
392-
if data.threat_impact is not None:
393-
topic.threat_impact = data.threat_impact
394384
if data.exploitation is not None:
395385
previous_exploitation = topic.exploitation
396386
topic.exploitation = data.exploitation

api/app/schemas.py

+1-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from enum import Enum
33
from uuid import UUID
44

5-
from pydantic import BaseModel, ConfigDict, Field, field_validator
5+
from pydantic import BaseModel, ConfigDict, Field
66

77
from app.constants import DEFAULT_ALERT_SSVC_PRIORITY
88
from app.models import (
@@ -135,11 +135,6 @@ class MispTagResponse(ORMModel):
135135
tag_name: str
136136

137137

138-
def threat_impact_range(value):
139-
assert value is None or 0 < value <= 4, "Specify a threat_impact between 1 and 4"
140-
return value
141-
142-
143138
class TopicEntry(ORMModel):
144139
topic_id: UUID
145140
title: str
@@ -151,15 +146,12 @@ class Topic(TopicEntry):
151146
topic_id: UUID
152147
title: str
153148
abstract: str
154-
threat_impact: int
155149
created_by: UUID
156150
created_at: datetime
157151
exploitation: ExploitationEnum | None
158152
automatable: AutomatableEnum | None
159153
cvss_v3_score: float | None
160154

161-
_threat_impact_range = field_validator("threat_impact", mode="before")(threat_impact_range)
162-
163155

164156
class TopicResponse(Topic):
165157
tags: list[TagResponse]
@@ -207,29 +199,23 @@ class ActionUpdateRequest(ORMModel):
207199
class TopicCreateRequest(ORMModel):
208200
title: str
209201
abstract: str
210-
threat_impact: int
211202
tags: list[str] = []
212203
misp_tags: list[str] = []
213204
actions: list[ActionCreateRequest] = []
214205
exploitation: ExploitationEnum | None = None
215206
automatable: AutomatableEnum | None = None
216207
cvss_v3_score: float | None = None
217208

218-
_threat_impact_range = field_validator("threat_impact", mode="before")(threat_impact_range)
219-
220209

221210
class TopicUpdateRequest(ORMModel):
222211
title: str | None = None
223212
abstract: str | None = None
224-
threat_impact: int | None = None
225213
tags: list[str] | None = None
226214
misp_tags: list[str] | None = None
227215
exploitation: ExploitationEnum | None = None
228216
automatable: AutomatableEnum | None = None
229217
cvss_v3_score: float | None = None
230218

231-
_threat_impact_range = field_validator("threat_impact", mode="before")(threat_impact_range)
232-
233219

234220
class PTeamInfo(PTeamEntry):
235221
alert_slack: Slack

api/app/tests/medium/constants.py

-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
"topic_id": uuid4(),
6262
"title": "topic one",
6363
"abstract": "abstract one",
64-
"threat_impact": 1,
6564
"tags": [TAG1],
6665
"misp_tags": [MISPTAG1],
6766
"actions": [],
@@ -73,7 +72,6 @@
7372
"topic_id": uuid4(),
7473
"title": "topic two",
7574
"abstract": "abstract two",
76-
"threat_impact": 2,
7775
"tags": [TAG1],
7876
"misp_tags": [],
7977
"actions": [],
@@ -84,7 +82,6 @@
8482
"topic_id": uuid4(),
8583
"title": "topic three",
8684
"abstract": "abstract three",
87-
"threat_impact": 1,
8885
"tags": [TAG1, TAG3],
8986
"misp_tags": [],
9087
"actions": [],
@@ -95,7 +92,6 @@
9592
"topic_id": uuid4(),
9693
"title": "topic four",
9794
"abstract": "abstract four",
98-
"threat_impact": 2,
9995
"tags": [TAG3],
10096
"misp_tags": [],
10197
"actions": [],

0 commit comments

Comments
 (0)