Skip to content

Commit

Permalink
feat(secret_scan): track options usage
Browse files Browse the repository at this point in the history
  • Loading branch information
gg-mmill committed Dec 3, 2024
1 parent ed4d4e1 commit 9c8dba5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
17 changes: 17 additions & 0 deletions ggshield/core/config/user_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging
import re
from dataclasses import field
Expand Down Expand Up @@ -62,6 +63,22 @@ def add_ignored_match(self, secret: IgnoredMatch) -> None:
return
self.ignored_matches.append(secret)

def dump_for_monitoring(self) -> str:
return json.dumps(
{
"show_secrets": self.show_secrets,
"ignored_detectors_count": len(self.ignored_detectors),
"ignored_matches_count": len(self.ignored_matches),
"ignored_paths_count": len(self.ignored_paths),
"ignore_known_secrets_secrets": self.show_secrets,
"with_incident_details": self.with_incident_details,
"has_prereceive_remediation_message": bool(
self.prereceive_remediation_message
),
"all_secrets": self.all_secrets,
}
)


def validate_policy_id(policy_id: str) -> bool:
return bool(POLICY_ID_PATTERN.fullmatch(policy_id))
Expand Down
5 changes: 4 additions & 1 deletion ggshield/verticals/secret/secret_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ def __init__(
self.client = client
self.cache = cache
self.secret_config = secret_config
self.headers = scan_context.get_http_headers()
self.headers = scan_context.get_http_headers() | {
"scan_options": secret_config.dump_for_monitoring()
}

self.command_id = scan_context.command_id

if secret_config.with_incident_details:
Expand Down
1 change: 1 addition & 0 deletions tests/unit/verticals/secret/test_secret_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ def test_request_headers(scan_mock: Mock, client):
"GGShield-OS-Version": os_version,
"GGShield-Python-Version": platform.python_version(),
"mode": "path",
"scan_options": ANY,
},
all_secrets=True,
)
Expand Down

0 comments on commit 9c8dba5

Please sign in to comment.