1515from requests .adapters import HTTPAdapter
1616from urllib3 import Retry
1717
18+ from nightfall .alerts import AlertConfig
1819from nightfall .detection_rules import DetectionRule , RedactionConfig
1920from nightfall .exceptions import NightfallUserError , NightfallSystemError
2021from nightfall .findings import Finding
@@ -57,7 +58,7 @@ def __init__(self, key: Optional[str] = None, signing_secret: Optional[str] = No
5758
5859 def scan_text (self , texts : List [str ], policy_uuids : List [str ] = None , detection_rules : Optional [List [DetectionRule ]] = None ,
5960 detection_rule_uuids : Optional [List [str ]] = None , context_bytes : Optional [int ] = None ,
60- default_redaction_config : Optional [RedactionConfig ] = None ) -> \
61+ default_redaction_config : Optional [RedactionConfig ] = None , alert_config : Optional [ AlertConfig ] = None ) -> \
6162 Tuple [List [List [Finding ]], List [str ]]:
6263 """Scan text with Nightfall.
6364
@@ -83,6 +84,8 @@ def scan_text(self, texts: List[str], policy_uuids: List[str] = None, detection_
8384 :param default_redaction_config: The default redaction configuration to apply to all detection rules, unless
8485 there is a more specific config within a detector.
8586 :type default_redaction_config: RedactionConfig or None
87+ :param alert_config: Configures external destinations to fan out alerts to in the event that findings are detected.
88+ :type alert_config: AlertConfig or None
8689 :returns: list of findings, list of redacted input texts
8790 """
8891
@@ -98,6 +101,8 @@ def scan_text(self, texts: List[str], policy_uuids: List[str] = None, detection_
98101 policy ["contextBytes" ] = context_bytes
99102 if default_redaction_config :
100103 policy ["defaultRedactionConfig" ] = default_redaction_config .as_dict ()
104+ if alert_config :
105+ policy ["alertConfig" ] = alert_config .as_dict ()
101106
102107 request_body = {
103108 "payload" : texts
@@ -132,7 +137,8 @@ def _scan_text_v3(self, data: dict):
132137 def scan_file (self , location : str , webhook_url : Optional [str ] = None , policy_uuid : Optional [str ] = None ,
133138 detection_rules : Optional [List [DetectionRule ]] = None ,
134139 detection_rule_uuids : Optional [List [str ]] = None ,
135- request_metadata : Optional [str ] = None ) -> Tuple [str , str ]:
140+ request_metadata : Optional [str ] = None ,
141+ alert_config : Optional [AlertConfig ] = None ) -> Tuple [str , str ]:
136142 """Scan file with Nightfall.
137143 At least one of policy_uuid, detection_rule_uuids or detection_rules is required.
138144
@@ -146,6 +152,8 @@ def scan_file(self, location: str, webhook_url: Optional[str] = None, policy_uui
146152 :type detection_rule_uuids: List[str] or None
147153 :param request_metadata: additional metadata that will be returned with the webhook response
148154 :type request_metadata: str or None
155+ :param alert_config: Configures external destinations to fan out alerts to in the event that findings are detected.
156+ :type alert_config: AlertConfig or None
149157 :returns: (scan_id, message)
150158 """
151159
@@ -169,7 +177,8 @@ def scan_file(self, location: str, webhook_url: Optional[str] = None, policy_uui
169177 detection_rules = detection_rules ,
170178 detection_rule_uuids = detection_rule_uuids ,
171179 webhook_url = webhook_url , policy_uuid = policy_uuid ,
172- request_metadata = request_metadata )
180+ request_metadata = request_metadata ,
181+ alert_config = alert_config )
173182 _validate_response (response , 200 )
174183 parsed_response = response .json ()
175184
@@ -216,15 +225,20 @@ def _file_scan_finalize(self, session_id: str):
216225
217226 def _file_scan_scan (self , session_id : str , detection_rules : Optional [List [DetectionRule ]] = None ,
218227 detection_rule_uuids : Optional [List [str ]] = None , webhook_url : Optional [str ] = None ,
219- policy_uuid : Optional [str ] = None , request_metadata : Optional [str ] = None ) -> requests .Response :
228+ policy_uuid : Optional [str ] = None , request_metadata : Optional [str ] = None ,
229+ alert_config : Optional [AlertConfig ] = None ) -> requests .Response :
220230 if policy_uuid :
221231 data = {"policyUUID" : policy_uuid }
222232 else :
223- data = {"policy" : {"webhookURL" : webhook_url }}
233+ data = {"policy" : {}}
234+ if webhook_url :
235+ data ["policy" ]["webhookURL" ] = webhook_url
224236 if detection_rule_uuids :
225237 data ["policy" ]["detectionRuleUUIDs" ] = detection_rule_uuids
226238 if detection_rules :
227239 data ["policy" ]["detectionRules" ] = [d .as_dict () for d in detection_rules ]
240+ if alert_config :
241+ data ["policy" ]["alertConfig" ] = alert_config .as_dict ()
228242
229243 if request_metadata :
230244 data ["requestMetadata" ] = request_metadata
0 commit comments