9
9
from codegate .config import Config
10
10
from codegate .pipeline .base import (
11
11
AlertSeverity ,
12
+ CodeSnippet ,
12
13
PipelineContext ,
13
14
PipelineResult ,
14
15
PipelineStep ,
@@ -44,7 +45,7 @@ def _hide_secret(self, match: Match) -> str:
44
45
pass
45
46
46
47
@abstractmethod
47
- def _notify_secret (self , match : Match , protected_text : List [str ]) -> None :
48
+ def _notify_secret (self , match : Match , code_snippet : Optional [ CodeSnippet ], protected_text : List [str ]) -> None :
48
49
"""
49
50
Notify about a found secret
50
51
TODO: If the secret came from a CodeSnippet we should notify about that. This would
@@ -185,11 +186,23 @@ def _hide_secret(self, match: Match) -> str:
185
186
)
186
187
return f"REDACTED<${ encrypted_value } >"
187
188
188
- def _notify_secret (self , match : Match , protected_text : List [str ]) -> None :
189
+ def _notify_secret (
190
+ self , match : Match , code_snippet : Optional [CodeSnippet ], protected_text : List [str ]
191
+ ) -> None :
189
192
secret_lines = self ._get_surrounding_secret_lines (protected_text , match .line_number )
190
- notify_string = f"{ match .service } - { match .type } :\n { secret_lines } "
193
+ notify_string = (
194
+ f"**Secret Detected** 🔒\n "
195
+ f"- Service: { match .service } \n "
196
+ f"- Type: { match .type } \n "
197
+ f"- Key: { match .key if match .key else '(Unknown)' } \n "
198
+ f"- Line Number: { match .line_number } \n "
199
+ f"- Context:\n ```\n { secret_lines } \n ```"
200
+ )
191
201
self ._context .add_alert (
192
- self ._name , trigger_string = notify_string , severity_category = AlertSeverity .CRITICAL
202
+ self ._name ,
203
+ trigger_string = notify_string ,
204
+ severity_category = AlertSeverity .CRITICAL ,
205
+ code_snippet = code_snippet ,
193
206
)
194
207
195
208
@@ -206,7 +219,7 @@ def _hide_secret(self, match: Match) -> str:
206
219
"""
207
220
return "*" * 32
208
221
209
- def _notify_secret (self , match : Match , protected_text : List [str ]) -> None :
222
+ def _notify_secret (self , match : Match , code_snippet : Optional [ CodeSnippet ], protected_text : List [str ]) -> None :
210
223
pass
211
224
212
225
@@ -282,6 +295,9 @@ async def process(
282
295
# Process all messages
283
296
for i , message in enumerate (new_request ["messages" ]):
284
297
if "content" in message and message ["content" ]:
298
+ # check if we can extract snippets from the text
299
+ #snippets = extract_snippets(user_message)
300
+
285
301
# Protect the text
286
302
protected_string , secrets_matched = self ._redact_text (
287
303
str (message ["content" ]), secrets_manager , session_id , context
0 commit comments