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

Commit 7f3f879

Browse files
committed
[client] add remove from draft/share/unshare methods for sightings and relationships
1 parent d2ce9cb commit 7f3f879

File tree

2 files changed

+122
-128
lines changed

2 files changed

+122
-128
lines changed

pycti/entities/opencti_stix_core_relationship.py

Lines changed: 61 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,87 +1248,85 @@ def import_from_stix2(self, **kwargs):
12481248
"[opencti_stix_core_relationship] Missing parameters: stixObject"
12491249
)
12501250

1251-
1252-
"""
1251+
"""
12531252
Share element to multiple organizations
12541253
12551254
:param entity_id: the stix_core_relationship id
12561255
:param organization_id:s the organization to share with
12571256
:return void
12581257
"""
12591258

1260-
1261-
def organization_share(self, entity_id, organization_ids, sharing_direct_container):
1262-
query = """
1263-
mutation StixCoreRelationshipEdit($id: ID!, $organizationId: [ID!]!, $directContainerSharing: Boolean) {
1264-
stixCoreRelationshipEdit(id: $id) {
1265-
restrictionOrganizationAdd(organizationId: $organizationId, directContainerSharing: $directContainerSharing) {
1266-
id
1259+
def organization_share(self, entity_id, organization_ids, sharing_direct_container):
1260+
query = """
1261+
mutation StixCoreRelationshipEdit($id: ID!, $organizationId: [ID!]!, $directContainerSharing: Boolean) {
1262+
stixCoreRelationshipEdit(id: $id) {
1263+
restrictionOrganizationAdd(organizationId: $organizationId, directContainerSharing: $directContainerSharing) {
1264+
id
1265+
}
12671266
}
12681267
}
1269-
}
1270-
"""
1271-
self.opencti.query(
1272-
query,
1273-
{
1274-
"id": entity_id,
1275-
"organizationId": organization_ids,
1276-
"directContainerSharing": sharing_direct_container,
1277-
},
1278-
)
1279-
1280-
1281-
"""
1282-
Unshare element from multiple organizations
1283-
1284-
:param entity_id: the stix_core_relationship id
1285-
:param organization_id:s the organization to share with
1286-
:return void
1287-
"""
1268+
"""
1269+
self.opencti.query(
1270+
query,
1271+
{
1272+
"id": entity_id,
1273+
"organizationId": organization_ids,
1274+
"directContainerSharing": sharing_direct_container,
1275+
},
1276+
)
12881277

1278+
"""
1279+
Unshare element from multiple organizations
1280+
1281+
:param entity_id: the stix_core_relationship id
1282+
:param organization_id:s the organization to share with
1283+
:return void
1284+
"""
12891285

1290-
def organization_unshare(self, entity_id, organization_ids, sharing_direct_container):
1291-
query = """
1292-
mutation StixCoreRelationshipEdit($id: ID!, $organizationId: [ID!]!, $directContainerSharing: Boolean) {
1293-
stixCoreRelationshipEdit(id: $id) {
1294-
restrictionOrganizationDelete(organizationId: $organizationId, directContainerSharing: $directContainerSharing) {
1295-
id
1286+
def organization_unshare(
1287+
self, entity_id, organization_ids, sharing_direct_container
1288+
):
1289+
query = """
1290+
mutation StixCoreRelationshipEdit($id: ID!, $organizationId: [ID!]!, $directContainerSharing: Boolean) {
1291+
stixCoreRelationshipEdit(id: $id) {
1292+
restrictionOrganizationDelete(organizationId: $organizationId, directContainerSharing: $directContainerSharing) {
1293+
id
1294+
}
12961295
}
12971296
}
1298-
}
1299-
"""
1300-
self.opencti.query(
1301-
query,
1302-
{
1303-
"id": entity_id,
1304-
"organizationId": organization_ids,
1305-
"directContainerSharing": sharing_direct_container,
1306-
},
1307-
)
1308-
1297+
"""
1298+
self.opencti.query(
1299+
query,
1300+
{
1301+
"id": entity_id,
1302+
"organizationId": organization_ids,
1303+
"directContainerSharing": sharing_direct_container,
1304+
},
1305+
)
13091306

1310-
"""
1307+
"""
13111308
Remove a stix_core_relationship object from draft (revert)
13121309
13131310
:param id: the stix_core_relationship id
13141311
:return void
13151312
"""
13161313

1317-
1318-
def remove_from_draft(self, **kwargs):
1319-
id = kwargs.get("id", None)
1320-
if id is not None:
1321-
self.opencti.app_logger.info("Draft remove stix_core_relationship", {"id": id})
1322-
query = """
1323-
mutation StixCoreRelationshipEditDraftRemove($id: ID!) {
1324-
stixCoreRelationshipEdit(id: $id) {
1325-
removeFromDraft
1314+
def remove_from_draft(self, **kwargs):
1315+
id = kwargs.get("id", None)
1316+
if id is not None:
1317+
self.opencti.app_logger.info(
1318+
"Draft remove stix_core_relationship", {"id": id}
1319+
)
1320+
query = """
1321+
mutation StixCoreRelationshipEditDraftRemove($id: ID!) {
1322+
stixCoreRelationshipEdit(id: $id) {
1323+
removeFromDraft
1324+
}
13261325
}
1327-
}
1328-
"""
1329-
self.opencti.query(query, {"id": id})
1330-
else:
1331-
self.opencti.app_logger.error(
1332-
"[stix_core_relationship] Cant remove from draft, missing parameters: id"
1333-
)
1334-
return None
1326+
"""
1327+
self.opencti.query(query, {"id": id})
1328+
else:
1329+
self.opencti.app_logger.error(
1330+
"[stix_core_relationship] Cant remove from draft, missing parameters: id"
1331+
)
1332+
return None

pycti/entities/opencti_stix_sighting_relationship.py

Lines changed: 61 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -802,90 +802,86 @@ def update_created_by(self, **kwargs):
802802
self.opencti.app_logger.error("Missing parameters: id")
803803
return False
804804

805-
806-
"""
805+
"""
807806
Share element to multiple organizations
808807
809808
:param entity_id: the stix_sighting id
810809
:param organization_id:s the organization to share with
811810
:return void
812811
"""
813812

814-
815-
def organization_share(self, entity_id, organization_ids, sharing_direct_container):
816-
query = """
817-
mutation StixSightingRelationshipEdit($id: ID!, $organizationId: [ID!]!, $directContainerSharing: Boolean) {
818-
stixSightingRelationshipEdit(id: $id) {
819-
restrictionOrganizationAdd(organizationId: $organizationId, directContainerSharing: $directContainerSharing) {
820-
id
821-
}
822-
}
823-
}
824-
"""
825-
self.opencti.query(
826-
query,
827-
{
828-
"id": entity_id,
829-
"organizationId": organization_ids,
830-
"directContainerSharing": sharing_direct_container,
831-
},
832-
)
833-
834-
835-
"""
836-
Unshare element from multiple organizations
837-
838-
:param entity_id: the stix_sighting id
839-
:param organization_id:s the organization to share with
840-
:return void
841-
"""
842-
843-
844-
def organization_unshare(self, entity_id, organization_ids, sharing_direct_container):
845-
query = """
846-
mutation StixSightingRelationshipEdit($id: ID!, $organizationId: [ID!]!, $directContainerSharing: Boolean) {
847-
stixSightingRelationshipEdit(id: $id) {
848-
restrictionOrganizationDelete(organizationId: $organizationId, directContainerSharing: $directContainerSharing) {
849-
id
813+
def organization_share(self, entity_id, organization_ids, sharing_direct_container):
814+
query = """
815+
mutation StixSightingRelationshipEdit($id: ID!, $organizationId: [ID!]!, $directContainerSharing: Boolean) {
816+
stixSightingRelationshipEdit(id: $id) {
817+
restrictionOrganizationAdd(organizationId: $organizationId, directContainerSharing: $directContainerSharing) {
818+
id
819+
}
850820
}
851821
}
852-
}
853-
"""
854-
self.opencti.query(
855-
query,
856-
{
857-
"id": entity_id,
858-
"organizationId": organization_ids,
859-
"directContainerSharing": sharing_direct_container,
860-
},
861-
)
862-
863-
864-
"""
865-
Remove a stix_sighting object from draft (revert)
822+
"""
823+
self.opencti.query(
824+
query,
825+
{
826+
"id": entity_id,
827+
"organizationId": organization_ids,
828+
"directContainerSharing": sharing_direct_container,
829+
},
830+
)
866831

867-
:param id: the stix_sighting id
832+
"""
833+
Unshare element from multiple organizations
834+
835+
:param entity_id: the stix_sighting id
836+
:param organization_id:s the organization to share with
868837
:return void
869838
"""
870839

871-
872-
def remove_from_draft(self, **kwargs):
873-
id = kwargs.get("id", None)
874-
if id is not None:
875-
self.opencti.app_logger.info("Draft remove stix_sighting", {"id": id})
840+
def organization_unshare(
841+
self, entity_id, organization_ids, sharing_direct_container
842+
):
876843
query = """
877-
mutation StixSightingRelationshipEditDraftRemove($id: ID!) {
844+
mutation StixSightingRelationshipEdit($id: ID!, $organizationId: [ID!]!, $directContainerSharing: Boolean) {
878845
stixSightingRelationshipEdit(id: $id) {
879-
removeFromDraft
846+
restrictionOrganizationDelete(organizationId: $organizationId, directContainerSharing: $directContainerSharing) {
847+
id
848+
}
880849
}
881850
}
882851
"""
883-
self.opencti.query(query, {"id": id})
884-
else:
885-
self.opencti.app_logger.error(
886-
"[stix_sighting] Cant remove from draft, missing parameters: id"
852+
self.opencti.query(
853+
query,
854+
{
855+
"id": entity_id,
856+
"organizationId": organization_ids,
857+
"directContainerSharing": sharing_direct_container,
858+
},
887859
)
888-
return None
860+
861+
"""
862+
Remove a stix_sighting object from draft (revert)
863+
864+
:param id: the stix_sighting id
865+
:return void
866+
"""
867+
868+
def remove_from_draft(self, **kwargs):
869+
id = kwargs.get("id", None)
870+
if id is not None:
871+
self.opencti.app_logger.info("Draft remove stix_sighting", {"id": id})
872+
query = """
873+
mutation StixSightingRelationshipEditDraftRemove($id: ID!) {
874+
stixSightingRelationshipEdit(id: $id) {
875+
removeFromDraft
876+
}
877+
}
878+
"""
879+
self.opencti.query(query, {"id": id})
880+
else:
881+
self.opencti.app_logger.error(
882+
"[stix_sighting] Cant remove from draft, missing parameters: id"
883+
)
884+
return None
889885

890886
"""
891887
Delete a stix_sighting

0 commit comments

Comments
 (0)