@@ -365,7 +365,7 @@ def _process_entity(
365365 collected_object_refs : List ,
366366 entity_mappings : Dict ,
367367 external_reference : stix2 .ExternalReference = None ,
368- ) -> None :
368+ ) -> Tuple [ List [ Dict ], List , Dict ] :
369369 """
370370 Process a single entity and add it to the report.
371371
@@ -398,6 +398,8 @@ def _process_entity(
398398 if self .logger :
399399 self .logger .debug (f"Added { entity_type } : { entity_value } " )
400400
401+ return related_objects , collected_object_refs , entity_mappings
402+
401403 def _process_entities (
402404 self ,
403405 entities : List [Dict ],
@@ -407,7 +409,7 @@ def _process_entities(
407409 collected_object_refs : List ,
408410 entity_mappings : Dict ,
409411 external_reference : stix2 .ExternalReference = None ,
410- ) -> None :
412+ ) -> Tuple [ List [ Dict ], List , Dict ] :
411413 """
412414 Process a list of entities of the same type.
413415
@@ -421,7 +423,11 @@ def _process_entities(
421423 external_reference: Optional reference to the report
422424 """
423425 for entity in entities :
424- self ._process_entity (
426+ (
427+ related_objects ,
428+ collected_object_refs ,
429+ entity_mappings ,
430+ ) = self ._process_entity (
425431 entity ,
426432 entity_type ,
427433 converter_method ,
@@ -431,14 +437,16 @@ def _process_entities(
431437 external_reference ,
432438 )
433439
440+ return related_objects , collected_object_refs , entity_mappings
441+
434442 def _process_threat_actor (
435443 self ,
436444 threat_actor : Dict ,
437445 related_objects : List ,
438446 collected_object_refs : List ,
439447 entity_mappings : Dict ,
440448 external_reference : stix2 .ExternalReference = None ,
441- ) -> None :
449+ ) -> Tuple [ List [ Dict ], List , Dict ] :
442450 """
443451 Process a threat actor entity with detailed information.
444452
@@ -461,14 +469,14 @@ def _process_threat_actor(
461469 f"Retrieved detailed information for threat actor: { entity_value } "
462470 )
463471
464- ta_object = self .converter .create_detailed_threat_actor (
472+ ta_object , bundle = self .converter .create_detailed_threat_actor (
465473 detailed_threat_actor ,
466474 context ,
467475 report_reference = external_reference ,
468476 )
469477
470478 is_abstract = detailed_threat_actor .get ("is_abstract" , False )
471- related_objects .append ( ta_object )
479+ related_objects .extend ( bundle )
472480 collected_object_refs .append (ta_object .id )
473481
474482 if is_abstract :
@@ -482,6 +490,8 @@ def _process_threat_actor(
482490 if self .logger :
483491 self .logger .debug (f"Added threat actor: { entity_value } " )
484492
493+ return related_objects , collected_object_refs , entity_mappings
494+
485495 except Exception as e :
486496 if self .logger :
487497 self .logger .warning (
@@ -501,6 +511,8 @@ def _process_threat_actor(
501511 if self .logger :
502512 self .logger .debug (f"Added threat actor: { entity_value } " )
503513
514+ return related_objects , collected_object_refs , entity_mappings
515+
504516 def create_report_from_member_content_with_references (
505517 self , content : Dict
506518 ) -> Tuple [Dict , List [Dict ]]:
@@ -528,6 +540,7 @@ def create_report_from_member_content_with_references(
528540 content_id = content .get ("id" )
529541 slug = content .get ("slug" , "" ) # noqa: F841
530542 tlp = content .get ("tlp" , TLPLevel .CLEAR .value )
543+ topics = content .get ("topics" , [])
531544 self .converter = self .get_stix_converter (tlp )
532545
533546 if published_on :
@@ -547,6 +560,9 @@ def create_report_from_member_content_with_references(
547560 labels .append (content ["category" ])
548561 if content .get ("sub_category" ) and content ["sub_category" ].get ("name" ):
549562 labels .append (content ["sub_category" ]["name" ])
563+ if len (topics ) > 0 :
564+ for topic in topics :
565+ labels .append (topic ["name" ])
550566
551567 report_id = (
552568 f"report--{ str (uuid .uuid5 (uuid .NAMESPACE_URL , f'catalyst-{ content_id } ' ))} "
@@ -606,14 +622,15 @@ def create_report_from_member_content_with_references(
606622 entity_id = observable .get ("id" )
607623 entity_value = observable .get ("value" )
608624 entity_type = observable .get ("type" )
609-
625+ entity_context = observable . get ( "context" , "" )
610626 if entity_id and entity_value and entity_type :
611627 observable_data = {
612628 "id" : entity_id ,
613629 "value" : entity_value ,
614630 "type" : entity_type ,
615631 "post_id" : content_id ,
616632 "tlp_marking" : content_marking ,
633+ "context" : entity_context ,
617634 }
618635
619636 (
@@ -657,7 +674,11 @@ def create_report_from_member_content_with_references(
657674 f"Skipping threat actor { threat_actor .get ('value' )} because user is not authenticated... This will be implemented in the future."
658675 )
659676 continue
660- self ._process_threat_actor (
677+ (
678+ related_objects ,
679+ collected_object_refs ,
680+ entity_mappings ,
681+ ) = self ._process_threat_actor (
661682 threat_actor ,
662683 related_objects ,
663684 collected_object_refs ,
@@ -684,7 +705,11 @@ def create_report_from_member_content_with_references(
684705 converter_method = processor
685706 mapping_type = entity_type
686707
687- self ._process_entities (
708+ (
709+ related_objects ,
710+ collected_object_refs ,
711+ entity_mappings ,
712+ ) = self ._process_entities (
688713 all_entities .get (entity_type , []),
689714 mapping_type ,
690715 converter_method ,
0 commit comments