Skip to content

Commit 2307913

Browse files
authored
Add support for AlertConfig (#47)
Callers may provide an alertConfig object as part of either a synchronous plaintext scan, or an asynchronous file scan to fan alerts out to any of { slack, email, and webhook}.
1 parent 5677211 commit 2307913

File tree

6 files changed

+336
-1
lines changed

6 files changed

+336
-1
lines changed

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

Lines changed: 41 additions & 1 deletion
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.alert.AlertConfig;
34
import com.fasterxml.jackson.annotation.JsonProperty;
45

56
import java.util.List;
@@ -12,6 +13,7 @@
1213
*/
1314
public class ScanPolicy {
1415

16+
@Deprecated
1517
@JsonProperty("webhookURL")
1618
private String webhookURL;
1719

@@ -21,6 +23,9 @@ public class ScanPolicy {
2123
@JsonProperty("detectionRuleUUIDs")
2224
private List<UUID> detectionRuleUUIDs;
2325

26+
@JsonProperty("alertConfig")
27+
private AlertConfig alertConfig;
28+
2429
/**
2530
* Create a scan policy with the provided detection rules.
2631
*
@@ -50,17 +55,32 @@ public static ScanPolicy fromDetectionRuleUUIDs(List<UUID> detectionRuleUUIDs, S
5055
* @param detectionRules a list of detection rules to use to scan content. maximum length 10.
5156
* @param detectionRuleUUIDs a list of detection rule UUIDs to use to scan content. maximum length 10.
5257
*/
58+
@Deprecated
5359
public ScanPolicy(String webhookURL, List<DetectionRule> detectionRules, List<UUID> detectionRuleUUIDs) {
5460
this.webhookURL = webhookURL;
5561
this.detectionRules = detectionRules;
5662
this.detectionRuleUUIDs = detectionRuleUUIDs;
5763
}
5864

5965
/**
60-
* Get the webhook URL.
66+
* Create a scan policy with the provided detection rules and detection rule UUIDs.
67+
*
68+
* @param alertConfig the alert configuration that Nightfall will use to deliver findings to external sources.
69+
* @param detectionRules a list of detection rules to use to scan content. maximum length 10.
70+
* @param detectionRuleUUIDs a list of detection rule UUIDs to use to scan content. maximum length 10.
71+
*/
72+
public ScanPolicy(AlertConfig alertConfig, List<DetectionRule> detectionRules, List<UUID> detectionRuleUUIDs) {
73+
this.alertConfig = alertConfig;
74+
this.detectionRules = detectionRules;
75+
this.detectionRuleUUIDs = detectionRuleUUIDs;
76+
}
77+
78+
/**
79+
* Get the webhook URL. Deprecated: use the <code>alertConfig</code> object instead.
6180
*
6281
* @return the webhook URL that Nightfall should deliver results to
6382
*/
83+
@Deprecated
6484
public String getWebhookURL() {
6585
return webhookURL;
6686
}
@@ -70,6 +90,7 @@ public String getWebhookURL() {
7090
*
7191
* @param webhookURL the webhook URL that Nightfall should deliver results to
7292
*/
93+
@Deprecated
7394
public void setWebhookURL(String webhookURL) {
7495
this.webhookURL = webhookURL;
7596
}
@@ -109,4 +130,23 @@ public List<UUID> getDetectionRuleUUIDs() {
109130
public void setDetectionRuleUUIDs(List<UUID> detectionRuleUUIDs) {
110131
this.detectionRuleUUIDs = detectionRuleUUIDs;
111132
}
133+
134+
/**
135+
* Get the alert configuration that specifies where alerts should be delivered when findings are detected.
136+
*
137+
* @return the alert configuration
138+
*/
139+
public AlertConfig getAlertConfig() {
140+
return alertConfig;
141+
}
142+
143+
/**
144+
* Sets the alert configuration that specifies where alerts should be delivered when findings are detected.
145+
*
146+
* @param alertConfig the alert configuration
147+
*/
148+
public void setAlertConfig(AlertConfig alertConfig) {
149+
this.alertConfig = alertConfig;
150+
}
151+
112152
}

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

Lines changed: 23 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.alert.AlertConfig;
34
import ai.nightfall.scan.model.redaction.RedactionConfig;
45
import com.fasterxml.jackson.annotation.JsonProperty;
56

@@ -23,6 +24,9 @@ public class ScanTextConfig {
2324
@JsonProperty("defaultRedactionConfig")
2425
private RedactionConfig defaultRedactionConfig;
2526

27+
@JsonProperty("alertConfig")
28+
private AlertConfig alertConfig;
29+
2630
/**
2731
* Create a scan configuration with the provided detection rules.
2832
*
@@ -148,13 +152,32 @@ public void setDefaultRedactionConfig(RedactionConfig defaultRedactionConfig) {
148152
this.defaultRedactionConfig = defaultRedactionConfig;
149153
}
150154

155+
/**
156+
* Get the alert configuration that specifies where alerts should be delivered when findings are detected.
157+
*
158+
* @return the alert configuration
159+
*/
160+
public AlertConfig getAlertConfig() {
161+
return alertConfig;
162+
}
163+
164+
/**
165+
* Sets the alert configuration that specifies where alerts should be delivered when findings are detected.
166+
*
167+
* @param alertConfig the alert configuration
168+
*/
169+
public void setAlertConfig(AlertConfig alertConfig) {
170+
this.alertConfig = alertConfig;
171+
}
172+
151173
@Override
152174
public String toString() {
153175
return "ScanTextConfig{"
154176
+ "detectionRuleUUIDs=" + detectionRuleUUIDs
155177
+ ", detectionRules=" + detectionRules
156178
+ ", contextBytes=" + contextBytes
157179
+ ", defaultRedactionConfig=" + defaultRedactionConfig
180+
+ ", alertConfig=" + alertConfig
158181
+ '}';
159182
}
160183
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package ai.nightfall.scan.model.alert;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
/**
6+
* The AlertConfig class allows clients to specify where alerts should be delivered when findings are discovered as
7+
* part of a scan. These alerts are delivered asynchronously to all destinations specified in the object instance.
8+
*/
9+
public class AlertConfig {
10+
11+
@JsonProperty("email")
12+
private EmailAlert emailAlert;
13+
14+
@JsonProperty("slack")
15+
private SlackAlert slackAlert;
16+
17+
@JsonProperty("url")
18+
private WebhookAlert webhookAlert;
19+
20+
/**
21+
* Build an instance of AlertConfig with all provided alert destinations.
22+
*
23+
* @param emailAlert the email alert destination
24+
* @param slackAlert the Slack alert destination
25+
* @param webhookAlert the webhook alert destination
26+
*/
27+
public AlertConfig(EmailAlert emailAlert, SlackAlert slackAlert, WebhookAlert webhookAlert) {
28+
this.emailAlert = emailAlert;
29+
this.slackAlert = slackAlert;
30+
this.webhookAlert = webhookAlert;
31+
}
32+
33+
/**
34+
* Build an instance of AlertConfig that sends findings alerts via webhook.
35+
*
36+
* @param webhookAlert the webhook alert destination
37+
*/
38+
public AlertConfig(WebhookAlert webhookAlert) {
39+
this.webhookAlert = webhookAlert;
40+
}
41+
42+
/**
43+
* Build an instance of AlertConfig that sends findings alerts via Slack.
44+
*
45+
* @param slackAlert the Slack alert destination
46+
*/
47+
public AlertConfig(SlackAlert slackAlert) {
48+
this.slackAlert = slackAlert;
49+
}
50+
51+
/**
52+
* Build an instance of AlertConfig that sends findings alerts via email.
53+
*
54+
* @param emailAlert the email alert destination
55+
*/
56+
public AlertConfig(EmailAlert emailAlert) {
57+
this.emailAlert = emailAlert;
58+
}
59+
60+
/**
61+
* Returns the email alert destination.
62+
*
63+
* @return the email alert destination
64+
*/
65+
public EmailAlert getEmailAlert() {
66+
return emailAlert;
67+
}
68+
69+
/**
70+
* Sets the email alert destination.
71+
*
72+
* @param emailAlert the email alert destination
73+
*/
74+
public void setEmailAlert(EmailAlert emailAlert) {
75+
this.emailAlert = emailAlert;
76+
}
77+
78+
/**
79+
* Returns the Slack alert destination.
80+
*
81+
* @return the Slack alert destination
82+
*/
83+
public SlackAlert getSlackAlert() {
84+
return slackAlert;
85+
}
86+
87+
/**
88+
* Sets the Slack alert destination.
89+
*
90+
* @param slackAlert the Slack alert destination
91+
*/
92+
public void setSlackAlert(SlackAlert slackAlert) {
93+
this.slackAlert = slackAlert;
94+
}
95+
96+
/**
97+
* Returns the webhook alert destination.
98+
*
99+
* @return the webhook alert destination
100+
*/
101+
public WebhookAlert getWebhookAlert() {
102+
return webhookAlert;
103+
}
104+
105+
/**
106+
* Sets the webhook alert destination.
107+
*
108+
* @param webhookAlert the webhook alert destination
109+
*/
110+
public void setWebhookAlert(WebhookAlert webhookAlert) {
111+
this.webhookAlert = webhookAlert;
112+
}
113+
114+
@Override
115+
public String toString() {
116+
return "AlertConfig{"
117+
+ "emailAlert=" + emailAlert
118+
+ ", slackAlert=" + slackAlert
119+
+ ", webhookAlert=" + webhookAlert
120+
+ '}';
121+
}
122+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package ai.nightfall.scan.model.alert;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
/**
6+
* The EmailAlert class contains the configuration required to allow clients to send an asynchronous email message
7+
* when findings are detected. The findings themselves will be delivered as a file attachment on the email.
8+
* Alerts are only sent if findings are detected.
9+
*/
10+
public class EmailAlert {
11+
12+
@JsonProperty("address")
13+
private String address;
14+
15+
/**
16+
* Creates an instance of the EmailAlert class with the provided email address.
17+
*
18+
* @param address an email address
19+
*/
20+
public EmailAlert(String address) {
21+
this.address = address;
22+
}
23+
24+
/**
25+
* Returns the email address to which alerts should be delivered.
26+
*
27+
* @return the email address
28+
*/
29+
public String getAddress() {
30+
return address;
31+
}
32+
33+
/**
34+
* Sets the email address to which alerts should be delivered.
35+
*
36+
* @param address the email address
37+
*/
38+
public void setAddress(String address) {
39+
this.address = address;
40+
}
41+
42+
@Override
43+
public String toString() {
44+
return "EmailAlert{"
45+
+ "address='" + address + '\''
46+
+ '}';
47+
}
48+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package ai.nightfall.scan.model.alert;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
/**
6+
* The SlackAlert class contains the configuration required to allow clients to send asynchronous alerts to a
7+
* Slack workspace when findings are detected. Note that in order for Slack alerts to be delivered to your workspace,
8+
* you must use authenticate Nightfall to your Slack workspace under the Settings menu on the
9+
* <a href="https://app.nightfall.ai/">Nightfall Dashboard</a>. Alerts are only sent if findings are detected.
10+
*
11+
* <p>Currently, Nightfall supports delivering alerts to public channels, formatted like "#general".
12+
*/
13+
public class SlackAlert {
14+
15+
@JsonProperty("target")
16+
private String target;
17+
18+
/**
19+
* Creates an instance of the SlackAlert class with the provided conversation name.
20+
*
21+
* @param target a Slack conversation name.
22+
*/
23+
public SlackAlert(String target) {
24+
this.target = target;
25+
}
26+
27+
/**
28+
* Returns the target conversation to which alerts should be delivered.
29+
*
30+
* @return the name of the target conversation
31+
*/
32+
public String getTarget() {
33+
return target;
34+
}
35+
36+
/**
37+
* Sets the target conversation to which alerts should be delivered.
38+
*
39+
* @param target the name of the target conversation
40+
*/
41+
public void setTarget(String target) {
42+
this.target = target;
43+
}
44+
45+
@Override
46+
public String toString() {
47+
return "SlackAlert{"
48+
+ "target='" + target + '\''
49+
+ '}';
50+
}
51+
}

0 commit comments

Comments
 (0)