Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally suppress missing detections during metadata validation #305

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions contentctl/actions/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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:")
Expand All @@ -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
)
)
18 changes: 11 additions & 7 deletions contentctl/objects/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -288,7 +286,6 @@ def getAPIPath(self)->pathlib.Path:

def getAppTemplatePath(self)->pathlib.Path:
return self.path/"app_template"



class StackType(StrEnum):
Expand All @@ -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=(
Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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
Loading