Skip to content

[client] New specific operations for PIR (#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

Open
wants to merge 9 commits into
base: release/current
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 add_pir_dependency(self, **kwargs):
id = kwargs.get("id", None)
input = kwargs.get("input", None)
query = """
mutation PirAddDependency($id: ID!, $input: PIRDependencyAddInput!) {
pirAddDependency(id: $id, input: $input)
}
"""
self.api.query(
query,
{
"id": id,
"input": input,
},
)

def delete_pir_dependency(self, **kwargs):
id = kwargs.get("id", None)
input = kwargs.get("input", None)
query = """
mutation PirDeleteDependency($id: ID!, $input: PirDeleteDependencyInput!) {
pirDeleteDependency(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 == "add_pir_dependency":
id = item["id"]
input = item["input"]
self.opencti.pir.add_pir_dependency(id=id, input=input)
elif operation == "delete_pir_dependency":
id = item["id"]
input = item["input"]
self.opencti.pir.delete_pir_dependency(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