Skip to content

Commit b8d2fa7

Browse files
authored
Write readme (#12)
1 parent 906158e commit b8d2fa7

File tree

4 files changed

+219
-1
lines changed

4 files changed

+219
-1
lines changed

CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These owners will be the default owners for everything in
2+
# the repo.
3+
* @evanfuller @galennightfall @dhertz

CONTRIBUTING.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Contributing
2+
3+
Thank you for considering contributing to the Nightfall Java SDK.
4+
5+
There are many ways to contribute, such as:
6+
* Writing code samples
7+
* Suggesting documentation improvements
8+
* Submitting bug reports and feature requests
9+
* Writing code to improve the library itself.
10+
11+
Please, don't use the issue tracker for personal support questions. Feel free to reach out to `[email protected]`
12+
to address those issues.
13+
14+
## Responsibilities
15+
* Ensure cross-platform compatibility for every change that's accepted. Windows, Mac, Debian & Ubuntu Linux, etc.
16+
* Ensure backwards compatibility with Java 8
17+
* Create issues for each major change and enhancement that you wish to make.
18+
* Discuss proposed changes transparently and collect community feedback.
19+
* Avoid introducing new external dependencies whenever possible. When absolutely required, validate the software
20+
licenses used by these dependencies (e.g. avoid unintentional copyleft requirements).
21+
22+
## How to report a bug
23+
24+
### Security Disclosures
25+
If you find a security vulnerability, do NOT open an issue. Email `[email protected]` instead.
26+
27+
In order to determine whether you are dealing with a security issue, ask yourself the following questions:
28+
* Can I access something that's not mine, or something I shouldn't have access to?
29+
* Can I disable something for other people?
30+
* Is there a potential vulnerability stemming from a library dependency?
31+
32+
If you answered yes to any of the above questions, then you're probably dealing with a security issue.
33+
Note that even if you answer "no" to all questions, you may still be dealing with a security issue, so if you're
34+
unsure, just email us at `[email protected]`.
35+
36+
### Creating an Issue
37+
When filing an issue, make sure to answer these questions:
38+
1. What version of Java are you using?
39+
2. What operating system and processor architecture are you using?
40+
3. How did you discover the issue?
41+
4. Is the issue reproducible? What are the steps to reproduce?
42+
5. What did you expect to see?
43+
6. What did you see instead?
44+
45+
46+
## Suggesting a New Feature
47+
48+
If you find yourself wishing for a feature that doesn't exist in this SDK, you are probably not alone.
49+
There are bound to be others out there with similar needs. Open an issue on our issues list on GitHub which
50+
describes the feature you would like to see, why you need it, and how it should work.
51+
52+
## Code Review
53+
54+
The core team looks at open pull requests on a regular basis. In order for your pull request to be merged, it
55+
must meet the following requirements:
56+
* It must pass the checkstyle linter; this should be run automatically when you run `mvn package`.
57+
* It must add unit tests to cover any new functionality.
58+
* It must get approval from one of the code owners.
59+
60+
If a pull request remains idle for more than two weeks, we may close it.

README.md

Lines changed: 148 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,148 @@
1-
# nightfall-java-sdk
1+
# Nightfall Java SDK
2+
3+
**Embed Nightfall scanning and detection functionality into Java applications**
4+
5+
<!-- TODO add badges [![Build Status](https://travis-ci.org/joemccann/dillinger.svg?branch=master)](https://travis-ci.org/joemccann/dillinger)
6+
-->
7+
8+
## Features
9+
10+
This SDK provides Java bindings for the Nightfall API. It allows you to add functionality to your applications to
11+
scan plain text and files in order to detect different categories of information. You can leverage any of
12+
the detectors in Nightfall's pre-built library, or you may programmatically define your own custom detectors.
13+
14+
Additionally, this library provides convenience features such as encapsulating the steps to chunk and upload files.
15+
16+
To obtain an API Key, login to the [Nightfall dashboard](https://app.nightfall.ai/) and click the section
17+
titled "Manage API Keys".
18+
19+
See our [developer documentation](https://docs.nightfall.ai/docs/entities-and-terms-to-know) for more details about
20+
integrating with the Nightfall API.
21+
22+
## Dependencies
23+
24+
The Nightfall Java SDK requires Java 8 or later.
25+
26+
For a full list of external dependencies please consult `pom.xml`.
27+
28+
## Installation
29+
30+
### Maven
31+
Add the following to your project's `pom.xml`:
32+
33+
``` xml
34+
<dependency>
35+
<groupId>ai.nightfall</groupId>
36+
<artifactId>scan-api</artifactId>
37+
<version>1.0.0</version>
38+
</dependency>
39+
```
40+
41+
### Gradle
42+
Add the following to your project's `dependencies`:
43+
44+
```
45+
implementation group: 'ai.nightfall.api', name: 'scan', version: '1.0'
46+
```
47+
48+
### Building Locally
49+
50+
Alternatively, if you would like to build the project yourself:
51+
1. Clone this git repository
52+
2. Run `mvn package` from the top-level directory.
53+
3. The `build` directory should contain two artifacts: `api-$VERSION.jar` and `api-$VERSION-shaded.jar`. The former
54+
contains *only* the compiled source files of this project, whereas the latter includes the compiled dependencies.
55+
4. Take whichever jar you prefer from the `build/` directory and add it to your project's classpath.
56+
57+
## Usage
58+
59+
### Scanning Plain Text
60+
61+
Nightfall provides pre-built detector types, covering data types ranging from PII to PHI to credentials. The following
62+
snippet shows an example of how to scan using pre-built detectors.
63+
64+
#### Sample Code
65+
66+
```java
67+
// By default, the client reads the API key from the environment variable NIGHTFALL_API_KEY
68+
try (NightfallClient c = NightfallClient.Builder.defaultClient()) {
69+
70+
// Define some detectors to use to scan your data
71+
Detector creditCard = new Detector("CREDIT_CARD_NUMBER");
72+
Detector ssn = new Detector("US_SOCIAL_SECURITY_NUMBER");
73+
74+
// A rule contains a set of detectors to scan with
75+
DetectionRule rule = new DetectionRule();
76+
rule.setDetectors(Arrays.asList(creditCard, ssn));
77+
rule.setLogicalOp("ANY");
78+
79+
List<String> payload = Arrays.asList("hello world", "my SSN is 678-99-8212", "4242-4242-4242-4242");
80+
ScanTextConfig config = ScanTextConfig.fromDetectionRuleUUIDs(Arrays.asList(rule), 20);
81+
ScanTextRequest req = new ScanTextRequest(payload, config);
82+
83+
ScanTextResponse response = c.scan(req);
84+
System.out.println("findings: " + response.getFindings());
85+
}
86+
```
87+
88+
### Scanning Files
89+
90+
Scanning common file types like PDF's or office documents typically requires cumbersome text
91+
extraction methods like OCR.
92+
93+
Rather than implementing this functionality yourself, the Nightfall API allows you to upload the
94+
original files, and then we'll handle the heavy lifting.
95+
96+
The file upload process is implemented as a series of requests to upload the file in chunks. The library
97+
provides a single method that wraps the steps required to upload your file. Please refer to the
98+
[API Reference](https://docs.nightfall.ai/reference) for more details.
99+
100+
The file is uploaded synchronously, but as files can be arbitrarily large, the scan itself is conducted asynchronously.
101+
The results from the scan are delivered by webhook; for more information about setting up a webhook server, refer to
102+
[the docs](https://docs.nightfall.ai/docs/creating-a-webhook-server).
103+
104+
#### Sample Code
105+
106+
```java
107+
// By default, the client reads the API key from the environment variable NIGHTFALL_API_KEY
108+
try (NightfallClient c = NightfallClient.Builder.defaultClient()) {
109+
110+
// Define some detectors to use to scan your data
111+
Detector creditCard = new Detector("CREDIT_CARD_NUMBER");
112+
Detector ssn = new Detector("US_SOCIAL_SECURITY_NUMBER");
113+
114+
// A rule contains a set of detectors to scan with
115+
DetectionRule rule = new DetectionRule();
116+
rule.setDetectors(Arrays.asList(creditCard, ssn));
117+
rule.setLogicalOp("ANY");
118+
119+
// File scans are conducted asynchronously, so provide a webhook route to an HTTPS server to send results to.
120+
String webhookResponseListenerURL = "https://my-service.com/nightfall/listener";
121+
ScanPolicy policy = ScanPolicy.fromDetectionRules(Arrays.asList(rule), webhookResponseListenerURL);
122+
ScanFileRequest req = new ScanFileRequest(policy, "my request metadata");
123+
124+
// Upload the data to the API, then trigger the async scan
125+
File file = new File("./super-secret-credit-cards.pdf");
126+
try (InputStream stream = new FileInputStream(file)) {
127+
ScanFileResponse response = c.scanFile(req, stream, file.length());
128+
System.out.println("started scan: " + response.toString());
129+
}
130+
}
131+
```
132+
133+
134+
## Contributing
135+
136+
Contributions are welcome! Open a pull request to fix a bug, or open an issue to discuss a new feature
137+
or change. Please adhere to the linting criteria defined in `checkstyle.xml`, and be sure to add unit
138+
tests for any new functionality you add.
139+
140+
Refer to `CONTRIBUTING.md` for the full details.
141+
142+
## License
143+
144+
This code is licensed under the terms of the MIT License. See [here](https://opensource.org/licenses/MIT)
145+
for more information.
146+
147+
Java is licensed by Oracle. See [here](https://www.oracle.com/java/technologies/javase/jdk-faqs.html)
148+
for more information.

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,12 @@ public UUID getId() {
3232
public String getMessage() {
3333
return message;
3434
}
35+
36+
@Override
37+
public String toString() {
38+
return "ScanFileResponse{"
39+
+ "id=" + id
40+
+ ", message='" + message + '\''
41+
+ '}';
42+
}
3543
}

0 commit comments

Comments
 (0)