Skip to content

Commit 77ed1fe

Browse files
author
Dan Hertz
authored
Merge pull request #19 from nightfallai/dan/plat-1320-add-context-bytes-to-python
add context byte setting
2 parents 9f16765 + f4a634d commit 77ed1fe

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

nightfall/api.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ 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: Optional[int] = None) ->\
56+
Tuple[List[List[Finding]], List[str]]:
5657
"""Scan text with Nightfall.
5758
5859
This method takes the specified config and then makes
@@ -67,6 +68,8 @@ def scan_text(self, texts: List[str], detection_rules: Optional[List[DetectionRu
6768
:param detection_rule_uuids: List of detection rule UUIDs to scan each text with.
6869
These can be created in the Nightfall UI.
6970
:type detection_rule_uuids: List[str] or None
71+
:param context_bytes: The number of bytes of context (leading and trailing) to return with any matched findings.
72+
:type context_bytes: int or None
7073
:returns: list of findings, list of redacted input texts
7174
"""
7275

@@ -78,6 +81,8 @@ def scan_text(self, texts: List[str], detection_rules: Optional[List[DetectionRu
7881
config["detectionRuleUUIDs"] = detection_rule_uuids
7982
if detection_rules:
8083
config["detectionRules"] = [d.as_dict() for d in detection_rules]
84+
if context_bytes:
85+
config["contextBytes"] = context_bytes
8186
request_body = {
8287
"payload": texts,
8388
"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)