11import logging
22from typing import Dict , List
33
4- from app .translator .const import CTI_MIN_LIMIT_QUERY
4+ from app .translator .const import CTI_MIN_LIMIT_QUERY , CTI_IOCS_PER_QUERY_LIMIT
55from app .translator .core .models .iocs import IocsChunkValue
66from app .translator .core .parser_cti import CTIParser , Iocs
77from app .translator .core .render_cti import RenderCTI
@@ -17,44 +17,46 @@ def __init__(self):
1717 self .logger = logging .getLogger ("cti_converter" )
1818 self .parser = CTIParser ()
1919
20- def _get_render_mapping (self , platform : CTIPlatform , include_source_ip : bool = False ) -> Dict [str , str ]:
21- return self .renders .get (platform .name ).default_mapping
22-
2320 @handle_translation_exceptions
24- def __parse_iocs_from_string (self , text : str , include_ioc_types : list = None , include_hash_types : list = None ,
25- exceptions : list = None , ioc_parsing_rules : list = None ) -> Iocs :
21+ def __parse_iocs_from_string (self , text : str ,
22+ include_ioc_types : list = None ,
23+ include_hash_types : list = None ,
24+ exceptions : list = None ,
25+ ioc_parsing_rules : list = None ,
26+ include_source_ip : bool = False ) -> dict :
2627 return self .parser .get_iocs_from_string (string = text ,
2728 include_ioc_types = include_ioc_types ,
2829 include_hash_types = include_hash_types ,
2930 exceptions = exceptions ,
3031 ioc_parsing_rules = ioc_parsing_rules ,
31- limit = CTI_MIN_LIMIT_QUERY )
32+ limit = CTI_MIN_LIMIT_QUERY ,
33+ include_source_ip = include_source_ip )
3234
3335 @handle_translation_exceptions
34- def __render_translation (self , parsed_data : dict , platform_data : CTIPlatform , iocs_per_query : int ,
35- include_source_ip : bool = False ) -> List [str ]:
36- mapping = self ._get_render_mapping (platform = platform_data , include_source_ip = include_source_ip )
36+ def __render_translation (self , parsed_data : dict , platform_data : CTIPlatform , iocs_per_query : int ) -> List [str ]:
3737 platform = self .renders .get (platform_data .name )
3838 platform_generation = self .generate (data = parsed_data , platform = platform , iocs_per_query = iocs_per_query ,
39- mapping = mapping )
39+ mapping = platform . default_mapping )
4040 return platform_generation
4141
4242 def convert (self , text : str ,
4343 platform_data : CTIPlatform ,
44- iocs_per_query : int = 25 ,
44+ iocs_per_query : int = None ,
4545 include_ioc_types : list = None ,
4646 include_hash_types : list = None ,
4747 exceptions : list = None ,
4848 ioc_parsing_rules : list = None ,
4949 include_source_ip : bool = False ) -> (bool , List [str ]):
50+ if not iocs_per_query :
51+ iocs_per_query = CTI_IOCS_PER_QUERY_LIMIT
5052 status , parsed_data = self .__parse_iocs_from_string (text = text ,
5153 include_ioc_types = include_ioc_types ,
5254 include_hash_types = include_hash_types ,
5355 exceptions = exceptions ,
54- ioc_parsing_rules = ioc_parsing_rules )
56+ ioc_parsing_rules = ioc_parsing_rules ,
57+ include_source_ip = include_source_ip )
5558 if status :
5659 return self .__render_translation (parsed_data = parsed_data ,
57- include_source_ip = include_source_ip ,
5860 platform_data = platform_data ,
5961 iocs_per_query = iocs_per_query
6062 )
0 commit comments