Skip to content

Commit 90a4f88

Browse files
committed
feat(models): handle is_excluded and exclude_reason in PolicyBreak
1 parent d754ed5 commit 90a4f88

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
-->
6+
7+
<!--
8+
### Removed
9+
10+
- A bullet item for the Removed category.
11+
12+
-->
13+
<!--
14+
### Added
15+
16+
- A bullet item for the Added category.
17+
18+
-->
19+
20+
### Changed
21+
22+
- `PolicyBreak` now contains two new fields: `is_excluded` and `exclude_reason`.
23+
<!--
24+
25+
### Deprecated
26+
27+
- A bullet item for the Deprecated category.
28+
29+
-->
30+
31+
<!--
32+
### Fixed
33+
34+
- A bullet item for the Fixed category.
35+
36+
-->
37+
<!--
38+
### Security
39+
40+
- A bullet item for the Security category.
41+
42+
-->

pygitguardian/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ class PolicyBreakSchema(BaseSchema):
262262
known_secret = fields.Boolean(required=False, load_default=False, dump_default=None)
263263
incident_url = fields.String(required=False, load_default=None, dump_default=None)
264264
matches = fields.List(fields.Nested(MatchSchema), required=True)
265+
is_excluded = fields.Boolean(required=False, load_default=False, dump_default=False)
266+
exclude_reason = fields.String(required=False, load_default=None, dump_default=None)
265267

266268
@post_load
267269
def make_policy_break(self, data: Dict[str, Any], **kwargs: Any) -> "PolicyBreak":
@@ -286,6 +288,8 @@ def __init__(
286288
matches: List[Match],
287289
known_secret: bool = False,
288290
incident_url: Optional[str] = None,
291+
is_excluded: bool = False,
292+
exclude_reason: Optional[str] = None,
289293
**kwargs: Any,
290294
) -> None:
291295
super().__init__()
@@ -295,6 +299,8 @@ def __init__(
295299
self.known_secret = known_secret
296300
self.incident_url = incident_url
297301
self.matches = matches
302+
self.is_excluded = is_excluded
303+
self.exclude_reason = exclude_reason
298304

299305
@property
300306
def is_secret(self) -> bool:

tests/test_models.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,34 @@ def test_document_handle_surrogates(self):
111111
"matches": [{"match": "hello", "type": "hello"}],
112112
},
113113
),
114+
(
115+
PolicyBreakSchema,
116+
PolicyBreak,
117+
{
118+
"type": "hello",
119+
"policy": "hello",
120+
"validity": "hey",
121+
"known_secret": True,
122+
"incident_url": "https://api.gitguardian.com/workspace/2/incidents/3",
123+
"matches": [{"match": "hello", "type": "hello"}],
124+
"is_excluded": True,
125+
"exclude_reason": "bad secret",
126+
},
127+
),
128+
(
129+
PolicyBreakSchema,
130+
PolicyBreak,
131+
{
132+
"type": "hello",
133+
"policy": "hello",
134+
"validity": "hey",
135+
"known_secret": True,
136+
"incident_url": "https://api.gitguardian.com/workspace/2/incidents/3",
137+
"matches": [{"match": "hello", "type": "hello"}],
138+
"is_excluded": False,
139+
"exclude_reason": None,
140+
},
141+
),
114142
(
115143
QuotaSchema,
116144
Quota,

0 commit comments

Comments
 (0)