Skip to content

Commit 0ba09fc

Browse files
committedAug 27, 2020
[client] Upgrade files to pass black version 20
1 parent 33e78ba commit 0ba09fc

17 files changed

+95
-50
lines changed
 

‎examples/add_tag_to_malware.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
# Create the tag (if not exists)
1818
tag = opencti_api_client.label.create(
19-
tag_type="Malware-Type", value="Ranswomware", color="#ffa500",
19+
tag_type="Malware-Type",
20+
value="Ranswomware",
21+
color="#ffa500",
2022
)
2123

2224
# Add the tag

‎examples/upload_file.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010
opencti_api_client = OpenCTIApiClient(api_url, api_token)
1111

1212
# Upload the file
13-
file = opencti_api_client.upload_file(file_name="./file.pdf",)
13+
file = opencti_api_client.upload_file(
14+
file_name="./file.pdf",
15+
)
1416
print(file)

‎examples/upload_file_to_intrusion_set.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
# Upload the file
2626
file = opencti_api_client.stix_domain_object.add_file(
27-
id=intrusion_set["id"], file_name="./file.pdf",
27+
id=intrusion_set["id"],
28+
file_name="./file.pdf",
2829
)
2930
print(file)

‎pycti/api/opencti_api_client.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ class OpenCTIApiClient:
7878
"""
7979

8080
def __init__(self, url, token, log_level="info", ssl_verify=False, proxies={}):
81-
"""Constructor method
82-
"""
81+
"""Constructor method"""
8382

8483
# Check configuration
8584
self.ssl_verify = ssl_verify
@@ -225,7 +224,11 @@ def query(self, query, variables={}):
225224
if isinstance(file.data, str):
226225
file_multi = (
227226
str(file_index),
228-
(file.name, io.BytesIO(file.data.encode()), file.mime,),
227+
(
228+
file.name,
229+
io.BytesIO(file.data.encode()),
230+
file.mime,
231+
),
229232
)
230233
else:
231234
file_multi = (
@@ -536,6 +539,7 @@ def upload_file(self, **kwargs):
536539
return self.query(query, {"file": (File(file_name, data, mime_type))})
537540
else:
538541
self.log(
539-
"error", "[upload] Missing parameters: file_name or data",
542+
"error",
543+
"[upload] Missing parameters: file_name or data",
540544
)
541545
return None

‎pycti/api/opencti_api_connector.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88

99
class OpenCTIApiConnector:
10-
"""OpenCTIApiConnector
11-
"""
10+
"""OpenCTIApiConnector"""
1211

1312
def __init__(self, api):
1413
self.api = api

‎pycti/api/opencti_api_job.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55

66
class OpenCTIApiJob:
7-
"""OpenCTIApiJob
8-
"""
7+
"""OpenCTIApiJob"""
98

109
def __init__(self, api):
1110
self.api = api

‎pycti/entities/opencti_identity.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,12 @@ def create(self, **kwargs):
308308
"""
309309
input_variables["type"] = type
310310
result_data_field = "identityAdd"
311-
result = self.opencti.query(query, {"input": input_variables,},)
311+
result = self.opencti.query(
312+
query,
313+
{
314+
"input": input_variables,
315+
},
316+
)
312317
return self.opencti.process_multiple_fields(
313318
result["data"][result_data_field]
314319
)

‎pycti/entities/opencti_label.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,18 @@ def create(self, **kwargs):
135135
"""
136136
)
137137
result = self.opencti.query(
138-
query, {"input": {"stix_id": stix_id, "value": value, "color": color,}},
138+
query,
139+
{
140+
"input": {
141+
"stix_id": stix_id,
142+
"value": value,
143+
"color": color,
144+
}
145+
},
139146
)
140147
return self.opencti.process_multiple_fields(result["data"]["labelAdd"])
141148
else:
142149
self.opencti.log(
143-
"error", "[opencti_label] Missing parameters: value",
150+
"error",
151+
"[opencti_label] Missing parameters: value",
144152
)

‎pycti/entities/opencti_note.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ def contains_stix_object_or_stix_relationship(self, **kwargs):
312312
return result["data"]["noteContainsStixObjectOrStixRelationship"]
313313
else:
314314
self.opencti.log(
315-
"error", "[opencti_note] Missing parameters: id or entity_id",
315+
"error",
316+
"[opencti_note] Missing parameters: id or entity_id",
316317
)
317318

318319
"""
@@ -374,7 +375,8 @@ def create(self, **kwargs):
374375
return self.opencti.process_multiple_fields(result["data"]["noteAdd"])
375376
else:
376377
self.opencti.log(
377-
"error", "[opencti_note] Missing parameters: content",
378+
"error",
379+
"[opencti_note] Missing parameters: content",
378380
)
379381

380382
"""

‎pycti/entities/opencti_observed_data.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ def contains_stix_object_or_stix_relationship(self, **kwargs):
314314
return result["data"]["observedDataContainsStixObjectOrStixRelationship"]
315315
else:
316316
self.opencti.log(
317-
"error", "[opencti_observedData] Missing parameters: id or entity_id",
317+
"error",
318+
"[opencti_observedData] Missing parameters: id or entity_id",
318319
)
319320

320321
"""

‎pycti/entities/opencti_opinion.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ def contains_stix_object_or_stix_relationship(self, **kwargs):
314314
return result["data"]["opinionContainsStixObjectOrStixRelationship"]
315315
else:
316316
self.opencti.log(
317-
"error", "[opencti_opinion] Missing parameters: id or entity_id",
317+
"error",
318+
"[opencti_opinion] Missing parameters: id or entity_id",
318319
)
319320

320321
"""
@@ -376,7 +377,8 @@ def create(self, **kwargs):
376377
return self.opencti.process_multiple_fields(result["data"]["opinionAdd"])
377378
else:
378379
self.opencti.log(
379-
"error", "[opencti_opinion] Missing parameters: content",
380+
"error",
381+
"[opencti_opinion] Missing parameters: content",
380382
)
381383

382384
"""

‎pycti/entities/opencti_report.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ def contains_stix_object_or_stix_relationship(self, **kwargs):
344344
return result["data"]["reportContainsStixObjectOrStixRelationship"]
345345
else:
346346
self.opencti.log(
347-
"error", "[opencti_report] Missing parameters: id or entity_id",
347+
"error",
348+
"[opencti_report] Missing parameters: id or entity_id",
348349
)
349350

350351
"""

‎pycti/entities/opencti_stix_core_relationship.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,8 @@ def create(self, **kwargs):
445445
update = kwargs.get("update", False)
446446

447447
self.opencti.log(
448-
"info", "Creating stix_core_relationship {" + from_id + ", " + to_id + "}.",
448+
"info",
449+
"Creating stix_core_relationship {" + from_id + ", " + to_id + "}.",
449450
)
450451
query = """
451452
mutation StixCoreRelationshipAdd($input: StixCoreRelationshipAddInput!) {

‎pycti/entities/opencti_stix_domain_object.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,10 @@ def update_created_by(self, **kwargs):
751751
"""
752752
variables = {
753753
"id": id,
754-
"input": {"toId": identity_id, "relationship_type": "created-by",},
754+
"input": {
755+
"toId": identity_id,
756+
"relationship_type": "created-by",
757+
},
755758
}
756759
self.opencti.query(query, variables)
757760

@@ -1038,7 +1041,8 @@ def reports(self, **kwargs):
10381041
id = kwargs.get("id", None)
10391042
if id is not None:
10401043
self.opencti.log(
1041-
"info", "Getting reports of the Stix-Domain-Object {" + id + "}.",
1044+
"info",
1045+
"Getting reports of the Stix-Domain-Object {" + id + "}.",
10421046
)
10431047
query = """
10441048
query StixDomainObject($id: String!) {
@@ -1197,7 +1201,8 @@ def notes(self, **kwargs):
11971201
id = kwargs.get("id", None)
11981202
if id is not None:
11991203
self.opencti.log(
1200-
"info", "Getting notes of the Stix-Domain-Object {" + id + "}.",
1204+
"info",
1205+
"Getting notes of the Stix-Domain-Object {" + id + "}.",
12011206
)
12021207
query = """
12031208
query StixDomainObject($id: String!) {

‎pycti/entities/opencti_stix_sighting_relationship.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,8 @@ def create(self, **kwargs):
433433
update = kwargs.get("update", False)
434434

435435
self.opencti.log(
436-
"info", "Creating stix_sighting {" + from_id + ", " + str(to_id) + "}.",
436+
"info",
437+
"Creating stix_sighting {" + from_id + ", " + str(to_id) + "}.",
437438
)
438439
query = """
439440
mutation StixSightingRelationshipAdd($input: StixSightingRelationshipAddInput!) {

‎pycti/entities/opencti_threat_actor.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ class ThreatActor:
1212
"""
1313

1414
def __init__(self, opencti):
15-
"""Create an instance of ThreatActor
16-
"""
15+
"""Create an instance of ThreatActor"""
1716

1817
self.opencti = opencti
1918
self.properties = """

‎pycti/utils/opencti_stix2.py

+36-23
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,9 @@ def get_author(self, name):
236236
return self.mapping_cache[name]
237237
else:
238238
author = self.opencti.identity.create(
239-
type="Organization", name=name, description="",
239+
type="Organization",
240+
name=name,
241+
description="",
240242
)
241243
self.mapping_cache[name] = author
242244
return author
@@ -350,8 +352,10 @@ def extract_embedded_relationships(self, stix_object, types=None) -> dict:
350352
"type": object_ref_result["entity_type"],
351353
}
352354
elif "observed-data" not in object_ref:
353-
object_ref_result = self.opencti.opencti_stix_object_or_stix_relationship.read(
354-
id=object_ref
355+
object_ref_result = (
356+
self.opencti.opencti_stix_object_or_stix_relationship.read(
357+
id=object_ref
358+
)
355359
)
356360
if object_ref_result is not None:
357361
self.mapping_cache[object_ref] = {
@@ -390,14 +394,18 @@ def extract_embedded_relationships(self, stix_object, types=None) -> dict:
390394
self.mapping_cache[url] = {"id": external_reference_id}
391395
external_references_ids.append(external_reference_id)
392396

393-
if stix_object["type"] in [
394-
"threat-actor",
395-
"intrusion-set",
396-
"campaign",
397-
"x-opencti-incident",
398-
"malware",
399-
"relationship",
400-
] and (types is None or "report" in types):
397+
if (
398+
stix_object["type"]
399+
in [
400+
"threat-actor",
401+
"intrusion-set",
402+
"campaign",
403+
"x-opencti-incident",
404+
"malware",
405+
"relationship",
406+
]
407+
and (types is None or "report" in types)
408+
):
401409
# Add a corresponding report
402410
# Extract date
403411
try:
@@ -443,11 +451,13 @@ def extract_embedded_relationships(self, stix_object, types=None) -> dict:
443451
"marking_tlpwhite"
444452
]
445453
else:
446-
object_marking_ref_result = self.opencti.marking_definition.read(
447-
filters=[
448-
{"key": "definition_type", "values": ["TLP"]},
449-
{"key": "definition", "values": ["TLP:WHITE"]},
450-
]
454+
object_marking_ref_result = (
455+
self.opencti.marking_definition.read(
456+
filters=[
457+
{"key": "definition_type", "values": ["TLP"]},
458+
{"key": "definition", "values": ["TLP:WHITE"]},
459+
]
460+
)
451461
)
452462
self.mapping_cache["marking_tlpwhite"] = {
453463
"id": object_marking_ref_result["id"]
@@ -551,7 +561,8 @@ def import_object(self, stix_object, update=False, types=None) -> list:
551561
stix_object["type"] = "location"
552562

553563
do_import = importer.get(
554-
stix_object["type"], lambda **kwargs: self.unknown_type(stix_object),
564+
stix_object["type"],
565+
lambda **kwargs: self.unknown_type(stix_object),
555566
)
556567
stix_object_results = do_import(
557568
stixObject=stix_object, extras=extras, update=update
@@ -802,14 +813,15 @@ def import_sighting(self, stix_sighting, from_id, to_id, update=False, types=Non
802813
if from_id in self.mapping_cache:
803814
final_from_id = self.mapping_cache[from_id]["id"]
804815
else:
805-
stix_object_result = self.opencti.opencti_stix_object_or_stix_relationship.read(
806-
id=from_id
816+
stix_object_result = (
817+
self.opencti.opencti_stix_object_or_stix_relationship.read(id=from_id)
807818
)
808819
if stix_object_result is not None:
809820
final_from_id = stix_object_result["id"]
810821
else:
811822
self.opencti.log(
812-
"error", "From ref of the sithing not found, doing nothing...",
823+
"error",
824+
"From ref of the sithing not found, doing nothing...",
813825
)
814826
return None
815827

@@ -819,14 +831,15 @@ def import_sighting(self, stix_sighting, from_id, to_id, update=False, types=Non
819831
if to_id in self.mapping_cache:
820832
final_to_id = self.mapping_cache[to_id]["id"]
821833
else:
822-
stix_object_result = self.opencti.opencti_stix_object_or_stix_relationship.read(
823-
id=to_id
834+
stix_object_result = (
835+
self.opencti.opencti_stix_object_or_stix_relationship.read(id=to_id)
824836
)
825837
if stix_object_result is not None:
826838
final_to_id = stix_object_result["id"]
827839
else:
828840
self.opencti.log(
829-
"error", "To ref of the sithing not found, doing nothing...",
841+
"error",
842+
"To ref of the sithing not found, doing nothing...",
830843
)
831844
return None
832845
date = datetime.datetime.today().strftime("%Y-%m-%dT%H:%M:%SZ")

0 commit comments

Comments
 (0)