From ce7e8ee95fe809ef9a5a2bdc857a2dace7c25f2b Mon Sep 17 00:00:00 2001 From: Kirill Chernakov Date: Sun, 24 Nov 2024 12:24:05 +0400 Subject: [PATCH] refactor: cleaner naming --- keep/api/core/db.py | 9 ++++----- keep/api/routes/preset.py | 4 ++-- keep/api/tasks/process_event_task.py | 6 +++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/keep/api/core/db.py b/keep/api/core/db.py index 844b88e1e..9be0d25f7 100644 --- a/keep/api/core/db.py +++ b/keep/api/core/db.py @@ -2616,7 +2616,7 @@ def get_presets( return presets -def get_preset_by_name(tenant_id: str, preset_name: str) -> Preset: +def get_db_preset_by_name(tenant_id: str, preset_name: str) -> Preset | None: with Session(engine) as session: preset = session.exec( select(Preset) @@ -2625,7 +2625,7 @@ def get_preset_by_name(tenant_id: str, preset_name: str) -> Preset: ).first() return preset -def get_all_presets(tenant_id: str) -> List[Preset]: +def get_db_presets(tenant_id: str) -> List[Preset]: with Session(engine) as session: presets = ( session.exec(select(Preset).where(Preset.tenant_id == tenant_id)) @@ -2634,9 +2634,8 @@ def get_all_presets(tenant_id: str) -> List[Preset]: ) return presets -# -def get_db_and_static_presets_dtos(tenant_id: str) -> List[PresetDto]: - presets = get_all_presets(tenant_id) +def get_all_presets_dtos(tenant_id: str) -> List[PresetDto]: + presets = get_db_presets(tenant_id) static_presets_dtos = list(STATIC_PRESETS.values()) return [PresetDto(**preset.to_dict()) for preset in presets] + static_presets_dtos diff --git a/keep/api/routes/preset.py b/keep/api/routes/preset.py index 1f3f9b22a..bd331806c 100644 --- a/keep/api/routes/preset.py +++ b/keep/api/routes/preset.py @@ -15,7 +15,7 @@ from sqlmodel import Session, select from keep.api.consts import PROVIDER_PULL_INTERVAL_DAYS, STATIC_PRESETS -from keep.api.core.db import get_preset_by_name as get_preset_by_name_db +from keep.api.core.db import get_db_preset_by_name from keep.api.core.db import get_presets as get_presets_db from keep.api.core.db import ( get_session, @@ -448,7 +448,7 @@ def get_preset_alerts( if preset_name in STATIC_PRESETS: preset = STATIC_PRESETS[preset_name] else: - preset = get_preset_by_name_db(tenant_id, preset_name) + preset = get_db_preset_by_name(tenant_id, preset_name) # if preset does not exist if not preset: raise HTTPException(404, "Preset not found") diff --git a/keep/api/tasks/process_event_task.py b/keep/api/tasks/process_event_task.py index c78ae6a47..80c0e680f 100644 --- a/keep/api/tasks/process_event_task.py +++ b/keep/api/tasks/process_event_task.py @@ -20,8 +20,8 @@ from keep.api.core.db import ( bulk_upsert_alert_fields, get_alerts_by_fingerprint, - get_all_presets, - get_db_and_static_presets_dtos, + get_db_presets, + get_all_presets_dtos, get_enrichment_with_session, get_session_sync, ) @@ -444,7 +444,7 @@ def __handle_formatted_events( return try: - presets = get_db_and_static_presets_dtos(tenant_id) + presets = get_all_presets_dtos(tenant_id) rules_engine = RulesEngine(tenant_id=tenant_id) presets_do_update = [] for preset_dto in presets: