Skip to content

[client] New specific operations for PIR (opencti #10032) #894

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 27, 2025
2 changes: 2 additions & 0 deletions pycti/api/opencti_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from pycti import __version__
from pycti.api.opencti_api_connector import OpenCTIApiConnector
from pycti.api.opencti_api_pir import OpenCTIApiPir
from pycti.api.opencti_api_playbook import OpenCTIApiPlaybook
from pycti.api.opencti_api_work import OpenCTIApiWork
from pycti.entities.opencti_attack_pattern import AttackPattern
Expand Down Expand Up @@ -170,6 +171,7 @@ def __init__(
self.playbook = OpenCTIApiPlaybook(self)
self.connector = OpenCTIApiConnector(self)
self.stix2 = OpenCTIStix2(self)
self.pir = OpenCTIApiPir(self)

# Define the entities
self.vocabulary = Vocabulary(self)
Expand Down
37 changes: 37 additions & 0 deletions pycti/api/opencti_api_pir.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class OpenCTIApiPir:
"""OpenCTIApiPir"""

def __init__(self, api):
self.api = api

def pir_flag_element(self, **kwargs):
id = kwargs.get("id", None)
input = kwargs.get("input", None)
query = """
mutation PirFlagElement($id: ID!, $input: PirFlagElementInput!) {
pirFlagElement(id: $id, input: $input)
}
"""
self.api.query(
query,
{
"id": id,
"input": input,
},
)

def pir_unflag_element(self, **kwargs):
id = kwargs.get("id", None)
input = kwargs.get("input", None)
query = """
mutation PirUnflagElement($id: ID!, $input: PirUnflagElementInput!) {
pirUnflagElement(id: $id, input: $input)
}
"""
self.api.query(
query,
{
"id": id,
"input": input,
},
)
8 changes: 8 additions & 0 deletions pycti/utils/opencti_stix2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2484,6 +2484,14 @@ def apply_opencti_operation(self, item, operation):
self.opencti.stix.merge(id=target_id, object_ids=source_ids)
elif operation == "patch":
self.apply_patch(item=item)
elif operation == "pir_flag_element":
id = item["id"]
input = item["input"]
self.opencti.pir.pir_flag_element(id=id, input=input)
elif operation == "pir_unflag_element":
id = item["id"]
input = item["input"]
self.opencti.pir.pir_unflag_element(id=id, input=input)
else:
raise ValueError("Not supported opencti_operation")

Expand Down
1 change: 1 addition & 0 deletions pycti/utils/opencti_stix2_splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
SUPPORTED_STIX_ENTITY_OBJECTS # entities
+ list(STIX_CYBER_OBSERVABLE_MAPPING.keys()) # observables
+ ["relationship", "sighting"] # relationships
+ ["pir"]
)


Expand Down