Skip to content

Commit fb15a1c

Browse files
committed
feat(scan_results): Add detector_name, detector_group_name and documentation url
1 parent d246b6a commit fb15a1c

File tree

7 files changed

+138
-67
lines changed

7 files changed

+138
-67
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
- Add extra information to scan results: detector name, detector group name, and documentation URL.
17+
18+
<!--
19+
### Changed
20+
21+
- A bullet item for the Changed category.
22+
23+
-->
24+
<!--
25+
### Deprecated
26+
27+
- A bullet item for the Deprecated category.
28+
29+
-->
30+
<!--
31+
### Fixed
32+
33+
- A bullet item for the Fixed category.
34+
35+
-->
36+
<!--
37+
### Security
38+
39+
- A bullet item for the Security category.
40+
41+
-->

pygitguardian/models.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ class DiffKind(str, Enum):
216216

217217
class PolicyBreakSchema(BaseSchema):
218218
break_type = fields.String(data_key="type", required=True)
219+
detector_name = fields.String(required=True)
220+
detector_group_name = fields.String(required=True)
221+
documentation_url = fields.String(
222+
required=False, load_default=None, dump_default=None
223+
)
219224
policy = fields.String(required=True)
220225
validity = fields.String(required=False, load_default=None, dump_default=None)
221226
known_secret = fields.Boolean(required=False, load_default=False, dump_default=None)
@@ -245,9 +250,12 @@ class PolicyBreak(FromDictWithBase):
245250
def __init__(
246251
self,
247252
break_type: str,
253+
detector_name: str,
254+
detector_group_name: str,
248255
policy: str,
249256
validity: str,
250257
matches: List[Match],
258+
documentation_url: Optional[str] = None,
251259
known_secret: bool = False,
252260
incident_url: Optional[str] = None,
253261
is_excluded: bool = False,
@@ -257,6 +265,9 @@ def __init__(
257265
) -> None:
258266
super().__init__()
259267
self.break_type = break_type
268+
self.detector_name = detector_name
269+
self.detector_group_name = detector_group_name
270+
self.documentation_url = documentation_url
260271
self.policy = policy
261272
self.validity = validity
262273
self.known_secret = known_secret

tests/cassettes/secret.yaml

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,49 @@ interactions:
1515
Content-Type:
1616
- application/json
1717
User-Agent:
18-
- pygitguardian/1.3.4 (Linux;py3.8.10)
18+
- pygitguardian/1.20.0 (Linux;py3.10.13)
1919
method: POST
2020
uri: https://api.gitguardian.com/v1/scan
2121
response:
2222
body:
2323
string:
24-
'{"policy_break_count":1,"policies":["File extensions","Filenames","Secrets
25-
detection"],"policy_breaks":[{"type":"Basic Auth String","policy":"Secrets
26-
detection","matches":[{"type":"username","match":"jen_barber","index_start":40,"index_end":49,"line_start":2,"line_end":2},{"type":"password","match":"correcthorsebatterystaple","index_start":51,"index_end":75,"line_start":2,"line_end":2},{"type":"host","match":"cake.gitguardian.com","index_start":77,"index_end":96,"line_start":2,"line_end":2}],"validity":"no_checker"}]}'
24+
'{"policy_break_count":1,"policies":["Secrets detection"],"policy_breaks":[{"type":"Basic
25+
Auth String","detector_name":"basic_auth_string","detector_group_name":"basic_auth_string","documentation_url":"https://docs.gitguardian.com/secrets-detection/secrets-detection-engine/detectors/generics/basic_auth_string","policy":"Secrets
26+
detection","matches":[{"type":"username","match":"jen_barber","index_start":45,"index_end":54,"line_start":3,"line_end":3},{"type":"password","match":"correcthorsebatterystaple","index_start":56,"index_end":80,"line_start":3,"line_end":3},{"type":"host","match":"cake.gitguardian.com","index_start":82,"index_end":101,"line_start":3,"line_end":3}],"is_excluded":false,"exclude_reason":null,"incident_url":"","known_secret":false,"validity":"no_checker","diff_kind":null}],"is_diff":false}'
2727
headers:
28-
Access-Control-Expose-Headers:
28+
access-control-expose-headers:
2929
- X-App-Version
30-
Allow:
30+
allow:
3131
- POST, OPTIONS
32-
Connection:
33-
- keep-alive
34-
Content-Length:
35-
- '523'
36-
Content-Type:
32+
content-length:
33+
- '817'
34+
content-type:
3735
- application/json
38-
Date:
39-
- Thu, 30 Jun 2022 10:29:37 GMT
40-
Referrer-Policy:
36+
cross-origin-opener-policy:
37+
- same-origin
38+
date:
39+
- Wed, 16 Apr 2025 09:38:48 GMT
40+
referrer-policy:
4141
- strict-origin-when-cross-origin
42-
Server:
43-
- nginx
44-
Set-Cookie:
45-
- AWSALB=1NmYXJP22kKYZ+2ZLAbbWA3Blwfokr7BL9/Vocl6/No3eAYPjl3Yy7M2i99hnGKmsPCbzJ8uuQ+oENgQOmrgBVZ5v3nzY7HvQvo76ABup3ibFUvhc8o9cLFsBgYE;
46-
Expires=Thu, 07 Jul 2022 10:29:37 GMT; Path=/
47-
- AWSALBCORS=1NmYXJP22kKYZ+2ZLAbbWA3Blwfokr7BL9/Vocl6/No3eAYPjl3Yy7M2i99hnGKmsPCbzJ8uuQ+oENgQOmrgBVZ5v3nzY7HvQvo76ABup3ibFUvhc8o9cLFsBgYE;
48-
Expires=Thu, 07 Jul 2022 10:29:37 GMT; Path=/; SameSite=None; Secure
49-
Strict-Transport-Security:
42+
server:
43+
- istio-envoy
44+
strict-transport-security:
5045
- max-age=31536000; includeSubDomains
51-
Vary:
46+
vary:
5247
- Cookie
53-
X-App-Version:
54-
- v2.8.1
55-
X-Content-Type-Options:
48+
x-app-version:
49+
- v2.189.0
50+
x-content-type-options:
5651
- nosniff
5752
- nosniff
58-
X-Frame-Options:
53+
x-envoy-upstream-service-time:
54+
- '99'
55+
x-frame-options:
5956
- DENY
6057
- SAMEORIGIN
61-
X-Secrets-Engine-Version:
62-
- 2.70.0
63-
X-XSS-Protection:
58+
x-secrets-engine-version:
59+
- 2.135.3
60+
x-xss-protection:
6461
- 1; mode=block
6562
status:
6663
code: 200

tests/cassettes/secret_validity.yaml

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,49 @@ interactions:
1515
Content-Type:
1616
- application/json
1717
User-Agent:
18-
- pygitguardian/1.3.4 (Linux;py3.8.10)
18+
- pygitguardian/1.20.0 (Linux;py3.10.13)
1919
method: POST
2020
uri: https://api.gitguardian.com/v1/scan
2121
response:
2222
body:
2323
string:
24-
'{"policy_break_count":1,"policies":["File extensions","Filenames","Secrets
25-
detection"],"policy_breaks":[{"type":"Basic Auth String","policy":"Secrets
26-
detection","matches":[{"type":"username","match":"jen_barber","index_start":40,"index_end":49,"line_start":2,"line_end":2},{"type":"password","match":"correcthorsebatterystaple","index_start":51,"index_end":75,"line_start":2,"line_end":2},{"type":"host","match":"cake.gitguardian.com","index_start":77,"index_end":96,"line_start":2,"line_end":2}],"validity":"no_checker"}]}'
24+
'{"policy_break_count":1,"policies":["Secrets detection"],"policy_breaks":[{"type":"Basic
25+
Auth String","detector_name":"basic_auth_string","detector_group_name":"basic_auth_string","documentation_url":"https://docs.gitguardian.com/secrets-detection/secrets-detection-engine/detectors/generics/basic_auth_string","policy":"Secrets
26+
detection","matches":[{"type":"username","match":"jen_barber","index_start":45,"index_end":54,"line_start":3,"line_end":3},{"type":"password","match":"correcthorsebatterystaple","index_start":56,"index_end":80,"line_start":3,"line_end":3},{"type":"host","match":"cake.gitguardian.com","index_start":82,"index_end":101,"line_start":3,"line_end":3}],"is_excluded":false,"exclude_reason":null,"incident_url":"","known_secret":false,"validity":"no_checker","diff_kind":null}],"is_diff":false}'
2727
headers:
28-
Access-Control-Expose-Headers:
28+
access-control-expose-headers:
2929
- X-App-Version
30-
Allow:
30+
allow:
3131
- POST, OPTIONS
32-
Connection:
33-
- keep-alive
34-
Content-Length:
35-
- '523'
36-
Content-Type:
32+
content-length:
33+
- '817'
34+
content-type:
3735
- application/json
38-
Date:
39-
- Thu, 30 Jun 2022 10:29:38 GMT
40-
Referrer-Policy:
36+
cross-origin-opener-policy:
37+
- same-origin
38+
date:
39+
- Wed, 16 Apr 2025 09:38:50 GMT
40+
referrer-policy:
4141
- strict-origin-when-cross-origin
42-
Server:
43-
- nginx
44-
Set-Cookie:
45-
- AWSALB=kwFXju+/3iAAD5HsuV7S8IIopfFRek/dMa1Ud809xgIQGdS6rxMRMsFCBCZpSj0mtddQ4zt018cmw+E3BpsOdamB5Y2XfMMfIVu9deJ/BYWX0519QFcbjfPJoe1B;
46-
Expires=Thu, 07 Jul 2022 10:29:38 GMT; Path=/
47-
- AWSALBCORS=kwFXju+/3iAAD5HsuV7S8IIopfFRek/dMa1Ud809xgIQGdS6rxMRMsFCBCZpSj0mtddQ4zt018cmw+E3BpsOdamB5Y2XfMMfIVu9deJ/BYWX0519QFcbjfPJoe1B;
48-
Expires=Thu, 07 Jul 2022 10:29:38 GMT; Path=/; SameSite=None; Secure
49-
Strict-Transport-Security:
42+
server:
43+
- istio-envoy
44+
strict-transport-security:
5045
- max-age=31536000; includeSubDomains
51-
Vary:
46+
vary:
5247
- Cookie
53-
X-App-Version:
54-
- v2.8.1
55-
X-Content-Type-Options:
48+
x-app-version:
49+
- v2.189.0
50+
x-content-type-options:
5651
- nosniff
5752
- nosniff
58-
X-Frame-Options:
53+
x-envoy-upstream-service-time:
54+
- '66'
55+
x-frame-options:
5956
- DENY
6057
- SAMEORIGIN
61-
X-Secrets-Engine-Version:
62-
- 2.70.0
63-
X-XSS-Protection:
58+
x-secrets-engine-version:
59+
- 2.135.3
60+
x-xss-protection:
6461
- 1; mode=block
6562
status:
6663
code: 200

tests/cassettes/with_breaks.yaml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,29 @@ interactions:
1616
Content-Type:
1717
- application/json
1818
User-Agent:
19-
- pygitguardian/1.19.0 (Linux;py3.10.12)
19+
- pygitguardian/1.20.0 (Linux;py3.10.13)
2020
method: POST
2121
uri: https://api.gitguardian.com/v1/multiscan
2222
response:
2323
body:
2424
string:
2525
'[{"policy_break_count":1,"policies":["Secrets detection"],"policy_breaks":[{"type":"Basic
26-
Auth String","policy":"Secrets detection","matches":[{"type":"username","match":"jen_barber","index_start":45,"index_end":54,"line_start":3,"line_end":3},{"type":"password","match":"correcthorsebatterystaple","index_start":56,"index_end":80,"line_start":3,"line_end":3},{"type":"host","match":"cake.gitguardian.com","index_start":82,"index_end":101,"line_start":3,"line_end":3}],"is_excluded":false,"exclude_reason":null,"incident_url":"https://dashboard.gitguardian.com/workspace/8/incidents/10114685","known_secret":true,"validity":"no_checker","diff_kind":null}],"is_diff":false},{"policy_break_count":0,"policies":["Secrets
26+
Auth String","detector_name":"basic_auth_string","detector_group_name":"basic_auth_string","documentation_url":"https://docs.gitguardian.com/secrets-detection/secrets-detection-engine/detectors/generics/basic_auth_string","policy":"Secrets
27+
detection","matches":[{"type":"username","match":"jen_barber","index_start":45,"index_end":54,"line_start":3,"line_end":3},{"type":"password","match":"correcthorsebatterystaple","index_start":56,"index_end":80,"line_start":3,"line_end":3},{"type":"host","match":"cake.gitguardian.com","index_start":82,"index_end":101,"line_start":3,"line_end":3}],"is_excluded":false,"exclude_reason":null,"incident_url":"","known_secret":false,"validity":"no_checker","diff_kind":null}],"is_diff":false},{"policy_break_count":0,"policies":["Secrets
2728
detection"],"policy_breaks":[],"is_diff":false}]'
2829
headers:
2930
access-control-expose-headers:
3031
- X-App-Version
3132
allow:
3233
- POST, OPTIONS
3334
content-length:
34-
- '766'
35+
- '912'
3536
content-type:
3637
- application/json
3738
cross-origin-opener-policy:
3839
- same-origin
3940
date:
40-
- Mon, 24 Feb 2025 12:49:30 GMT
41+
- Wed, 16 Apr 2025 09:42:21 GMT
4142
referrer-policy:
4243
- strict-origin-when-cross-origin
4344
server:
@@ -47,17 +48,17 @@ interactions:
4748
vary:
4849
- Cookie
4950
x-app-version:
50-
- v2.155.0
51+
- v2.189.0
5152
x-content-type-options:
5253
- nosniff
5354
- nosniff
5455
x-envoy-upstream-service-time:
55-
- '490'
56+
- '88'
5657
x-frame-options:
5758
- DENY
5859
- SAMEORIGIN
5960
x-secrets-engine-version:
60-
- 2.132.2
61+
- 2.135.3
6162
x-xss-protection:
6263
- 1; mode=block
6364
status:

tests/test_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,9 @@ def test_multiscan_parameters(client: GGClient, ignore_known_secrets, all_secret
581581
"policy_breaks": [
582582
{
583583
"type": "break",
584+
"detector_name": "break",
585+
"detector_group_name": "break",
586+
"documentation_url": None,
584587
"policy": "mypol",
585588
"matches": [
586589
{

tests/test_models.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ def test_document_handle_surrogates(self):
9595
"policy_breaks": [
9696
{
9797
"type": "break",
98+
"detector_name": "hello",
99+
"detector_group_name": "hello",
100+
"documentation_url": None,
98101
"policy": "mypol",
99102
"matches": [
100103
{
@@ -114,6 +117,9 @@ def test_document_handle_surrogates(self):
114117
PolicyBreak,
115118
{
116119
"type": "hello",
120+
"detector_name": "hello",
121+
"detector_group_name": "hello",
122+
"documentation_url": None,
117123
"policy": "hello",
118124
"validity": "hey",
119125
"matches": [{"match": "hello", "type": "hello"}],
@@ -124,6 +130,9 @@ def test_document_handle_surrogates(self):
124130
PolicyBreak,
125131
{
126132
"type": "hello",
133+
"detector_name": "hello",
134+
"detector_group_name": "hello",
135+
"documentation_url": None,
127136
"policy": "hello",
128137
"validity": "hey",
129138
"known_secret": True,
@@ -136,6 +145,9 @@ def test_document_handle_surrogates(self):
136145
PolicyBreak,
137146
{
138147
"type": "hello",
148+
"detector_name": "hello",
149+
"detector_group_name": "hello",
150+
"documentation_url": None,
139151
"policy": "hello",
140152
"validity": "hey",
141153
"known_secret": True,
@@ -150,6 +162,9 @@ def test_document_handle_surrogates(self):
150162
PolicyBreak,
151163
{
152164
"type": "hello",
165+
"detector_name": "hello",
166+
"detector_group_name": "hello",
167+
"documentation_url": None,
153168
"policy": "hello",
154169
"validity": "hey",
155170
"known_secret": True,
@@ -165,6 +180,9 @@ def test_document_handle_surrogates(self):
165180
PolicyBreak,
166181
{
167182
"type": "hello",
183+
"detector_name": "hello",
184+
"detector_group_name": "hello",
185+
"documentation_url": None,
168186
"policy": "hello",
169187
"validity": "hey",
170188
"known_secret": True,
@@ -482,6 +500,9 @@ def test_policy_break_known_secret_field(self, known_secret):
482500
"""
483501
data = {
484502
"type": "hello",
503+
"detector_name": "hello",
504+
"detector_group_name": "hello",
505+
"documentation_url": None,
485506
"policy": "hello",
486507
"validity": "hey",
487508
"matches": [{"match": "hello", "type": "hello"}],

0 commit comments

Comments
 (0)