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

Commit 98a4301

Browse files
committed
[client] Format with new black
1 parent 7df269e commit 98a4301

Some content is hidden

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

42 files changed

+2577
-1978
lines changed

pycti/connector/opencti_connector_helper.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,11 @@ def run(self) -> None:
299299
port=self.port,
300300
virtual_host=self.vhost,
301301
credentials=self.pika_credentials,
302-
ssl_options=pika.SSLOptions(
303-
create_mq_ssl_context(self.config), self.host
304-
)
305-
if self.use_ssl
306-
else None,
302+
ssl_options=(
303+
pika.SSLOptions(create_mq_ssl_context(self.config), self.host)
304+
if self.use_ssl
305+
else None
306+
),
307307
)
308308
self.pika_connection = pika.BlockingConnection(self.pika_parameters)
309309
self.channel = self.pika_connection.channel()
@@ -1035,12 +1035,14 @@ def send_stix2_bundle(self, bundle, **kwargs) -> list:
10351035
port=self.connector_config["connection"]["port"],
10361036
virtual_host=self.connector_config["connection"]["vhost"],
10371037
credentials=pika_credentials,
1038-
ssl_options=pika.SSLOptions(
1039-
create_mq_ssl_context(self.config),
1040-
self.connector_config["connection"]["host"],
1041-
)
1042-
if self.connector_config["connection"]["use_ssl"]
1043-
else None,
1038+
ssl_options=(
1039+
pika.SSLOptions(
1040+
create_mq_ssl_context(self.config),
1041+
self.connector_config["connection"]["host"],
1042+
)
1043+
if self.connector_config["connection"]["use_ssl"]
1044+
else None
1045+
),
10441046
)
10451047
pika_connection = pika.BlockingConnection(pika_parameters)
10461048
channel = pika_connection.channel()

pycti/entities/opencti_attack_pattern.py

Lines changed: 76 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -524,81 +524,99 @@ def import_from_stix2(self, **kwargs):
524524
else 0
525525
)
526526
if "x_mitre_platforms" not in stix_object:
527-
stix_object[
528-
"x_mitre_platforms"
529-
] = self.opencti.get_attribute_in_mitre_extension(
530-
"platforms", stix_object
527+
stix_object["x_mitre_platforms"] = (
528+
self.opencti.get_attribute_in_mitre_extension(
529+
"platforms", stix_object
530+
)
531531
)
532532
if "x_mitre_permissions_required" not in stix_object:
533-
stix_object[
534-
"x_mitre_permissions_required"
535-
] = self.opencti.get_attribute_in_mitre_extension(
536-
"permissions_required", stix_object
533+
stix_object["x_mitre_permissions_required"] = (
534+
self.opencti.get_attribute_in_mitre_extension(
535+
"permissions_required", stix_object
536+
)
537537
)
538538
if "x_mitre_detection" not in stix_object:
539-
stix_object[
540-
"x_mitre_detection"
541-
] = self.opencti.get_attribute_in_mitre_extension(
542-
"detection", stix_object
539+
stix_object["x_mitre_detection"] = (
540+
self.opencti.get_attribute_in_mitre_extension(
541+
"detection", stix_object
542+
)
543543
)
544544
if "x_opencti_stix_ids" not in stix_object:
545-
stix_object[
546-
"x_opencti_stix_ids"
547-
] = self.opencti.get_attribute_in_extension("stix_ids", stix_object)
545+
stix_object["x_opencti_stix_ids"] = (
546+
self.opencti.get_attribute_in_extension("stix_ids", stix_object)
547+
)
548548
if "x_opencti_granted_refs" not in stix_object:
549-
stix_object[
550-
"x_opencti_granted_refs"
551-
] = self.opencti.get_attribute_in_extension("granted_refs", stix_object)
549+
stix_object["x_opencti_granted_refs"] = (
550+
self.opencti.get_attribute_in_extension("granted_refs", stix_object)
551+
)
552552

553553
return self.create(
554554
stix_id=stix_object["id"],
555-
createdBy=extras["created_by_id"]
556-
if "created_by_id" in extras
557-
else None,
558-
objectMarking=extras["object_marking_ids"]
559-
if "object_marking_ids" in extras
560-
else None,
561-
objectLabel=extras["object_label_ids"]
562-
if "object_label_ids" in extras
563-
else None,
564-
externalReferences=extras["external_references_ids"]
565-
if "external_references_ids" in extras
566-
else None,
555+
createdBy=(
556+
extras["created_by_id"] if "created_by_id" in extras else None
557+
),
558+
objectMarking=(
559+
extras["object_marking_ids"]
560+
if "object_marking_ids" in extras
561+
else None
562+
),
563+
objectLabel=(
564+
extras["object_label_ids"] if "object_label_ids" in extras else None
565+
),
566+
externalReferences=(
567+
extras["external_references_ids"]
568+
if "external_references_ids" in extras
569+
else None
570+
),
567571
revoked=stix_object["revoked"] if "revoked" in stix_object else None,
568-
confidence=stix_object["confidence"]
569-
if "confidence" in stix_object
570-
else None,
572+
confidence=(
573+
stix_object["confidence"] if "confidence" in stix_object else None
574+
),
571575
lang=stix_object["lang"] if "lang" in stix_object else None,
572576
created=stix_object["created"] if "created" in stix_object else None,
573577
modified=stix_object["modified"] if "modified" in stix_object else None,
574578
name=stix_object["name"],
575-
description=self.opencti.stix2.convert_markdown(
576-
stix_object["description"]
577-
)
578-
if "description" in stix_object
579-
else None,
579+
description=(
580+
self.opencti.stix2.convert_markdown(stix_object["description"])
581+
if "description" in stix_object
582+
else None
583+
),
580584
aliases=self.opencti.stix2.pick_aliases(stix_object),
581-
x_mitre_platforms=stix_object["x_mitre_platforms"]
582-
if "x_mitre_platforms" in stix_object
583-
else stix_object["x_amitt_platforms"]
584-
if "x_amitt_platforms" in stix_object
585-
else None,
586-
x_mitre_permissions_required=stix_object["x_mitre_permissions_required"]
587-
if "x_mitre_permissions_required" in stix_object
588-
else None,
589-
x_mitre_detection=stix_object["x_mitre_detection"]
590-
if "x_mitre_detection" in stix_object
591-
else None,
585+
x_mitre_platforms=(
586+
stix_object["x_mitre_platforms"]
587+
if "x_mitre_platforms" in stix_object
588+
else (
589+
stix_object["x_amitt_platforms"]
590+
if "x_amitt_platforms" in stix_object
591+
else None
592+
)
593+
),
594+
x_mitre_permissions_required=(
595+
stix_object["x_mitre_permissions_required"]
596+
if "x_mitre_permissions_required" in stix_object
597+
else None
598+
),
599+
x_mitre_detection=(
600+
stix_object["x_mitre_detection"]
601+
if "x_mitre_detection" in stix_object
602+
else None
603+
),
592604
x_mitre_id=x_mitre_id,
593-
killChainPhases=extras["kill_chain_phases_ids"]
594-
if "kill_chain_phases_ids" in extras
595-
else None,
596-
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
597-
if "x_opencti_stix_ids" in stix_object
598-
else None,
599-
objectOrganization=stix_object["x_opencti_granted_refs"]
600-
if "x_opencti_granted_refs" in stix_object
601-
else None,
605+
killChainPhases=(
606+
extras["kill_chain_phases_ids"]
607+
if "kill_chain_phases_ids" in extras
608+
else None
609+
),
610+
x_opencti_stix_ids=(
611+
stix_object["x_opencti_stix_ids"]
612+
if "x_opencti_stix_ids" in stix_object
613+
else None
614+
),
615+
objectOrganization=(
616+
stix_object["x_opencti_granted_refs"]
617+
if "x_opencti_granted_refs" in stix_object
618+
else None
619+
),
602620
update=update,
603621
)
604622
else:

pycti/entities/opencti_campaign.py

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -450,57 +450,65 @@ def import_from_stix2(self, **kwargs):
450450
if stix_object is not None:
451451
# Search in extensions
452452
if "x_opencti_stix_ids" not in stix_object:
453-
stix_object[
454-
"x_opencti_stix_ids"
455-
] = self.opencti.get_attribute_in_extension("stix_ids", stix_object)
453+
stix_object["x_opencti_stix_ids"] = (
454+
self.opencti.get_attribute_in_extension("stix_ids", stix_object)
455+
)
456456
if "x_opencti_granted_refs" not in stix_object:
457-
stix_object[
458-
"x_opencti_granted_refs"
459-
] = self.opencti.get_attribute_in_extension("granted_refs", stix_object)
457+
stix_object["x_opencti_granted_refs"] = (
458+
self.opencti.get_attribute_in_extension("granted_refs", stix_object)
459+
)
460460

461461
return self.create(
462462
stix_id=stix_object["id"],
463-
createdBy=extras["created_by_id"]
464-
if "created_by_id" in extras
465-
else None,
466-
objectMarking=extras["object_marking_ids"]
467-
if "object_marking_ids" in extras
468-
else None,
469-
objectLabel=extras["object_label_ids"]
470-
if "object_label_ids" in extras
471-
else None,
472-
externalReferences=extras["external_references_ids"]
473-
if "external_references_ids" in extras
474-
else None,
463+
createdBy=(
464+
extras["created_by_id"] if "created_by_id" in extras else None
465+
),
466+
objectMarking=(
467+
extras["object_marking_ids"]
468+
if "object_marking_ids" in extras
469+
else None
470+
),
471+
objectLabel=(
472+
extras["object_label_ids"] if "object_label_ids" in extras else None
473+
),
474+
externalReferences=(
475+
extras["external_references_ids"]
476+
if "external_references_ids" in extras
477+
else None
478+
),
475479
revoked=stix_object["revoked"] if "revoked" in stix_object else None,
476-
confidence=stix_object["confidence"]
477-
if "confidence" in stix_object
478-
else None,
480+
confidence=(
481+
stix_object["confidence"] if "confidence" in stix_object else None
482+
),
479483
lang=stix_object["lang"] if "lang" in stix_object else None,
480484
created=stix_object["created"] if "created" in stix_object else None,
481485
modified=stix_object["modified"] if "modified" in stix_object else None,
482486
name=stix_object["name"],
483-
description=self.opencti.stix2.convert_markdown(
484-
stix_object["description"]
485-
)
486-
if "description" in stix_object
487-
else None,
487+
description=(
488+
self.opencti.stix2.convert_markdown(stix_object["description"])
489+
if "description" in stix_object
490+
else None
491+
),
488492
aliases=self.opencti.stix2.pick_aliases(stix_object),
489-
objective=stix_object["objective"]
490-
if "objective" in stix_object
491-
else None,
492-
first_seen=stix_object["first_seen"]
493-
if "first_seen" in stix_object
494-
else None,
495-
last_seen=stix_object["last_seen"]
496-
if "last_seen" in stix_object
497-
else None,
498-
x_opencti_stix_ids=stix_object["x_opencti_stix_ids"]
499-
if "x_opencti_stix_ids" in stix_object
500-
else None,
501-
objectOrganization=stix_object["x_opencti_granted_refs"]
502-
if "x_opencti_granted_refs" in stix_object
503-
else None,
493+
objective=(
494+
stix_object["objective"] if "objective" in stix_object else None
495+
),
496+
first_seen=(
497+
stix_object["first_seen"] if "first_seen" in stix_object else None
498+
),
499+
last_seen=(
500+
stix_object["last_seen"] if "last_seen" in stix_object else None
501+
),
502+
x_opencti_stix_ids=(
503+
stix_object["x_opencti_stix_ids"]
504+
if "x_opencti_stix_ids" in stix_object
505+
else None
506+
),
507+
objectOrganization=(
508+
stix_object["x_opencti_granted_refs"]
509+
if "x_opencti_granted_refs" in stix_object
510+
else None
511+
),
504512
update=update,
505513
)
506514
else:

0 commit comments

Comments
 (0)