Add [tidal] sub option

This commit is contained in:
niclas 2024-03-05 14:18:15 +01:00
parent 1a5ccd23a2
commit cde860647c
3 changed files with 100 additions and 89 deletions

View file

@ -156,7 +156,7 @@ document$.subscribe(function () {
// Create nodes // Create nodes
var node = svg.append("g") var node = svg.append("g")
.attr("stroke", "#fff") .attr("stroke", "#D3D3D3")
.attr("stroke-width", 1.5) .attr("stroke-width", 1.5)
.selectAll("circle") .selectAll("circle")
.data(nodes) .data(nodes)

View file

@ -17,7 +17,7 @@ GALAXY_PATH = "../../galaxies"
CLUSTER_PATH = "../../clusters" CLUSTER_PATH = "../../clusters"
def create_galaxy(endpoint: str, version: int, extended_relations: bool = False): def create_galaxy(endpoint: str, version: int, extended_relations: bool = False, create_subs: bool = False):
api = TidalAPI() api = TidalAPI()
data = api.get_data(endpoint) data = api.get_data(endpoint)
with open(f"{CONFIG}/{endpoint}.json", "r") as file: with open(f"{CONFIG}/{endpoint}.json", "r") as file:
@ -28,16 +28,16 @@ def create_galaxy(endpoint: str, version: int, extended_relations: bool = False)
match endpoint: match endpoint:
case "groups": case "groups":
cluster = GroupCluster(**config["cluster"], uuid=galaxy.uuid, enrichment=extended_relations) cluster = GroupCluster(**config["cluster"], uuid=galaxy.uuid, enrichment=extended_relations, subs=create_subs)
cluster.add_values(data) cluster.add_values(data)
case "software": case "software":
cluster = SoftwareCluster(**config["cluster"], uuid=galaxy.uuid, enrichment=extended_relations) cluster = SoftwareCluster(**config["cluster"], uuid=galaxy.uuid, enrichment=extended_relations, subs=create_subs)
cluster.add_values(data) cluster.add_values(data)
case "campaigns": case "campaigns":
cluster = CampaignsCluster(**config["cluster"], uuid=galaxy.uuid) cluster = CampaignsCluster(**config["cluster"], uuid=galaxy.uuid)
cluster.add_values(data) cluster.add_values(data)
case "technique": case "technique":
cluster = TechniqueCluster(**config["cluster"], uuid=galaxy.uuid) cluster = TechniqueCluster(**config["cluster"], uuid=galaxy.uuid, subs=create_subs)
cluster.add_values(data) cluster.add_values(data)
case "tactic": case "tactic":
cluster = TacticCluster(**config["cluster"], uuid=galaxy.uuid) cluster = TacticCluster(**config["cluster"], uuid=galaxy.uuid)
@ -56,9 +56,9 @@ def create_galaxy(endpoint: str, version: int, extended_relations: bool = False)
def main(args, galaxies): def main(args, galaxies):
if args.all: if args.all:
for galaxy in galaxies: for galaxy in galaxies:
create_galaxy(galaxy, args.version, args.extended_relations) create_galaxy(galaxy, args.version, args.extended_relations, args.create_subs)
else: else:
create_galaxy(args.type, args.version, args.extended_relations) create_galaxy(args.type, args.version, args.extended_relations, args.create_subs)
if __name__ == "__main__": if __name__ == "__main__":
@ -92,7 +92,12 @@ if __name__ == "__main__":
parser.add_argument( parser.add_argument(
"--extended-relations", "--extended-relations",
action="store_true", action="store_true",
help="Create extended relations in the cluster", help="Create extended relations for the clusters",
)
parser.add_argument(
"--create-subs",
action="store_true",
help="Create subclusters from the API",
) )
parser.set_defaults(func=main) parser.set_defaults(func=main)

View file

@ -177,9 +177,11 @@ class GroupCluster(Cluster):
type: str, type: str,
uuid: str, uuid: str,
enrichment: bool = False, enrichment: bool = False,
subs: bool = False,
): ):
super().__init__(authors, category, description, name, source, type, uuid) super().__init__(authors, category, description, name, source, type, uuid)
self.enrichment = enrichment self.enrichment = enrichment
self.subs = subs
def add_values(self, data): def add_values(self, data):
for entry in data["data"]: for entry in data["data"]:
@ -213,7 +215,7 @@ class GroupCluster(Cluster):
"type": "similar", "type": "similar",
} }
) )
if self.subs:
for associated_group in entry.get("associated_groups"): for associated_group in entry.get("associated_groups"):
associated_meta = AssociatedGroupsMeta( associated_meta = AssociatedGroupsMeta(
id=associated_group.get("id"), id=associated_group.get("id"),
@ -241,7 +243,6 @@ class GroupCluster(Cluster):
"type": "similar", "type": "similar",
} }
) )
value = ClusterValue( value = ClusterValue(
description=entry.get("description"), description=entry.get("description"),
meta=meta, meta=meta,
@ -263,9 +264,11 @@ class SoftwareCluster(Cluster):
type: str, type: str,
uuid: str, uuid: str,
enrichment: bool = False, enrichment: bool = False,
subs: bool = False,
): ):
super().__init__(authors, category, description, name, source, type, uuid) super().__init__(authors, category, description, name, source, type, uuid)
self.enrichment = enrichment self.enrichment = enrichment
self.subs = subs
def add_values(self, data): def add_values(self, data):
for entry in data["data"]: for entry in data["data"]:
@ -307,7 +310,7 @@ class SoftwareCluster(Cluster):
"type": "similar", "type": "similar",
} }
) )
if self.subs:
for associated_software in entry.get("associated_software"): for associated_software in entry.get("associated_software"):
associated_meta = AssociatedSoftwareMeta( associated_meta = AssociatedSoftwareMeta(
id=associated_software.get("id"), id=associated_software.get("id"),
@ -356,8 +359,10 @@ class TechniqueCluster(Cluster):
source: str, source: str,
type: str, type: str,
uuid: str, uuid: str,
subs: bool = False,
): ):
super().__init__(authors, category, description, name, source, type, uuid) super().__init__(authors, category, description, name, source, type, uuid)
self.subs = subs
def add_values(self, data): def add_values(self, data):
for entry in data["data"]: for entry in data["data"]:
@ -376,6 +381,7 @@ class TechniqueCluster(Cluster):
} }
) )
if self.subs:
for sub_technique in entry.get("sub_technique"): for sub_technique in entry.get("sub_technique"):
sub_meta = SubTechniqueMeta( sub_meta = SubTechniqueMeta(
source=sub_technique.get("source"), source=sub_technique.get("source"),