mirror of
https://github.com/MISP/misp-galaxy.git
synced 2024-11-26 08:47:18 +00:00
Merge pull request #932 from NMD03/formatted
Ignore deprecated galaxies + bugfix
This commit is contained in:
commit
a94fd523db
1 changed files with 51 additions and 17 deletions
|
@ -10,6 +10,8 @@ import validators
|
||||||
|
|
||||||
CLUSTER_PATH = "../../clusters"
|
CLUSTER_PATH = "../../clusters"
|
||||||
SITE_PATH = "./site/docs"
|
SITE_PATH = "./site/docs"
|
||||||
|
GALAXY_PATH = "../../galaxies"
|
||||||
|
|
||||||
|
|
||||||
FILES_TO_IGNORE = [] # if you want to skip a specific cluster in the generation
|
FILES_TO_IGNORE = [] # if you want to skip a specific cluster in the generation
|
||||||
|
|
||||||
|
@ -63,6 +65,7 @@ class Galaxy:
|
||||||
def __init__(
|
def __init__(
|
||||||
self, cluster_list: List[dict], authors, description, name, json_file_name
|
self, cluster_list: List[dict], authors, description, name, json_file_name
|
||||||
):
|
):
|
||||||
|
|
||||||
self.cluster_list = cluster_list
|
self.cluster_list = cluster_list
|
||||||
self.authors = authors
|
self.authors = authors
|
||||||
self.description = description
|
self.description = description
|
||||||
|
@ -203,7 +206,9 @@ class Cluster:
|
||||||
if meta not in excluded_meta:
|
if meta not in excluded_meta:
|
||||||
self.entry += f" | {meta} | {self.meta[meta]} |\n"
|
self.entry += f" | {meta} | {self.meta[meta]} |\n"
|
||||||
|
|
||||||
def get_related_clusters(self, cluster_dict, depth=-1, visited=None, level=1):
|
def get_related_clusters(
|
||||||
|
self, cluster_dict, depth=-1, visited=None, level=1, related_private_clusters={}
|
||||||
|
):
|
||||||
global public_relations_count
|
global public_relations_count
|
||||||
global private_relations_count
|
global private_relations_count
|
||||||
global private_clusters
|
global private_clusters
|
||||||
|
@ -234,6 +239,15 @@ class Cluster:
|
||||||
private_relations_count += 1
|
private_relations_count += 1
|
||||||
if dest_uuid not in private_clusters:
|
if dest_uuid not in private_clusters:
|
||||||
private_clusters.append(dest_uuid)
|
private_clusters.append(dest_uuid)
|
||||||
|
if dest_uuid in related_private_clusters:
|
||||||
|
related_clusters.append(
|
||||||
|
(
|
||||||
|
self,
|
||||||
|
related_private_clusters[dest_uuid],
|
||||||
|
level,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
related_clusters.append(
|
related_clusters.append(
|
||||||
(
|
(
|
||||||
self,
|
self,
|
||||||
|
@ -249,6 +263,7 @@ class Cluster:
|
||||||
level,
|
level,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
related_private_clusters[dest_uuid] = related_clusters[-1][1]
|
||||||
continue
|
continue
|
||||||
|
|
||||||
related_cluster = cluster_dict[dest_uuid]
|
related_cluster = cluster_dict[dest_uuid]
|
||||||
|
@ -265,7 +280,13 @@ class Cluster:
|
||||||
if cluster["dest-uuid"] in cluster_dict:
|
if cluster["dest-uuid"] in cluster_dict:
|
||||||
related_clusters += cluster_dict[
|
related_clusters += cluster_dict[
|
||||||
cluster["dest-uuid"]
|
cluster["dest-uuid"]
|
||||||
].get_related_clusters(cluster_dict, new_depth, visited, level + 1)
|
].get_related_clusters(
|
||||||
|
cluster_dict,
|
||||||
|
new_depth,
|
||||||
|
visited,
|
||||||
|
level + 1,
|
||||||
|
related_private_clusters,
|
||||||
|
)
|
||||||
|
|
||||||
if empty_uuids > 0:
|
if empty_uuids > 0:
|
||||||
empty_uuids_dict[self.value] = empty_uuids
|
empty_uuids_dict[self.value] = empty_uuids
|
||||||
|
@ -370,9 +391,9 @@ class Cluster:
|
||||||
|
|
||||||
def create_index(galaxies):
|
def create_index(galaxies):
|
||||||
index_output = INTRO
|
index_output = INTRO
|
||||||
index_output += STATISTICS
|
|
||||||
for galaxie in galaxies:
|
for galaxie in galaxies:
|
||||||
index_output += f"- [{galaxie.name}](./{galaxie.json_file_name}/index.md)\n"
|
index_output += f"- [{galaxie.name}](./{galaxie.json_file_name}/index.md)\n"
|
||||||
|
index_output += STATISTICS
|
||||||
index_output += CONTRIBUTING
|
index_output += CONTRIBUTING
|
||||||
return index_output
|
return index_output
|
||||||
|
|
||||||
|
@ -482,8 +503,21 @@ def create_statistics(cluster_dict):
|
||||||
return statistic_output
|
return statistic_output
|
||||||
|
|
||||||
|
|
||||||
|
def get_deprecated_galaxy_files():
|
||||||
|
deprecated_galaxy_files = []
|
||||||
|
for f in os.listdir(GALAXY_PATH):
|
||||||
|
with open(os.path.join(GALAXY_PATH, f)) as fr:
|
||||||
|
galaxy_json = json.load(fr)
|
||||||
|
if "namespace" in galaxy_json and galaxy_json["namespace"] == "deprecated":
|
||||||
|
deprecated_galaxy_files.append(f)
|
||||||
|
|
||||||
|
return deprecated_galaxy_files
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
||||||
|
FILES_TO_IGNORE.extend(get_deprecated_galaxy_files())
|
||||||
galaxies_fnames = []
|
galaxies_fnames = []
|
||||||
for f in os.listdir(CLUSTER_PATH):
|
for f in os.listdir(CLUSTER_PATH):
|
||||||
if ".json" in f and f not in FILES_TO_IGNORE:
|
if ".json" in f and f not in FILES_TO_IGNORE:
|
||||||
|
|
Loading…
Reference in a new issue