Skip to content

Commit 4446ff3

Browse files
authored
Add support for default redaction config (#34)
Plaintext scanning now supports a new field 'defaultRedactionConfig'. When set, this specifies how all findings should be redacted; this default configuration can be overridden at the detector level.
1 parent 60c91a4 commit 4446ff3

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

src/main/java/ai/nightfall/scan/model/ScanTextConfig.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ai.nightfall.scan.model;
22

3+
import ai.nightfall.scan.model.redaction.RedactionConfig;
34
import com.fasterxml.jackson.annotation.JsonProperty;
45

56
import java.util.List;
@@ -19,6 +20,9 @@ public class ScanTextConfig {
1920
@JsonProperty("contextBytes")
2021
private int contextBytes;
2122

23+
@JsonProperty("defaultRedactionConfig")
24+
private RedactionConfig defaultRedactionConfig;
25+
2226
/**
2327
* Create a scan configuration with the provided detection rules.
2428
*
@@ -54,6 +58,22 @@ public ScanTextConfig(List<UUID> detectionRuleUUIDs, List<DetectionRule> detecti
5458
this.contextBytes = contextBytes;
5559
}
5660

61+
/**
62+
* Create a scan configuration with the provided inline detection rules and detection rule UUIDs.
63+
*
64+
* @param detectionRuleUUIDs a list of detection rules to use to scan content (maximum length 10)
65+
* @param detectionRules a list of detection rules to use to scan content (maximum length 10)
66+
* @param contextBytes the number of bytes of context (leading and trailing) to return with any matched findings
67+
* @param defaultRedactionConfig the default redaction configuration to apply to all detection rules
68+
*/
69+
public ScanTextConfig(List<UUID> detectionRuleUUIDs, List<DetectionRule> detectionRules, int contextBytes,
70+
RedactionConfig defaultRedactionConfig) {
71+
this.detectionRuleUUIDs = detectionRuleUUIDs;
72+
this.detectionRules = detectionRules;
73+
this.contextBytes = contextBytes;
74+
this.defaultRedactionConfig = defaultRedactionConfig;
75+
}
76+
5777
/**
5878
* Get the detection rule UUIDs.
5979
*
@@ -108,12 +128,33 @@ public void setContextBytes(int contextBytes) {
108128
this.contextBytes = contextBytes;
109129
}
110130

131+
/**
132+
* Get the default redaction configuration to-be-applied to all detection rules, unless a more specific redaction
133+
* configuration is supplied at the detector level.
134+
*
135+
* @return the default redaction configuration
136+
*/
137+
public RedactionConfig getDefaultRedactionConfig() {
138+
return defaultRedactionConfig;
139+
}
140+
141+
/**
142+
* Set the default redaction configuration to-be-applied to all detection rules, unless a more specific redaction
143+
* configuration is supplied at the detector level.
144+
*
145+
* @param defaultRedactionConfig the default redaction configuration
146+
*/
147+
public void setDefaultRedactionConfig(RedactionConfig defaultRedactionConfig) {
148+
this.defaultRedactionConfig = defaultRedactionConfig;
149+
}
150+
111151
@Override
112152
public String toString() {
113153
return "ScanTextConfig{"
114154
+ "detectionRuleUUIDs=" + detectionRuleUUIDs
115155
+ ", detectionRules=" + detectionRules
116156
+ ", contextBytes=" + contextBytes
157+
+ ", defaultRedactionConfig=" + defaultRedactionConfig
117158
+ '}';
118159
}
119160
}

src/test/java/ai/nightfall/scan/NightfallClientTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
import ai.nightfall.scan.model.ScanFileRequest;
88
import ai.nightfall.scan.model.ScanFileResponse;
99
import ai.nightfall.scan.model.ScanPolicy;
10+
import ai.nightfall.scan.model.ScanTextConfig;
1011
import ai.nightfall.scan.model.ScanTextRequest;
1112
import ai.nightfall.scan.model.ScanTextResponse;
13+
import ai.nightfall.scan.model.redaction.RedactionConfig;
14+
import ai.nightfall.scan.model.redaction.SubstitutionConfig;
1215
import okhttp3.HttpUrl;
1316
import okhttp3.OkHttpClient;
1417
import okhttp3.mockwebserver.Dispatcher;
@@ -24,6 +27,7 @@
2427
import java.io.IOException;
2528
import java.time.Duration;
2629
import java.util.Arrays;
30+
import java.util.Collections;
2731
import java.util.List;
2832
import java.util.UUID;
2933

@@ -42,9 +46,11 @@ public void testScanText_HappyPath() {
4246
try (MockWebServer server = new MockWebServer()) {
4347
server.enqueue(new MockResponse().setBody("{\"findings\": [[]]}"));
4448

45-
List<List<Finding>> expectedFindings = Arrays.asList(Arrays.asList());
49+
List<List<Finding>> expectedFindings = Arrays.asList(Collections.emptyList());
4650
NightfallClient c = new NightfallClient(getRequestURL(server), "key", 1, getHttpClient());
47-
ScanTextRequest req = new ScanTextRequest(null, null);
51+
RedactionConfig defRedCfg = new RedactionConfig(new SubstitutionConfig("REDACTED"));
52+
ScanTextConfig cfg = new ScanTextConfig(Arrays.asList(UUID.fromString("c08c6c43-85ca-40e5-8f46-7d1cf1e176a3")), Collections.emptyList(), 20, defRedCfg);
53+
ScanTextRequest req = new ScanTextRequest(null, cfg);
4854
ScanTextResponse resp = c.scanText(req);
4955
assertEquals(expectedFindings, resp.getFindings());
5056
} catch (IOException e) {

0 commit comments

Comments
 (0)