Skip to content

Commit

Permalink
feat(models): handle is_excluded and exclude_reason in PolicyBreak
Browse files Browse the repository at this point in the history
  • Loading branch information
gg-mmill committed Oct 14, 2024
1 parent 2c10769 commit a0c1ea9
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Removed
- A bullet item for the Removed category.
-->
<!--
### Added
- A bullet item for the Added category.
-->
<!--
### Changed
- A bullet item for the Changed category.
-->
- Handles `is_excluded` and `exclude_reason` fields in `PolicyBreak`
<!--
### Deprecated
- A bullet item for the Deprecated category.
-->
<!--
### Fixed
- A bullet item for the Fixed category.
-->
<!--
### Security
- A bullet item for the Security category.
-->
6 changes: 6 additions & 0 deletions pygitguardian/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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__()
Expand All @@ -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:
Expand Down
28 changes: 28 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a0c1ea9

Please sign in to comment.