@@ -55,19 +55,24 @@ def __init__(self, key: Optional[str] = None, signing_secret: Optional[str] = No
5555 'Authorization' : f'Bearer { self .key } ' ,
5656 }
5757
58- def scan_text (self , texts : List [str ], detection_rules : Optional [List [DetectionRule ]] = None ,
58+ def scan_text (self , texts : List [str ], policy_uuids : List [ str ] = None , detection_rules : Optional [List [DetectionRule ]] = None ,
5959 detection_rule_uuids : Optional [List [str ]] = None , context_bytes : Optional [int ] = None ,
6060 default_redaction_config : Optional [RedactionConfig ] = None ) -> \
6161 Tuple [List [List [Finding ]], List [str ]]:
6262 """Scan text with Nightfall.
6363
6464 This method takes the specified config and then makes
6565 one or more requests to the Nightfall API for scanning.
66- At least one of detection_rule_uuids or detection_rules is required.
6766
67+ A caller must provide exactly one of the following:
68+ * a non-empty policy_uuids list (current maximum supported length = 1)
69+ * at least one of detection_rule_uuids or detection_rules
6870
6971 :param texts: List of strings to scan.
7072 :type texts: List[str]
73+ :param policy_uuids: List of policy UUIDs to scan each text with.
74+ These can be created in the Nightfall UI.
75+ :type policy_uuids: List[str] or None
7176 :param detection_rules: List of detection rules to scan each text with.
7277 :type detection_rules: List[DetectionRule] or None
7378 :param detection_rule_uuids: List of detection rule UUIDs to scan each text with.
@@ -81,22 +86,26 @@ def scan_text(self, texts: List[str], detection_rules: Optional[List[DetectionRu
8186 :returns: list of findings, list of redacted input texts
8287 """
8388
84- if not detection_rule_uuids and not detection_rules :
85- raise NightfallUserError ("at least one of detection_rule_uuids or detection_rules required" , 40001 )
89+ if not policy_uuids and not detection_rule_uuids and not detection_rules :
90+ raise NightfallUserError ("at least one of policy_uuids, detection_rule_uuids, or detection_rules is required" , 40001 )
8691
87- config = {}
92+ policy = {}
8893 if detection_rule_uuids :
89- config ["detectionRuleUUIDs" ] = detection_rule_uuids
94+ policy ["detectionRuleUUIDs" ] = detection_rule_uuids
9095 if detection_rules :
91- config ["detectionRules" ] = [d .as_dict () for d in detection_rules ]
96+ policy ["detectionRules" ] = [d .as_dict () for d in detection_rules ]
9297 if context_bytes :
93- config ["contextBytes" ] = context_bytes
98+ policy ["contextBytes" ] = context_bytes
9499 if default_redaction_config :
95- config ["defaultRedactionConfig" ] = default_redaction_config .as_dict ()
100+ policy ["defaultRedactionConfig" ] = default_redaction_config .as_dict ()
101+
96102 request_body = {
97- "payload" : texts ,
98- "config" : config
103+ "payload" : texts
99104 }
105+ if policy :
106+ request_body ["policy" ] = policy
107+ if policy_uuids :
108+ request_body ["policyUUIDs" ] = policy_uuids
100109 response = self ._scan_text_v3 (request_body )
101110
102111 _validate_response (response , 200 )
0 commit comments