From 5e23fe8dbef353cd4f93cba6f121a4d5379614f2 Mon Sep 17 00:00:00 2001 From: Mathias Millet Date: Tue, 17 Dec 2024 09:26:20 +0100 Subject: [PATCH] feat: add ignore reason to json output --- ggshield/verticals/secret/output/schemas.py | 2 ++ .../verticals/secret/output/secret_json_output_handler.py | 4 ++++ ggshield/verticals/secret/secret_scan_collection.py | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/ggshield/verticals/secret/output/schemas.py b/ggshield/verticals/secret/output/schemas.py index 78c5dbf332..a19e617002 100644 --- a/ggshield/verticals/secret/output/schemas.py +++ b/ggshield/verticals/secret/output/schemas.py @@ -14,6 +14,8 @@ class FlattenedPolicyBreak(BaseSchema): incident_url = fields.String(required=True, dump_default="") incident_details = fields.Nested(SecretIncidentSchema) known_secret = fields.Bool(required=True, dump_default=False) + is_ignored = fields.Bool(required=False) + ignore_reason = fields.String(required=False) class JSONResultSchema(BaseSchema): diff --git a/ggshield/verticals/secret/output/secret_json_output_handler.py b/ggshield/verticals/secret/output/secret_json_output_handler.py index 64de72f643..e8d7cbb562 100644 --- a/ggshield/verticals/secret/output/secret_json_output_handler.py +++ b/ggshield/verticals/secret/output/secret_json_output_handler.py @@ -132,6 +132,10 @@ def serialized_policy_break( if details is not None: flattened_dict["incident_details"] = details + if policy_breaks[0].ignore_reason is not None: + flattened_dict["is_ignored"] = True + flattened_dict["ignore_reason"] = policy_breaks[0].ignore_reason + for policy_break in policy_breaks: flattened_dict["occurrences"].extend( self.serialize_policy_break_matches(policy_break) diff --git a/ggshield/verticals/secret/secret_scan_collection.py b/ggshield/verticals/secret/secret_scan_collection.py index 627985d4db..4a1fe103e9 100644 --- a/ggshield/verticals/secret/secret_scan_collection.py +++ b/ggshield/verticals/secret/secret_scan_collection.py @@ -52,6 +52,12 @@ def to_human_readable(self): res += f"({self.detail})" return res + def to_machine_readable(self): + res = self.kind.name.lower() + if self.detail: + res += f"({self.detail})" + return res + def compute_ignore_reason( policy_break: PolicyBreak, secret_config: SecretConfig