88
99from pycti .entities import LOGGER
1010from pycti .entities .opencti_threat_actor_group import ThreatActorGroup
11+ from pycti .entities .opencti_threat_actor_individual import ThreatActorIndividual
1112
1213
1314class ThreatActor :
@@ -21,6 +22,7 @@ def __init__(self, opencti):
2122
2223 self .opencti = opencti
2324 self .threat_actor_group = ThreatActorGroup (opencti )
25+ self .threat_actor_individual = ThreatActorIndividual (opencti )
2426 self .properties = """
2527 id
2628 standard_id
@@ -186,11 +188,11 @@ def list(self, **kwargs) -> dict:
186188 LOGGER .info ("Listing Threat-Actors with filters %s." , json .dumps (filters ))
187189 query = (
188190 """
189- query ThreatActors($filters: [ThreatActorsFiltering], $search: String, $first: Int, $after: ID, $orderBy: ThreatActorsOrdering, $orderMode: OrderingMode) {
190- threatActors(filters: $filters, search: $search, first: $first, after: $after, orderBy: $orderBy, orderMode: $orderMode) {
191- edges {
192- node {
193- """
191+ query ThreatActors($filters: [ThreatActorsFiltering], $search: String, $first: Int, $after: ID, $orderBy: ThreatActorsOrdering, $orderMode: OrderingMode) {
192+ threatActors(filters: $filters, search: $search, first: $first, after: $after, orderBy: $orderBy, orderMode: $orderMode) {
193+ edges {
194+ node {
195+ """
194196 + (custom_attributes if custom_attributes is not None else self .properties )
195197 + """
196198 }
@@ -242,9 +244,9 @@ def read(self, **kwargs) -> Union[dict, None]:
242244 LOGGER .info ("Reading Threat-Actor {%s}." , id )
243245 query = (
244246 """
245- query ThreatActor($id: String!) {
246- threatActor(id: $id) {
247- """
247+ query ThreatActor($id: String!) {
248+ threatActor(id: $id) {
249+ """
248250 + (
249251 custom_attributes
250252 if custom_attributes is not None
@@ -267,41 +269,9 @@ def read(self, **kwargs) -> Union[dict, None]:
267269 LOGGER .error ("[opencti_threat_actor] Missing parameters: id or filters" )
268270 return None
269271
272+ @DeprecationWarning
270273 def create (self , ** kwargs ):
271- """Create a Threat-Actor object
272-
273- The Threat-Actor entity will only be created if it doesn't exists
274- By setting `update` to `True` it acts like an upsert and updates
275- fields of an existing Threat-Actor entity.
276-
277- The create method accepts the following kwargs.
278-
279- Note: `name` and `description` or `stix_id` is required.
280-
281- :param str stix_id: stix2 id reference for the Threat-Actor entity
282- :param str createdBy: (optional) id of the organization that created the knowledge
283- :param list objectMarking: (optional) list of OpenCTI markin definition ids
284- :param list objectLabel: (optional) list of OpenCTI label ids
285- :param list externalReferences: (optional) list of OpenCTI external references ids
286- :param bool revoked: is this entity revoked
287- :param int confidence: confidence level
288- :param str lang: language
289- :param str created: (optional) date in OpenCTI date format
290- :param str modified: (optional) date in OpenCTI date format
291- :param str name: name of the threat actor
292- :param str description: description of the threat actor
293- :param list aliases: (optional) list of alias names for the Threat-Actor
294- :param list threat_actor_types: (optional) list of threat actor types
295- :param str first_seen: (optional) date in OpenCTI date format
296- :param str last_seen: (optional) date in OpenCTI date format
297- :param list roles: (optional) list of roles
298- :param list goals: (optional) list of goals
299- :param str sophistication: (optional) describe the actors sophistication in text
300- :param str resource_level: (optional) describe the actors resource_level in text
301- :param str primary_motivation: (optional) describe the actors primary_motivation in text
302- :param list secondary_motivations: (optional) describe the actors secondary_motivations in list of string
303- :param bool update: (optional) choose to updated an existing Threat-Actor entity, default `False`
304- """
274+ # For backward compatibility, please use threat_actor_group or threat_actor_individual
305275 return self .threat_actor_group .create (** kwargs )
306276
307277 """
@@ -312,4 +282,17 @@ def create(self, **kwargs):
312282 """
313283
314284 def import_from_stix2 (self , ** kwargs ):
315- return self .threat_actor_group .import_from_stix2 (** kwargs )
285+ stix_object = kwargs .get ("stixObject" , None )
286+ if "x_opencti_type" in stix_object :
287+ type = stix_object ["x_opencti_type" ].lower ()
288+ elif self .opencti .get_attribute_in_extension ("type" , stix_object ) is not None :
289+ type = self .opencti .get_attribute_in_extension ("type" , stix_object ).lower ()
290+ elif "individual" in stix_object ["resource_level" ].lower ():
291+ type = "threat-actor-individual"
292+ else :
293+ type = "threat-actor-group"
294+
295+ if "threat-actor-group" in type :
296+ return self .threat_actor_group .import_from_stix2 (** kwargs )
297+ if "threat-actor-individual" in type :
298+ return self .threat_actor_individual .import_from_stix2 (** kwargs )
0 commit comments