Skip to content

Commit a46fe7f

Browse files
author
Samuel Hassine
committed
[client] Update examples
1 parent c96cdb3 commit a46fe7f

8 files changed

+19
-17
lines changed

examples/add_organization_to_sector.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020
)
2121

2222
# Create the relation
23-
relation = opencti_api_client.stix_relation.create(
23+
relation = opencti_api_client.stix_core_relationship.create(
2424
fromType="Organization",
2525
fromId=organization["id"],
2626
toType="Sector",
2727
toId=sector["id"],
28-
relationship_type="gathering",
28+
relationship_type="part-of",
2929
description="BNP Paribas is part of the sector Banking institutions.",
30-
ignore_dates=True,
3130
)
3231

3332
# Print

examples/add_tag_to_malware.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
)
2323

2424
# Add the tag
25-
opencti_api_client.stix_domain_object.add_tag(id=malware["id"], tag_id=tag["id"])
25+
opencti_api_client.stix_domain_object.add_label(id=malware["id"], tag_id=tag["id"])
2626

2727
# Print
2828
malware = opencti_api_client.malware.read(id=malware["id"])

examples/create_campaign_attributed-to_intrusion_set.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
print(campaign)
3636

3737
# Attribute the Campaign to the Intrusion Set
38-
relation = opencti_api_client.stix_relation.create(
38+
relation = opencti_api_client.stix_core_relationship.create(
3939
fromType="Campaign",
4040
fromId=campaign["id"],
4141
toType="Intrusion-Set",

examples/create_incident_with_ttps_and_indicators.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
observable_refs = []
2020

2121
# Create the incident
22-
incident = opencti_api_client.incident.create(
22+
incident = opencti_api_client.x_opencti_incident.create(
2323
name="My new incident",
2424
description="We have been compromised",
2525
objective="Espionage",
@@ -39,7 +39,7 @@
3939
ttp1 = opencti_api_client.attack_pattern.read(
4040
filters=[{"key": "external_id", "values": ["T1193"]}]
4141
)
42-
ttp1_relation = opencti_api_client.stix_relation.create(
42+
ttp1_relation = opencti_api_client.stix_domain_object.create(
4343
fromType="Incident",
4444
fromId=incident["id"],
4545
toType="Attack-Pattern",
@@ -51,7 +51,7 @@
5151
)
5252
# Add kill chain phases to the relation
5353
for kill_chain_phase_id in ttp1["killChainPhasesIds"]:
54-
opencti_api_client.stix_relation.add_kill_chain_phase(
54+
opencti_api_client.stix_core_relationship.add_kill_chain_phase(
5555
id=ttp1_relation["id"], kill_chain_phase_id=kill_chain_phase_id
5656
)
5757

@@ -63,7 +63,7 @@
6363
# Get the indicator
6464
indicator_ttp1 = observable_ttp1["indicators"][0]
6565
# Indicates the relation Incident => uses => TTP
66-
indicator_ttp1_relation = opencti_api_client.stix_relation.create(
66+
indicator_ttp1_relation = opencti_api_client.stix_core_relationship.create(
6767
fromType="Indicator",
6868
fromId=indicator_ttp1["id"],
6969
toType="stix_relation",
@@ -90,7 +90,7 @@
9090
filters=[{"key": "external_id", "values": ["T1060"]}]
9191
)
9292
# Create the relation
93-
ttp2_relation = opencti_api_client.stix_relation.create(
93+
ttp2_relation = opencti_api_client.stix_core_relationship.create(
9494
fromType="Incident",
9595
fromId=incident["id"],
9696
toType="Attack-Pattern",
@@ -102,7 +102,7 @@
102102
)
103103
# Add kill chain phases to the relation
104104
for kill_chain_phase_id in ttp2["killChainPhasesIds"]:
105-
opencti_api_client.stix_relation.add_kill_chain_phase(
105+
opencti_api_client.stix_core_relationship.add_kill_chain_phase(
106106
id=ttp2_relation["id"], kill_chain_phase_id=kill_chain_phase_id
107107
)
108108

@@ -114,7 +114,7 @@
114114
# Get the indicator
115115
indicator_ttp2 = observable_ttp2["indicators"][0]
116116
# Indicates the relation Incident => uses => TTP
117-
indicator_ttp2_relation = opencti_api_client.stix_relation.create(
117+
indicator_ttp2_relation = opencti_api_client.stix_core_relationship.create(
118118
fromType="Indicator",
119119
fromId=indicator_ttp2["id"],
120120
toType="stix_relation",
@@ -139,7 +139,7 @@
139139
ttp3 = opencti_api_client.attack_pattern.read(
140140
filters=[{"key": "external_id", "values": ["T1022"]}]
141141
)
142-
ttp3_relation = opencti_api_client.stix_relation.create(
142+
ttp3_relation = opencti_api_client.stix_core_relationship.create(
143143
fromType="Incident",
144144
fromId=incident["id"],
145145
toType="Attack-Pattern",
@@ -151,7 +151,7 @@
151151
)
152152
# Add kill chain phases to the relation
153153
for kill_chain_phase_id in ttp3["killChainPhasesIds"]:
154-
opencti_api_client.stix_relation.add_kill_chain_phase(
154+
opencti_api_client.stix_core_relationship.add_kill_chain_phase(
155155
id=ttp3_relation["id"], kill_chain_phase_id=kill_chain_phase_id
156156
)
157157
# Elements for the report
@@ -166,7 +166,7 @@
166166
opencti_api_client.report.add_stix_observable(
167167
id=report["id"], report=report, stix_observable_id=observable_ref
168168
)
169-
opencti_api_client.stix_relation.create(
169+
opencti_api_client.stix_core_relationship.create(
170170
fromType="Stix-Observable",
171171
fromId=observable_ref,
172172
toType="Incident",

examples/create_indicator_of_campaign.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
print(indicator)
3737

3838
# Create the relation
39-
relation = opencti_api_client.stix_relation.create(
39+
relation = opencti_api_client.stix_core_relationship.create(
4040
fromType="Indicator",
4141
fromId=indicator["id"],
4242
toType="Campaign",

examples/export_incident_stix2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
opencti_api_client = OpenCTIApiClient(api_url, api_token)
1212

1313
# Get the incident created in the create_incident_with_ttps_and_indicators.py
14-
incident = opencti_api_client.incident.read(
14+
incident = opencti_api_client.x_opencti_incident.read(
1515
filters=[{"key": "name", "values": ["My new incident"]}]
1616
)
1717

pycti/entities/opencti_identity.py

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def __init__(self, opencti):
9292
confidence
9393
created
9494
modified
95+
identity_class
9596
name
9697
description
9798
x_opencti_aliases

pycti/utils/opencti_stix2.py

+2
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,8 @@ def prepare_export(self, entity, mode="simple", max_marking_definition_entity=No
10761076
objects_to_get.append(entity["to"]["standard_id"])
10771077
if "to" in entity:
10781078
del entity["to"]
1079+
if "observable_value" in entity:
1080+
del entity["observable_value"]
10791081

10801082
result.append(entity)
10811083

0 commit comments

Comments
 (0)