Skip to content

Commit f4c7e46

Browse files
author
Samuel Hassine
authored
[client/examples] Introduce the black formatter (OpenCTI-Platform#53)
1 parent 96b8189 commit f4c7e46

File tree

58 files changed

+6131
-4455
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+6131
-4455
lines changed

.circleci/config.yml

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ jobs:
1010
- run:
1111
name: install dependencies
1212
command: pip3 install -r requirements.txt --user
13+
- run:
14+
name: install dependencies
15+
command: black --check .
1316
- run:
1417
name: build
1518
command: python3 setup.py sdist

examples/add_external_reference_to_report.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,35 @@
44
from pycti import OpenCTIApiClient
55

66
# Variables
7-
api_url = 'https://demo.opencti.io'
8-
api_token = 'bb4aca90-b98c-49ee-9582-7eac92b61b82'
7+
api_url = "https://demo.opencti.io"
8+
api_token = "bb4aca90-b98c-49ee-9582-7eac92b61b82"
99

1010
# OpenCTI initialization
1111
opencti_api_client = OpenCTIApiClient(api_url, api_token)
1212

1313
# Define the date
14-
date = parse('2019-12-01').strftime('%Y-%m-%dT%H:%M:%SZ')
14+
date = parse("2019-12-01").strftime("%Y-%m-%dT%H:%M:%SZ")
1515

1616
# Create the report
1717
report = opencti_api_client.report.create(
18-
name='My test report',
19-
description='A new threat report.',
18+
name="My test report",
19+
description="A new threat report.",
2020
published=date,
21-
report_class='Threat Report'
21+
report_class="Threat Report",
2222
)
2323

2424
# Create the external reference
2525
external_reference = opencti_api_client.external_reference.create(
26-
source_name='Wikipedia',
27-
url='https://en.wikipedia.org/wiki/Fancy_Bear'
26+
source_name="Wikipedia", url="https://en.wikipedia.org/wiki/Fancy_Bear"
2827
)
2928

3029
# Add the external reference to the report
3130
opencti_api_client.stix_entity.add_external_reference(
32-
id=report['id'],
33-
external_reference_id=external_reference['id']
31+
id=report["id"], external_reference_id=external_reference["id"]
3432
)
3533

3634
# Get the report
37-
report = opencti_api_client.report.read(id=report['id'])
35+
report = opencti_api_client.report.read(id=report["id"])
3836

3937
# Print
40-
print(report)
38+
print(report)

examples/add_organization_to_sector.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@
55
from pycti import OpenCTIApiClient
66

77
# Variables
8-
api_url = 'https://demo.opencti.io'
9-
api_token = 'bb4aca90-b98c-49ee-9582-7eac92b61b82'
8+
api_url = "https://demo.opencti.io"
9+
api_token = "bb4aca90-b98c-49ee-9582-7eac92b61b82"
1010

1111
# OpenCTI initialization
1212
opencti_api_client = OpenCTIApiClient(api_url, api_token)
1313

1414
# Get the sector
15-
sector = opencti_api_client.identity.read(filters=[{'key': 'name', 'values': ['Banking institutions']}])
15+
sector = opencti_api_client.identity.read(
16+
filters=[{"key": "name", "values": ["Banking institutions"]}]
17+
)
1618

1719
# Create the organization
1820
organization = opencti_api_client.identity.create(
19-
type='Organization',
20-
name='BNP Paribas',
21-
description='A french bank.'
21+
type="Organization", name="BNP Paribas", description="A french bank."
2222
)
2323

2424
# Create the relation
2525
relation = opencti_api_client.stix_relation.create(
26-
fromType='Organization',
27-
fromId=organization['id'],
28-
toType='Sector',
29-
toId=sector['id'],
30-
relationship_type='gathering',
31-
description='BNP Paribas is part of the sector Banking institutions.',
32-
ignore_dates=True
26+
fromType="Organization",
27+
fromId=organization["id"],
28+
toType="Sector",
29+
toId=sector["id"],
30+
relationship_type="gathering",
31+
description="BNP Paribas is part of the sector Banking institutions.",
32+
ignore_dates=True,
3333
)
3434

3535
# Print

examples/add_tag_to_malware.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,25 @@
44
from pycti import OpenCTIApiClient
55

66
# Variables
7-
api_url = 'https://demo.opencti.io'
8-
api_token = 'bb4aca90-b98c-49ee-9582-7eac92b61b82'
7+
api_url = "https://demo.opencti.io"
8+
api_token = "bb4aca90-b98c-49ee-9582-7eac92b61b82"
99

1010
# OpenCTI initialization
1111
opencti_api_client = OpenCTIApiClient(api_url, api_token)
1212

1313
# Create the malware
1414
malware = opencti_api_client.malware.create(
15-
name='My new malware',
16-
description='A new evil tool.'
15+
name="My new malware", description="A new evil tool."
1716
)
1817

1918
# Create the tag (if not exists)
2019
tag = opencti_api_client.tag.create(
21-
tag_type='Malware-Type',
22-
value='Ranswomware',
23-
color='#ffa500',
20+
tag_type="Malware-Type", value="Ranswomware", color="#ffa500",
2421
)
2522

2623
# Add the tag
27-
opencti_api_client.stix_entity.add_tag(
28-
id=malware['id'],
29-
tag_id=tag['id']
30-
)
24+
opencti_api_client.stix_entity.add_tag(id=malware["id"], tag_id=tag["id"])
3125

3226
# Print
33-
malware = opencti_api_client.malware.read(id=malware['id'])
34-
print(malware)
27+
malware = opencti_api_client.malware.read(id=malware["id"])
28+
print(malware)

examples/add_tool_usage_to_intrusion-set.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
from pycti import OpenCTIApiClient
77

88
# Variables
9-
api_url = 'https://demo.opencti.io'
10-
api_token = 'bb4aca90-b98c-49ee-9582-7eac92b61b82'
9+
api_url = "https://demo.opencti.io"
10+
api_token = "bb4aca90-b98c-49ee-9582-7eac92b61b82"
1111

1212
# OpenCTI initialization
1313
opencti_api_client = OpenCTIApiClient(api_url, api_token)
14-

examples/create_campaign_attributed-to_intrusion_set.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,46 @@
44
from pycti import OpenCTIApiClient
55

66
# Variables
7-
api_url = 'https://demo.opencti.io'
8-
api_token = 'bb4aca90-b98c-49ee-9582-7eac92b61b82'
7+
api_url = "https://demo.opencti.io"
8+
api_token = "bb4aca90-b98c-49ee-9582-7eac92b61b82"
99

1010
# OpenCTI initialization
1111
opencti_api_client = OpenCTIApiClient(api_url, api_token)
1212

1313
# Define the date
14-
date = parse('2019-12-01').strftime('%Y-%m-%dT%H:%M:%SZ')
14+
date = parse("2019-12-01").strftime("%Y-%m-%dT%H:%M:%SZ")
1515

1616
# Create the Intrusion Set
1717
intrusion_set = opencti_api_client.intrusion_set.create(
18-
name='My new Intrusion Set',
19-
description='Evil Cluster',
18+
name="My new Intrusion Set",
19+
description="Evil Cluster",
2020
first_seen=date,
2121
last_seen=date,
22-
update=True
22+
update=True,
2323
)
2424
print(intrusion_set)
2525

2626
# Create the Campaign
2727
campaign = opencti_api_client.campaign.create(
28-
name='My new Campaign',
29-
description='Large SpearPhishing and intrusions followed by ransomware',
30-
objective='Financial gain',
28+
name="My new Campaign",
29+
description="Large SpearPhishing and intrusions followed by ransomware",
30+
objective="Financial gain",
3131
first_seen=date,
3232
last_seen=date,
33-
update=True
33+
update=True,
3434
)
3535
print(campaign)
3636

3737
# Attribute the Campaign to the Intrusion Set
3838
relation = opencti_api_client.stix_relation.create(
39-
fromType='Campaign',
40-
fromId=campaign['id'],
41-
toType='Intrusion-Set',
42-
toId=intrusion_set['id'],
43-
relationship_type='attributed-to',
39+
fromType="Campaign",
40+
fromId=campaign["id"],
41+
toType="Intrusion-Set",
42+
toId=intrusion_set["id"],
43+
relationship_type="attributed-to",
4444
first_seen=date,
4545
last_seen=date,
46-
description='My new campaign is attributed to my new Intrusion Set, the evil cluster.'
46+
description="My new campaign is attributed to my new Intrusion Set, the evil cluster.",
4747
)
4848

4949
# Print

examples/create_hashes_and_link_together.py

+32-32
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,57 @@
33
from pycti import OpenCTIApiClient
44

55
# Variables
6-
api_url = 'https://demo.opencti.io'
7-
api_token = 'bb4aca90-b98c-49ee-9582-7eac92b61b82'
6+
api_url = "https://demo.opencti.io"
7+
api_token = "bb4aca90-b98c-49ee-9582-7eac92b61b82"
88

99
# OpenCTI initialization
1010
opencti_api_client = OpenCTIApiClient(api_url, api_token)
1111

1212
# Create observables
1313
hash_md5 = opencti_api_client.stix_observable.create(
14-
type='File-MD5',
15-
observable_value='16b3f663d0f0371a4706642c6ac04e42',
16-
description='Hash linked to Emotet',
17-
update=True
14+
type="File-MD5",
15+
observable_value="16b3f663d0f0371a4706642c6ac04e42",
16+
description="Hash linked to Emotet",
17+
update=True,
1818
)
1919
print(hash_md5)
2020
hash_sha1 = opencti_api_client.stix_observable.create(
21-
type='File-SHA1',
22-
observable_value='3a1f908941311fc357051b5c35fd2a4e0c834e37',
23-
description='Hash linked to Emotet',
24-
update=True
21+
type="File-SHA1",
22+
observable_value="3a1f908941311fc357051b5c35fd2a4e0c834e37",
23+
description="Hash linked to Emotet",
24+
update=True,
2525
)
2626
print(hash_sha1)
2727
hash_sha256 = opencti_api_client.stix_observable.create(
28-
type='File-SHA256',
29-
observable_value='bcc70a49fab005b4cdbe0cbd87863ec622c6b2c656987d201adbb0e05ec03e56',
30-
description='Hash linked to Emotet',
31-
update=True
28+
type="File-SHA256",
29+
observable_value="bcc70a49fab005b4cdbe0cbd87863ec622c6b2c656987d201adbb0e05ec03e56",
30+
description="Hash linked to Emotet",
31+
update=True,
3232
)
3333
print(hash_sha256)
3434

3535
# Create relations
3636
opencti_api_client.stix_observable_relation.create(
37-
relationship_type='corresponds',
38-
fromType='File-MD5',
39-
fromId=hash_md5['id'],
40-
toType='File-SHA1',
41-
toId=hash_sha1['id'],
42-
ignore_dates=True
37+
relationship_type="corresponds",
38+
fromType="File-MD5",
39+
fromId=hash_md5["id"],
40+
toType="File-SHA1",
41+
toId=hash_sha1["id"],
42+
ignore_dates=True,
4343
)
4444
opencti_api_client.stix_observable_relation.create(
45-
relationship_type='corresponds',
46-
fromType='File-MD5',
47-
fromId=hash_md5['id'],
48-
toType='File-SHA256',
49-
toId=hash_sha256['id'],
50-
ignore_dates=True
45+
relationship_type="corresponds",
46+
fromType="File-MD5",
47+
fromId=hash_md5["id"],
48+
toType="File-SHA256",
49+
toId=hash_sha256["id"],
50+
ignore_dates=True,
5151
)
5252
opencti_api_client.stix_observable_relation.create(
53-
relationship_type='corresponds',
54-
fromType='File-SHA1',
55-
fromId=hash_sha1['id'],
56-
toType='File-SHA256',
57-
toId=hash_sha256['id'],
58-
ignore_dates=True
53+
relationship_type="corresponds",
54+
fromType="File-SHA1",
55+
fromId=hash_sha1["id"],
56+
toType="File-SHA256",
57+
toId=hash_sha256["id"],
58+
ignore_dates=True,
5959
)

0 commit comments

Comments
 (0)