- Notifications
You must be signed in to change notification settings - Fork33
linter issues fix#41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
3 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletiontranslator/Dockerfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
39 changes: 15 additions & 24 deletionstranslator/app/routers/assistance.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,46 +1,37 @@ | ||
| import json | ||
| import os | ||
| from collections.abc import Generator | ||
| from contextlib import asynccontextmanager | ||
| from datetime import datetime | ||
| from fastapi import APIRouter, FastAPI | ||
| from app.translator.core.mitre import MitreConfig | ||
| from const import ROOT_PROJECT_PATH | ||
| assistance_router = APIRouter() | ||
| suggestions = {} | ||
| @asynccontextmanager | ||
| async def lifespan(app: FastAPI) -> Generator[None, None, None]: # noqa: ARG001 | ||
| MitreConfig().update_mitre_config() | ||
| with open(os.path.join(ROOT_PROJECT_PATH, "app/dictionaries/uncoder_meta_info_roota.json")) as file: | ||
| suggestions["roota"] = json.load(file) | ||
| with open(os.path.join(ROOT_PROJECT_PATH, "app/dictionaries/uncoder_meta_info_sigma.json")) as file: | ||
| suggestions["sigma"] = json.load(file) | ||
| yield | ||
| @assistance_router.get("/suggestions/{parser_id}", tags=["assistance"], description="Get suggestions") | ||
| async def get_suggestions(parser_id: str) -> list[dict]: | ||
| parser_dict = suggestions.get(parser_id, []) | ||
| if parser_id =="roota": | ||
| today = datetime.today().strftime("%Y-%m-%d") | ||
| for i in parser_dict: | ||
| if i["title"] =="Date": | ||
| for v in i["dictionary"]: | ||
| v["name"] = today | ||
| return parser_dict | ||
| return parser_dict |
60 changes: 31 additions & 29 deletionstranslator/app/routers/ioc_translate.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,46 +1,48 @@ | ||
| from typing import Optional | ||
| from fastapi import APIRouter, Body | ||
| from app.models.ioc_translation import CTIPlatform, OneTranslationCTIData | ||
| from app.models.translation import InfoMessage | ||
| from app.translator.cti_translator import CTIConverter | ||
| from app.translator.tools.const import HashType, IocParsingRule, IOCType | ||
| iocs_router = APIRouter() | ||
| converter = CTIConverter() | ||
| @iocs_router.post("/iocs/translate", description="Parse IOCs from text.") | ||
| @iocs_router.post("/iocs/translate", include_in_schema=False) | ||
| def parse_and_translate_iocs( | ||
| text: str = Body(..., description="Text to parse IOCs from", embed=True), | ||
| iocs_per_query: int = Body(25, description="Platforms to parse IOCs to", embed=True), | ||
| platform: CTIPlatform = Body(..., description="Platforms to parse IOCs to", embed=True), | ||
| include_ioc_types: Optional[list[IOCType]] = Body( | ||
| None, description="List of IOC types to include. By default all types are enabled.", embed=True | ||
| ), | ||
| include_hash_types: Optional[list[HashType]] = Body( | ||
| None, description="List of hash types to include. By default all hash types are enabled.", embed=True | ||
| ), | ||
| exceptions: Optional[list[str]] = Body( | ||
| None, description="List of exceptions. IOC is ignored if it contains one of exception values.", embed=True | ||
| ), | ||
| ioc_parsing_rules: Optional[list[IocParsingRule]] = Body( | ||
| None, embed=True, description="Additional parsing parameters." | ||
| ), | ||
| include_source_ip: Optional[bool] = Body(False, description="Include source IP in query. By default it is false."), | ||
| ) -> OneTranslationCTIData: | ||
| status, translations = converter.convert( | ||
| text=text, | ||
| platform_data=platform, | ||
| iocs_per_query=iocs_per_query, | ||
| include_ioc_types=include_ioc_types, | ||
| include_hash_types=include_hash_types, | ||
| exceptions=exceptions, | ||
| ioc_parsing_rules=ioc_parsing_rules, | ||
| include_source_ip=include_source_ip, | ||
| ) | ||
| if status: | ||
| return OneTranslationCTIData(status=status, translations=translations, target_siem_type=platform.name) | ||
| info_message = InfoMessage(message=translations, severity="error") | ||
| return OneTranslationCTIData(info=info_message, status=status, target_siem_type=platform.name) |
105 changes: 47 additions & 58 deletionstranslator/app/routers/translate.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,101 +1,90 @@ | ||
| from fastapi import APIRouter, Body | ||
| from app.models.translation importConvertorPlatforms, InfoMessage, OneTranslationData, Platform | ||
| from app.translator.cti_translator import CTIConverter | ||
| from app.translator.translator importSiemConverter | ||
| st_router = APIRouter() | ||
| converter = SiemConverter() | ||
| @st_router.post("/translate", tags=["siem_translate"], description="Generate target translation") | ||
| @st_router.post("/translate/", include_in_schema=False) | ||
| def generate_one_translation( | ||
| source_siem: str = Body(..., embed=True), | ||
| source_scheme: str = Body(None, embed=True), # noqa: ARG001 | ||
| target_siem: str = Body(..., embed=True), | ||
| target_scheme: str = Body(None, embed=True), # noqa: ARG001 | ||
| text: str = Body(..., embed=True), | ||
| ) -> OneTranslationData: | ||
| status, data = converter.generate_translation(text=text, source=source_siem, target=target_siem) | ||
| if status: | ||
| return OneTranslationData(status=status, translation=data, target_siem_type=target_siem) | ||
| info_message = InfoMessage(message=data, severity="error") | ||
| return OneTranslationData(info=info_message, status=status, target_siem_type=target_siem) | ||
| @st_router.post("/translate/all", tags=["siem_translate"], description="Generate all translations") | ||
| @st_router.post("/translate/all/", include_in_schema=False) | ||
| def generate_all_translations( | ||
| source_siem: str = Body(..., embed=True), | ||
| source_scheme: str = Body(None, embed=True), # noqa: ARG001 | ||
| text: str = Body(..., embed=True), | ||
| ) -> list[OneTranslationData]: | ||
| result = converter.generate_all_translation(text=text, source=source_siem) | ||
| translations = [] | ||
| for siem_result in result: | ||
| if siem_result.get("status"): | ||
| translations.append( | ||
| OneTranslationData( | ||
| status=siem_result.get("status", True), | ||
| translation=siem_result.get("result"), | ||
| target_siem_type=siem_result.get("siem_type"), | ||
| ) | ||
| ) | ||
| else: | ||
| translations.append( | ||
| OneTranslationData( | ||
| status=siem_result.get("status", False), | ||
| info=InfoMessage(message=siem_result.get("result"), severity="error"), | ||
| target_siem_type=siem_result.get("siem_type"), | ||
| ) | ||
| ) | ||
| return translations | ||
| @st_router.get("/platforms", tags=["siem_translate"], description="Get translator platforms") | ||
| @st_router.get("/platforms/", include_in_schema=False) | ||
| def get_convertor_platforms() -> ConvertorPlatforms: | ||
| renders, parsers = converter.get_all_platforms() | ||
| return ConvertorPlatforms(renders=renders, parsers=parsers) | ||
| @st_router.get("/all_platforms", description="Get Sigma, RootA and iocs platforms") | ||
| @st_router.get("/all_platforms/", include_in_schema=False) | ||
| def get_all_platforms() -> list: | ||
| converter_renders, converter_platforms = converter.get_all_platforms() | ||
| return [ | ||
| Platform( | ||
| id="roota", | ||
| name="RootA", | ||
| code="roota", | ||
| group_name="RootA", | ||
| group_id="roota", | ||
| renders=converter_renders, | ||
| parsers=converter_platforms, | ||
| ), | ||
| Platform( | ||
| id="sigma", | ||
| name="Sigma", | ||
| code="sigma", | ||
| group_name="Sigma", | ||
| group_id="sigma", | ||
| renders=[render for render in converter_renders if render.code != "sigma"], | ||
| ), | ||
| Platform( | ||
| id="ioc", name="IOCs", code="ioc", group_name="IOCs", group_id="ioc", renders=CTIConverter().get_renders() | ||
| ), | ||
| ] |
4 changes: 2 additions & 2 deletionstranslator/app/translator/const.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| from os.path import abspath, dirname | ||
| from typing import Union | ||
| APP_PATH = dirname(abspath(__file__)) | ||
| CTI_MIN_LIMIT_QUERY = 10000 | ||
| CTI_IOCS_PER_QUERY_LIMIT = 25 | ||
| DEFAULT_VALUE_TYPE = Union[int, str,list[int],list[str]] |
8 changes: 8 additions & 0 deletionstranslator/app/translator/core/custom_types/meta_info.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from app.translator.tools.custom_enum import CustomEnum | ||
| class SeverityType(CustomEnum): | ||
| critical = "critical" | ||
| high = "high" | ||
| medium = "medium" | ||
| low = "low" |
10 changes: 5 additions & 5 deletionstranslator/app/translator/core/escape_manager.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.