Skip to content

Commit f63611a

Browse files
author
Dan Hertz
committed
add context byte setting
1 parent 9f16765 commit f63611a

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

nightfall/api.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(self, key: Optional[str] = None, signing_secret: Optional[str] = No
5252
self.logger = logging.getLogger(__name__)
5353

5454
def scan_text(self, texts: List[str], detection_rules: Optional[List[DetectionRule]] = None,
55-
detection_rule_uuids: Optional[List[str]] = None) -> Tuple[List[List[Finding]], List[str]]:
55+
detection_rule_uuids: Optional[List[str]] = None, context_bytes = None) -> Tuple[List[List[Finding]], List[str]]:
5656
"""Scan text with Nightfall.
5757
5858
This method takes the specified config and then makes
@@ -67,6 +67,8 @@ def scan_text(self, texts: List[str], detection_rules: Optional[List[DetectionRu
6767
:param detection_rule_uuids: List of detection rule UUIDs to scan each text with.
6868
These can be created in the Nightfall UI.
6969
:type detection_rule_uuids: List[str] or None
70+
:param context_bytes: The number of bytes of context (leading and trailing) to return with any matched findings.
71+
:type context_bytes: int or None
7072
:returns: list of findings, list of redacted input texts
7173
"""
7274

@@ -78,6 +80,8 @@ def scan_text(self, texts: List[str], detection_rules: Optional[List[DetectionRu
7880
config["detectionRuleUUIDs"] = detection_rule_uuids
7981
if detection_rules:
8082
config["detectionRules"] = [d.as_dict() for d in detection_rules]
83+
if context_bytes:
84+
config["contextBytes"] = context_bytes
8185
request_body = {
8286
"payload": texts,
8387
"config": config

nightfall/detection_rules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class Detector:
182182
context_rules (List[ContextRule] or None): The context rules to use to customize the behavior of this detector.
183183
exclusion_rules (List[ExclusionRule] or None): The exclusion rules to use to customize the behavior of this
184184
detector.
185-
redaction_config (RedactionConfig or None): Sets the redaction configuration to-be-applied to this detector.
185+
redaction_config (RedactionConfig or None): The redaction configuration to-be-applied to this detector.
186186
This configuration is currently only supported for scanning plaintext, not for file scanning.
187187
"""
188188
min_confidence: Confidence

tests/test_api.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ def test_scan_text_detection_rules_v3(nightfall):
2929
redaction_config=RedactionConfig(remove_finding=False,
3030
mask_config=MaskConfig(masking_char='👀',
3131
num_chars_to_leave_unmasked=3,
32-
chars_to_ignore=["-"]))
33-
)])]
32+
chars_to_ignore=["-"])),
33+
)])],
34+
context_bytes=10,
3435
)
3536

3637
assert len(result) == 1
3738
assert result[0][0] == Finding(
3839
"4916-6734-7572-5015",
3940
'491👀-👀👀👀👀-👀👀👀👀-👀👀👀👀',
40-
None, None,
41+
None, " is my cre",
4142
"Credit Card Number",
4243
result[0][0].detector_uuid,
4344
Confidence.VERY_LIKELY,

0 commit comments

Comments
 (0)