Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Commit b872310

Browse files
richard-julienJeremyCloarec
authored andcommitted
[client] Introduce new functions share/unshare and rescan
1 parent 9da0100 commit b872310

File tree

2 files changed

+102
-3
lines changed

2 files changed

+102
-3
lines changed

pycti/entities/opencti_stix_core_object.py

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,9 @@ def rule_apply(self, **kwargs):
16921692
rule_id = kwargs.get("rule_id", None)
16931693
element_id = kwargs.get("element_id", None)
16941694
if element_id is not None and rule_id is not None:
1695-
self.opencti.app_logger.info("Apply rule stix_core_object", {"id": element_id})
1695+
self.opencti.app_logger.info(
1696+
"Apply rule stix_core_object", {"id": element_id}
1697+
)
16961698
query = """
16971699
mutation StixCoreApplyRule($elementId: ID!, $ruleId: ID!) {
16981700
ruleApply(elementId: $elementId, ruleId: $ruleId)
@@ -1715,7 +1717,9 @@ def rule_clear(self, **kwargs):
17151717
rule_id = kwargs.get("rule_id", None)
17161718
element_id = kwargs.get("element_id", None)
17171719
if element_id is not None and rule_id is not None:
1718-
self.opencti.app_logger.info("Apply rule clear stix_core_object", {"id": element_id})
1720+
self.opencti.app_logger.info(
1721+
"Apply rule clear stix_core_object", {"id": element_id}
1722+
)
17191723
query = """
17201724
mutation StixCoreClearRule($elementId: ID!, $ruleId: ID!) {
17211725
ruleClear(elementId: $elementId, ruleId: $ruleId)
@@ -1726,6 +1730,81 @@ def rule_clear(self, **kwargs):
17261730
self.opencti.app_logger.error("[stix_core_object] Missing parameters: id")
17271731
return None
17281732

1733+
"""
1734+
Apply rules rescan to Stix-Core-Object object
1735+
1736+
:param element_id: the Stix-Core-Object id
1737+
:return void
1738+
"""
1739+
1740+
def rules_rescan(self, **kwargs):
1741+
element_id = kwargs.get("element_id", None)
1742+
if element_id is not None:
1743+
self.opencti.app_logger.info(
1744+
"Apply rules rescan stix_core_object", {"id": element_id}
1745+
)
1746+
query = """
1747+
mutation StixCoreRescanRules($elementId: ID!) {
1748+
rulesRescan(elementId: $elementId)
1749+
}
1750+
"""
1751+
self.opencti.query(query, {"elementId": element_id})
1752+
else:
1753+
self.opencti.app_logger.error("[stix_core_object] Missing parameters: id")
1754+
return None
1755+
1756+
"""
1757+
Share element to multiple organizations
1758+
1759+
:param entity_id: the Stix-Core-Object id
1760+
:param organization_id:s the organization to share with
1761+
:return void
1762+
"""
1763+
1764+
def organization_share(self, entity_id, organization_ids):
1765+
query = """
1766+
mutation StixCoreObjectEdit($id: ID!, $organizationId: [ID!]!) {
1767+
stixCoreObjectEdit(id: $id) {
1768+
restrictionOrganizationAdd(organizationId: $organizationId) {
1769+
id
1770+
}
1771+
}
1772+
}
1773+
"""
1774+
self.opencti.query(
1775+
query,
1776+
{
1777+
"id": entity_id,
1778+
"organizationId": organization_ids,
1779+
},
1780+
)
1781+
1782+
"""
1783+
Unshare element from multiple organizations
1784+
1785+
:param entity_id: the Stix-Core-Object id
1786+
:param organization_id:s the organization to share with
1787+
:return void
1788+
"""
1789+
1790+
def organization_unshare(self, entity_id, organization_ids):
1791+
query = """
1792+
mutation StixCoreObjectEdit($id: ID!, $organizationId: [ID!]!) {
1793+
stixCoreObjectEdit(id: $id) {
1794+
restrictionOrganizationDelete(organizationId: $organizationId) {
1795+
id
1796+
}
1797+
}
1798+
}
1799+
"""
1800+
self.opencti.query(
1801+
query,
1802+
{
1803+
"id": entity_id,
1804+
"organizationId": organization_ids,
1805+
},
1806+
)
1807+
17291808
"""
17301809
Delete a Stix-Core-Object object
17311810

pycti/utils/opencti_stix2.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2475,6 +2475,17 @@ def rule_clear(self, item):
24752475
rule_id = item["opencti_rule"]
24762476
self.opencti.stix_core_object.rule_clear(element_id=item["id"], rule_id=rule_id)
24772477

2478+
def rules_rescan(self, item):
2479+
self.opencti.stix_core_object.rules_rescan(element_id=item["id"])
2480+
2481+
def organization_share(self, item):
2482+
organization_ids = item["organization_ids"]
2483+
self.opencti.stix_core_object.organization_share(item["id"], organization_ids)
2484+
2485+
def organization_unshare(self, item):
2486+
organization_ids = item["organization_ids"]
2487+
self.opencti.stix_core_object.organization_unshare(item["id"], organization_ids)
2488+
24782489
def apply_opencti_operation(self, item, operation):
24792490
if operation == "delete":
24802491
delete_id = item["id"]
@@ -2489,8 +2500,17 @@ def apply_opencti_operation(self, item, operation):
24892500
self.rule_apply(item=item)
24902501
elif operation == "rule_clear":
24912502
self.rule_clear(item=item)
2503+
elif operation == "rules_rescan":
2504+
self.rules_rescan(item=item)
2505+
elif operation == "share":
2506+
self.organization_share(item=item)
2507+
elif operation == "unshare":
2508+
self.organization_unshare(item=item)
24922509
else:
2493-
raise ValueError("Not supported opencti_operation")
2510+
raise ValueError(
2511+
"Not supported opencti_operation",
2512+
{"operation": operation},
2513+
)
24942514

24952515
def import_item(
24962516
self,

0 commit comments

Comments
 (0)