Skip to content

Commit 657aa2c

Browse files
Add violation config to scan requests for partners (#88)
* Add violation config to file/text scan requests * update action enums * lint * tag build as beta release * make enum public * doc string
1 parent 8488814 commit 657aa2c

File tree

7 files changed

+328
-4
lines changed

7 files changed

+328
-4
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
BUILD_DIR=build
33

4-
VERSION=1.2.2
4+
VERSION=1.2.3-beta-1
55

66
NAME=scan-api
77
ARTIFACT=$(NAME)-$(VERSION).jar

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ and then set your API key as an environment variable and run the sample program
7474

7575
```bash
7676
export NIGHTFALL_API_KEY="NF-XXXXXX" # replace with your API key
77-
java -cp build/scan-api-1.2.2.jar ai.nightfall.examples.FileScannerExample /path/to/file
77+
java -cp build/scan-api-1.2.3-beta-1.jar ai.nightfall.examples.FileScannerExample /path/to/file
7878
```
7979

8080

@@ -116,7 +116,7 @@ then set your API key as an environment variable and run the sample program (cha
116116
```bash
117117
export NIGHTFALL_API_KEY="NF-XXXXXX" # replace with your API key
118118
NGROK_URL="myurl" # replace with the URL from running ngrok above
119-
java -cp build/scan-api-1.2.2.jar ai.nightfall.examples.FileScannerExample "$NGROK_URL" /path/to/file
119+
java -cp build/scan-api-1.2.3-beta-1.jar ai.nightfall.examples.FileScannerExample "$NGROK_URL" /path/to/file
120120
```
121121

122122

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>ai.nightfall</groupId>
88
<artifactId>scan-api</artifactId>
9-
<version>1.2.2</version>
9+
<version>1.2.3-beta-1</version>
1010

1111
<name>${project.groupId}:${project.artifactId}</name>
1212
<description>The Nightfall Scanner provides Java bindings for our developer platform, which allows clients

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public class ScanFileRequest {
1919
@JsonProperty("requestMetadata")
2020
private String requestMetadata;
2121

22+
@JsonProperty("violation")
23+
private ViolationConfig violationConfig;
24+
2225
/**
2326
* Create a new request to scan a file.
2427
*
@@ -30,6 +33,19 @@ public ScanFileRequest(ScanPolicy policy, String requestMetadata) {
3033
this.requestMetadata = requestMetadata;
3134
}
3235

36+
/**
37+
* Create a new request to scan a file.
38+
*
39+
* @param policy the policy to use to scan the file.
40+
* @param requestMetadata arbitrary metadata to pass along with the request; maximum length 10 KB.
41+
* @param violationConfig the violation configuration to use on the scanned content.
42+
*/
43+
public ScanFileRequest(ScanPolicy policy, String requestMetadata, ViolationConfig violationConfig) {
44+
this.policy = policy;
45+
this.requestMetadata = requestMetadata;
46+
this.violationConfig = violationConfig;
47+
}
48+
3349
/**
3450
* Create a new request to scan a file.
3551
*
@@ -41,6 +57,19 @@ public ScanFileRequest(UUID policyUUID, String requestMetadata) {
4157
this.requestMetadata = requestMetadata;
4258
}
4359

60+
/**
61+
* Create a new request to scan a file.
62+
*
63+
* @param policyUUID the UUID of an existing policy to use to scan the file.
64+
* @param requestMetadata arbitrary metadata to pass along with the request; maximum length 10 KB.
65+
* @param violationConfig the violation configuration to use on the scanned content.
66+
*/
67+
public ScanFileRequest(UUID policyUUID, String requestMetadata, ViolationConfig violationConfig) {
68+
this.policyUUID = policyUUID;
69+
this.requestMetadata = requestMetadata;
70+
this.violationConfig = violationConfig;
71+
}
72+
4473
/**
4574
* Get the policy UUID.
4675
*
@@ -76,4 +105,22 @@ public String getRequestMetadata() {
76105
public void setRequestMetadata(String requestMetadata) {
77106
this.requestMetadata = requestMetadata;
78107
}
108+
109+
/**
110+
* Get the violation config to use when performing a scan.
111+
*
112+
* @return the violation config.
113+
*/
114+
public ViolationConfig getViolationConfig() {
115+
return violationConfig;
116+
}
117+
118+
/**
119+
* Set the violation config to use when performing a scan.
120+
*
121+
* @param violationConfig the violation config.
122+
*/
123+
public void setViolationConfig(ViolationConfig violationConfig) {
124+
this.violationConfig = violationConfig;
125+
}
79126
}

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public class ScanTextRequest {
1919
@JsonProperty("policyUUIDs")
2020
private List<UUID> policyUUIDs;
2121

22+
@JsonProperty("violation")
23+
private ViolationConfig violationConfig;
24+
2225
/**
2326
* Create a request to scan the provided <code>payload</code> against the provided scanning
2427
* <code>policy</code>.
@@ -31,6 +34,20 @@ public ScanTextRequest(List<String> payload, ScanTextConfig policy) {
3134
this.policy = policy;
3235
}
3336

37+
/**
38+
* Create a request to scan the provided <code>payload</code> against the provided scanning
39+
* <code>policy</code>.
40+
*
41+
* @param payload the content to scan
42+
* @param policy the configuration to use to scan the content
43+
* @param violationConfig the violation configuration to use on the scanned content
44+
*/
45+
public ScanTextRequest(List<String> payload, ScanTextConfig policy, ViolationConfig violationConfig) {
46+
this.payload = payload;
47+
this.policy = policy;
48+
this.violationConfig = violationConfig;
49+
}
50+
3451
/**
3552
* Create a request to scan the provided <code>payload</code> against the provided
3653
* <code>policyUUIDs</code>.
@@ -43,6 +60,20 @@ public ScanTextRequest(List<String> payload, List<UUID> policyUUIDs) {
4360
this.policyUUIDs = policyUUIDs;
4461
}
4562

63+
/**
64+
* Create a request to scan the provided <code>payload</code> against the provided
65+
* <code>policyUUIDs</code>.
66+
*
67+
* @param payload the content to scan
68+
* @param policyUUIDs a list of UUIDs referring to pre-created policies to-be-used when scanning. Maximum 1.
69+
* @param violationConfig the violation configuration to use on the scanned content
70+
*/
71+
public ScanTextRequest(List<String> payload, List<UUID> policyUUIDs, ViolationConfig violationConfig) {
72+
this.payload = payload;
73+
this.policyUUIDs = policyUUIDs;
74+
this.violationConfig = violationConfig;
75+
}
76+
4677
/**
4778
* Get the request payload.
4879
*
@@ -122,4 +153,22 @@ public List<UUID> getPolicyUUIDs() {
122153
public void setPolicyUUIDs(List<UUID> policyUUIDs) {
123154
this.policyUUIDs = policyUUIDs;
124155
}
156+
157+
/**
158+
* Get the violation config to use when performing a scan.
159+
*
160+
* @return the violation config.
161+
*/
162+
public ViolationConfig getViolationConfig() {
163+
return violationConfig;
164+
}
165+
166+
/**
167+
* Set the violation config to use when performing a scan.
168+
*
169+
* @param violationConfig the violation config.
170+
*/
171+
public void setViolationConfig(ViolationConfig violationConfig) {
172+
this.violationConfig = violationConfig;
173+
}
125174
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package ai.nightfall.scan.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
/**
6+
* User details associated with a violation.
7+
*/
8+
public class UserViolation {
9+
@JsonProperty("id")
10+
private String id;
11+
12+
@JsonProperty("displayName")
13+
private String displayName;
14+
15+
/**
16+
* Creates a new UserViolation object.
17+
*
18+
* @param id the id of the user
19+
* @param displayName the display name for the user
20+
*/
21+
public UserViolation(String id, String displayName) {
22+
this.id = id;
23+
this.displayName = displayName;
24+
}
25+
26+
/**
27+
* Get the id.
28+
*
29+
* @return the id of the user
30+
*/
31+
public String getId() {
32+
return id;
33+
}
34+
35+
/**
36+
* Set the id.
37+
*
38+
* @param id the id of the user
39+
*/
40+
public void setId(String id) {
41+
this.id = id;
42+
}
43+
44+
/**
45+
* Get the display name.
46+
*
47+
* @return the display name of the user
48+
*/
49+
public String getDisplayName() {
50+
return displayName;
51+
}
52+
53+
/**
54+
* Set the display name.
55+
*
56+
* @param displayName the display name of the user
57+
*/
58+
public void setDisplayName(String displayName) {
59+
this.displayName = displayName;
60+
}
61+
}

0 commit comments

Comments
 (0)