From b12383eac23f65abe12121280bb50171acdd028d Mon Sep 17 00:00:00 2001 From: pyth0n1c Date: Wed, 9 Oct 2024 12:11:54 -0700 Subject: [PATCH] commit simple changes so that we can get this feature working now. Eventually the more robust changes will be merged from a separate branch --- contentctl/actions/inspect.py | 10 ++++++---- contentctl/objects/config.py | 18 +++++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/contentctl/actions/inspect.py b/contentctl/actions/inspect.py index 38bc2b23..261fd413 100644 --- a/contentctl/actions/inspect.py +++ b/contentctl/actions/inspect.py @@ -297,9 +297,11 @@ def check_detection_metadata(self, config: inspect) -> None: validation_errors[rule_name] = [] # No detections should be removed from build to build if rule_name not in current_build_conf.detection_stanzas: - validation_errors[rule_name].append(DetectionMissingError(rule_name=rule_name)) + if config.suppress_missing_content_exceptions: + print(f"[SUPPRESSED] {DetectionMissingError(rule_name=rule_name).long_message}") + else: + validation_errors[rule_name].append(DetectionMissingError(rule_name=rule_name)) continue - # Pull out the individual stanza for readability previous_stanza = previous_build_conf.detection_stanzas[rule_name] current_stanza = current_build_conf.detection_stanzas[rule_name] @@ -335,7 +337,7 @@ def check_detection_metadata(self, config: inspect) -> None: ) # Convert our dict mapping to a flat list of errors for use in reporting - validation_error_list = [x for inner_list in validation_errors.values() for x in inner_list] + validation_error_list = [x for inner_list in validation_errors.values() for x in inner_list] # Report failure/success print("\nDetection Metadata Validation:") @@ -355,4 +357,4 @@ def check_detection_metadata(self, config: inspect) -> None: raise ExceptionGroup( "Validation errors when comparing detection stanzas in current and previous build:", validation_error_list - ) + ) \ No newline at end of file diff --git a/contentctl/objects/config.py b/contentctl/objects/config.py index 0b262c55..f287d010 100644 --- a/contentctl/objects/config.py +++ b/contentctl/objects/config.py @@ -159,8 +159,6 @@ def getApp(self, config:test, stage_file=True)->str: verbose_print=True) return str(destination) - - # TODO (#266): disable the use_enum_values configuration class Config_Base(BaseModel): model_config = ConfigDict(use_enum_values=True,validate_default=True, arbitrary_types_allowed=True) @@ -288,7 +286,6 @@ def getAPIPath(self)->pathlib.Path: def getAppTemplatePath(self)->pathlib.Path: return self.path/"app_template" - class StackType(StrEnum): @@ -311,6 +308,16 @@ class inspect(build): "should be enabled." ) ) + suppress_missing_content_exceptions: bool = Field( + default=False, + description=( + "Suppress exceptions during metadata validation if a detection that existed in " + "the previous build does not exist in this build. This is to ensure that content " + "is not accidentally removed. In order to support testing both public and private " + "content, this warning can be suppressed. If it is suppressed, it will still be " + "printed out as a warning." + ) + ) enrichments: bool = Field( default=True, description=( @@ -952,7 +959,6 @@ def check_environment_variable_for_config(cls, v:List[Infrastructure]): index+=1 - class release_notes(Config_Base): old_tag:Optional[str] = Field(None, description="Name of the tag to diff against to find new content. " "If it is not supplied, then it will be inferred as the " @@ -1034,6 +1040,4 @@ def ensureNewTagOrLatestBranch(self): # raise ValueError("The latest_branch '{self.latest_branch}' was not found in the repository") - # return self - - + # return self \ No newline at end of file