From 9f8572e427b009cef0e0cf477dcfaed87f0704ff Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Tue, 2 Jul 2024 17:05:53 -0700 Subject: [PATCH] check if key does not want secret detection to run --- enterprise/enterprise_hooks/secret_detection.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/enterprise/enterprise_hooks/secret_detection.py b/enterprise/enterprise_hooks/secret_detection.py index d2bd22a5d..befacc07b 100644 --- a/enterprise/enterprise_hooks/secret_detection.py +++ b/enterprise/enterprise_hooks/secret_detection.py @@ -464,6 +464,14 @@ class _ENTERPRISE_SecretDetection(CustomLogger): return detected_secrets + async def should_run_check(self, user_api_key_dict: UserAPIKeyAuth) -> bool: + if user_api_key_dict.permissions is not None: + if "secret_detection" in user_api_key_dict.permissions: + if user_api_key_dict.permissions["secret_detection"] is False: + return False + + return True + #### CALL HOOKS - proxy only #### async def async_pre_call_hook( self, @@ -475,6 +483,9 @@ class _ENTERPRISE_SecretDetection(CustomLogger): from detect_secrets import SecretsCollection from detect_secrets.settings import default_settings + if await self.should_run_check(user_api_key_dict) is False: + return + if "messages" in data and isinstance(data["messages"], list): for message in data["messages"]: if "content" in message and isinstance(message["content"], str):