diff --git a/changelog.d/20241014_101918_mathias.millet_handle_excluded_policy_breaks.md b/changelog.d/20241014_101918_mathias.millet_handle_excluded_policy_breaks.md new file mode 100644 index 00000000..28fc6ccd --- /dev/null +++ b/changelog.d/20241014_101918_mathias.millet_handle_excluded_policy_breaks.md @@ -0,0 +1,43 @@ + + + + + +- Handles `is_excluded` and `exclude_reason` fields in `PolicyBreak` + + + diff --git a/pygitguardian/models.py b/pygitguardian/models.py index 9e3b53ae..ac447205 100644 --- a/pygitguardian/models.py +++ b/pygitguardian/models.py @@ -262,6 +262,8 @@ class PolicyBreakSchema(BaseSchema): known_secret = fields.Boolean(required=False, load_default=False, dump_default=None) incident_url = fields.String(required=False, load_default=None, dump_default=None) matches = fields.List(fields.Nested(MatchSchema), required=True) + is_excluded = fields.Boolean(required=False, load_default=False, dump_default=False) + exclude_reason = fields.String(required=False, load_default=None, dump_default=None) @post_load def make_policy_break(self, data: Dict[str, Any], **kwargs: Any) -> "PolicyBreak": @@ -286,6 +288,8 @@ def __init__( matches: List[Match], known_secret: bool = False, incident_url: Optional[str] = None, + is_excluded: Optional[bool] = False, + exclude_reason: Optional[str] = None, **kwargs: Any, ) -> None: super().__init__() @@ -295,6 +299,8 @@ def __init__( self.known_secret = known_secret self.incident_url = incident_url self.matches = matches + self.is_excluded = is_excluded + self.exclude_reason = exclude_reason @property def is_secret(self) -> bool: diff --git a/tests/test_models.py b/tests/test_models.py index 1c1acca9..dbddde79 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -111,6 +111,34 @@ def test_document_handle_surrogates(self): "matches": [{"match": "hello", "type": "hello"}], }, ), + ( + PolicyBreakSchema, + PolicyBreak, + { + "type": "hello", + "policy": "hello", + "validity": "hey", + "known_secret": True, + "incident_url": "https://api.gitguardian.com/workspace/2/incidents/3", + "matches": [{"match": "hello", "type": "hello"}], + "is_excluded": True, + "exclude_reason": "bad secret", + }, + ), + ( + PolicyBreakSchema, + PolicyBreak, + { + "type": "hello", + "policy": "hello", + "validity": "hey", + "known_secret": True, + "incident_url": "https://api.gitguardian.com/workspace/2/incidents/3", + "matches": [{"match": "hello", "type": "hello"}], + "is_excluded": False, + "exclude_reason": None, + }, + ), ( QuotaSchema, Quota,