Skip to content

Commit

Permalink
add new option to contentctl inspect that makes missing detections NO…
Browse files Browse the repository at this point in the history
…T an error - instead just print a warning message.
  • Loading branch information
pyth0n1c committed Sep 30, 2024
1 parent 5488ca6 commit 82e350d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
8 changes: 5 additions & 3 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.exception_on_removed_detections:
validation_errors[rule_name].append(DetectionMissingError(rule_name=rule_name))
else:
print(f"[SUPPRESSED] {DetectionMissingError(rule_name=rule_name).long_message}")
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 Down
14 changes: 8 additions & 6 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,14 @@ class inspect(build):
"should be enabled."
)
)
exception_on_removed_detections: bool = Field(
default=True,
description=(
"Throw an exception 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."
)
)
enrichments: bool = Field(
default=True,
description=(
Expand Down Expand Up @@ -952,7 +957,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 @@ -1035,5 +1039,3 @@ def ensureNewTagOrLatestBranch(self):


# return self


0 comments on commit 82e350d

Please sign in to comment.