Skip to content

Commit 180040f

Browse files
committed
feat(metadata): add remediation messages
1 parent a2485b8 commit 180040f

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

pygitguardian/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
JWTService,
3636
MultiScanResult,
3737
QuotaResponse,
38+
RemediationMessages,
3839
ScanResult,
3940
SecretScanPreferences,
4041
ServerMetadata,
@@ -151,6 +152,7 @@ class GGClient:
151152
user_agent: str
152153
extra_headers: Dict
153154
secret_scan_preferences: SecretScanPreferences
155+
remediation_messages: RemediationMessages
154156
callbacks: Optional[GGClientCallbacks]
155157

156158
def __init__(
@@ -214,6 +216,7 @@ def __init__(
214216
)
215217
self.maximum_payload_size = MAXIMUM_PAYLOAD_SIZE
216218
self.secret_scan_preferences = SecretScanPreferences()
219+
self.remediation_messages = RemediationMessages()
217220

218221
def request(
219222
self,
@@ -676,6 +679,7 @@ def read_metadata(self) -> Optional[Detail]:
676679
"general__maximum_payload_size", MAXIMUM_PAYLOAD_SIZE
677680
)
678681
self.secret_scan_preferences = metadata.secret_scan_preferences
682+
self.remediation_messages = metadata.remediation_messages
679683
return None
680684

681685
def create_jwt(

pygitguardian/config.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,16 @@
55
MULTI_DOCUMENT_LIMIT = 20
66
DOCUMENT_SIZE_THRESHOLD_BYTES = 1048576 # 1MB
77
MAXIMUM_PAYLOAD_SIZE = 2621440 # 25MB
8+
9+
DEFAULT_PRE_COMMIT_MESSAGE = """Since the secret was detected before the commit was made:
10+
1. replace the secret with its reference (e.g. environment variable).
11+
2. commit again."""
12+
13+
DEFAULT_PRE_PUSH_MESSAGE = """Since the secret was detected before the push BUT after the commit, you need to:
14+
1. rewrite the git history making sure to replace the secret with its reference (e.g. environment variable).
15+
2. push again."""
16+
17+
DEFAULT_PRE_RECEIVE_MESSAGE = """A pre-receive hook set server side prevented you from pushing secrets.
18+
Since the secret was detected during the push BUT after the commit, you need to:
19+
1. rewrite the git history making sure to replace the secret with its reference (e.g. environment variable).
20+
2. push again."""

pygitguardian/models.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@
1919
)
2020
from typing_extensions import Self
2121

22-
from .config import DOCUMENT_SIZE_THRESHOLD_BYTES, MULTI_DOCUMENT_LIMIT
22+
from .config import (
23+
DEFAULT_PRE_COMMIT_MESSAGE,
24+
DEFAULT_PRE_PUSH_MESSAGE,
25+
DEFAULT_PRE_RECEIVE_MESSAGE,
26+
DOCUMENT_SIZE_THRESHOLD_BYTES,
27+
MULTI_DOCUMENT_LIMIT,
28+
)
2329

2430

2531
class ToDictMixin:
@@ -734,13 +740,23 @@ class SecretScanPreferences:
734740
maximum_documents_per_scan: int = MULTI_DOCUMENT_LIMIT
735741

736742

743+
@dataclass
744+
class RemediationMessages:
745+
pre_commit: str = DEFAULT_PRE_COMMIT_MESSAGE
746+
pre_push: str = DEFAULT_PRE_PUSH_MESSAGE
747+
pre_receive: str = DEFAULT_PRE_RECEIVE_MESSAGE
748+
749+
737750
@dataclass
738751
class ServerMetadata(Base, FromDictMixin):
739752
version: str
740753
preferences: Dict[str, Any]
741754
secret_scan_preferences: SecretScanPreferences = field(
742755
default_factory=SecretScanPreferences
743756
)
757+
remediation_messages: RemediationMessages = field(
758+
default_factory=RemediationMessages
759+
)
744760

745761

746762
ServerMetadata.SCHEMA = cast(

0 commit comments

Comments
 (0)