From 94db182208d30496e19550e427743dcbb2b0289b Mon Sep 17 00:00:00 2001 From: pyth0n1c <87383215+pyth0n1c@users.noreply.github.com> Date: Mon, 12 May 2025 17:12:43 -0700 Subject: [PATCH 1/4] bump to v2 naming schema for json api objects --- contentctl/output/api_json_output.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/contentctl/output/api_json_output.py b/contentctl/output/api_json_output.py index 846d44bb..79c877de 100644 --- a/contentctl/output/api_json_output.py +++ b/contentctl/output/api_json_output.py @@ -17,6 +17,9 @@ from contentctl.output.json_writer import JsonWriter + +JSON_API_VERSION = 2 + class ApiJsonOutput: output_path: pathlib.Path app_label: str @@ -70,7 +73,7 @@ def writeDetections( # del() JsonWriter.writeJsonObject( - os.path.join(self.output_path, "detections.json"), "detections", detections + os.path.join(self.output_path, f"detections_v{JSON_API_VERSION}.json"), "detections", detections ) def writeMacros( @@ -86,7 +89,7 @@ def writeMacros( if k in macro: del macro[k] JsonWriter.writeJsonObject( - os.path.join(self.output_path, "macros.json"), "macros", macros + os.path.join(self.output_path, f"macros_v{JSON_API_VERSION}.json"), "macros", macros ) def writeStories( @@ -132,7 +135,7 @@ def writeStories( ] JsonWriter.writeJsonObject( - os.path.join(self.output_path, "stories.json"), "stories", stories + os.path.join(self.output_path, f"stories_v{JSON_API_VERSION}.json"), "stories", stories ) def writeBaselines( @@ -163,7 +166,7 @@ def writeBaselines( ] JsonWriter.writeJsonObject( - os.path.join(self.output_path, "baselines.json"), "baselines", baselines + os.path.join(self.output_path, f"baselines_v{JSON_API_VERSION}.json"), "baselines", baselines ) def writeInvestigations( @@ -195,7 +198,7 @@ def writeInvestigations( for investigation in objects ] JsonWriter.writeJsonObject( - os.path.join(self.output_path, "response_tasks.json"), + os.path.join(self.output_path, f"response_tasks_v{JSON_API_VERSION}.json"), "response_tasks", investigations, ) @@ -227,7 +230,7 @@ def writeLookups( if k in lookup: del lookup[k] JsonWriter.writeJsonObject( - os.path.join(self.output_path, "lookups.json"), "lookups", lookups + os.path.join(self.output_path, f"lookups_v{JSON_API_VERSION}.json"), "lookups", lookups ) def writeDeployments( @@ -255,7 +258,7 @@ def writeDeployments( # references are not to be included, but have been deleted in the # model_serialization logic JsonWriter.writeJsonObject( - os.path.join(self.output_path, "deployments.json"), + os.path.join(self.output_path, f"deployments_v{JSON_API_VERSION}.json"), "deployments", deployments, ) From 7606c360cef6fd21b043b2b8c80d8ecce3cd4563 Mon Sep 17 00:00:00 2001 From: pyth0n1c <87383215+pyth0n1c@users.noreply.github.com> Date: Mon, 12 May 2025 17:16:39 -0700 Subject: [PATCH 2/4] bump version.json file to version_v2.json as well --- contentctl/actions/build.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contentctl/actions/build.py b/contentctl/actions/build.py index 6d5e96bd..21e1108d 100644 --- a/contentctl/actions/build.py +++ b/contentctl/actions/build.py @@ -6,7 +6,7 @@ from contentctl.input.director import DirectorOutputDto from contentctl.objects.config import build -from contentctl.output.api_json_output import ApiJsonOutput +from contentctl.output.api_json_output import ApiJsonOutput, JSON_API_VERSION from contentctl.output.conf_output import ConfOutput from contentctl.output.conf_writer import ConfWriter @@ -76,7 +76,7 @@ def execute(self, input_dto: BuildInputDto) -> DirectorOutputDto: api_json_output.writeDeployments(input_dto.director_output_dto.deployments) # create version file for sse api - version_file = input_dto.config.getAPIPath() / "version.json" + version_file = input_dto.config.getAPIPath() / f"version_v{JSON_API_VERSION}.json" utc_time = ( datetime.datetime.now(datetime.timezone.utc) .replace(microsecond=0, tzinfo=None) From 70e86b232367c6fd1e7f64342c46e6e64fffe08e Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 13 May 2025 12:01:06 -0700 Subject: [PATCH 3/4] fix ruff error --- contentctl/actions/build.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/contentctl/actions/build.py b/contentctl/actions/build.py index 21e1108d..64bcad4e 100644 --- a/contentctl/actions/build.py +++ b/contentctl/actions/build.py @@ -6,7 +6,7 @@ from contentctl.input.director import DirectorOutputDto from contentctl.objects.config import build -from contentctl.output.api_json_output import ApiJsonOutput, JSON_API_VERSION +from contentctl.output.api_json_output import JSON_API_VERSION, ApiJsonOutput from contentctl.output.conf_output import ConfOutput from contentctl.output.conf_writer import ConfWriter @@ -76,7 +76,9 @@ def execute(self, input_dto: BuildInputDto) -> DirectorOutputDto: api_json_output.writeDeployments(input_dto.director_output_dto.deployments) # create version file for sse api - version_file = input_dto.config.getAPIPath() / f"version_v{JSON_API_VERSION}.json" + version_file = ( + input_dto.config.getAPIPath() / f"version_v{JSON_API_VERSION}.json" + ) utc_time = ( datetime.datetime.now(datetime.timezone.utc) .replace(microsecond=0, tzinfo=None) From 90c9399d7de17e3e001b1f3b1eff51475a9b50c4 Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 13 May 2025 12:08:08 -0700 Subject: [PATCH 4/4] lint and format another file --- contentctl/output/api_json_output.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/contentctl/output/api_json_output.py b/contentctl/output/api_json_output.py index 79c877de..dabf18fd 100644 --- a/contentctl/output/api_json_output.py +++ b/contentctl/output/api_json_output.py @@ -16,10 +16,9 @@ from contentctl.output.json_writer import JsonWriter - - JSON_API_VERSION = 2 + class ApiJsonOutput: output_path: pathlib.Path app_label: str @@ -73,7 +72,9 @@ def writeDetections( # del() JsonWriter.writeJsonObject( - os.path.join(self.output_path, f"detections_v{JSON_API_VERSION}.json"), "detections", detections + os.path.join(self.output_path, f"detections_v{JSON_API_VERSION}.json"), + "detections", + detections, ) def writeMacros( @@ -89,7 +90,9 @@ def writeMacros( if k in macro: del macro[k] JsonWriter.writeJsonObject( - os.path.join(self.output_path, f"macros_v{JSON_API_VERSION}.json"), "macros", macros + os.path.join(self.output_path, f"macros_v{JSON_API_VERSION}.json"), + "macros", + macros, ) def writeStories( @@ -135,7 +138,9 @@ def writeStories( ] JsonWriter.writeJsonObject( - os.path.join(self.output_path, f"stories_v{JSON_API_VERSION}.json"), "stories", stories + os.path.join(self.output_path, f"stories_v{JSON_API_VERSION}.json"), + "stories", + stories, ) def writeBaselines( @@ -166,7 +171,9 @@ def writeBaselines( ] JsonWriter.writeJsonObject( - os.path.join(self.output_path, f"baselines_v{JSON_API_VERSION}.json"), "baselines", baselines + os.path.join(self.output_path, f"baselines_v{JSON_API_VERSION}.json"), + "baselines", + baselines, ) def writeInvestigations( @@ -230,7 +237,9 @@ def writeLookups( if k in lookup: del lookup[k] JsonWriter.writeJsonObject( - os.path.join(self.output_path, f"lookups_v{JSON_API_VERSION}.json"), "lookups", lookups + os.path.join(self.output_path, f"lookups_v{JSON_API_VERSION}.json"), + "lookups", + lookups, ) def writeDeployments(