Skip to content

Commit f0d8162

Browse files
authored
samples: bring back samples README (#271)
1 parent df6fbc1 commit f0d8162

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

dlp/snippets/snippets/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Cloud Data Loss Prevention (DLP) API Samples
2+
3+
<a href="https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-dlp&page=editor&open_in_editor=samples/snippets/README.md">
4+
<img alt="Open in Cloud Shell" src ="http://gstatic.com/cloudssh/images/open-btn.png"></a>
5+
6+
The [Data Loss Prevention API](https://cloud.google.com/dlp/docs/) provides programmatic access to
7+
a powerful detection engine for personally identifiable information and other privacy-sensitive data
8+
in unstructured data streams.
9+
10+
## Setup
11+
- A Google Cloud project with billing enabled
12+
- [Enable](https://console.cloud.google.com/launcher/details/google/dlp.googleapis.com) the DLP API.
13+
- [Create a service account](https://cloud.google.com/docs/authentication/getting-started)
14+
and set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable pointing to the downloaded credentials file.
15+
16+
## Running
17+
18+
To run a specific sample, edit any variables under the `TODO(developer):` in the
19+
function at the top of each sample, and then execute the function as convenient.
20+
21+
For example, if using the command line you might use the following (replacing
22+
`<CLASS_NAME>` with the name of the sample):
23+
```bash
24+
mvn exec:java -Dexec.mainClass="dlp.snippets.<CLASS_NAME>"
25+
```
26+
27+
28+
## Testing
29+
30+
### Setup
31+
- Ensure that `GOOGLE_APPLICATION_CREDENTIALS` points to authorized service account credentials file.
32+
- Set the `DLP_DEID_WRAPPED_KEY` environment variable to an AES-256 key encrypted ('wrapped') [with a Cloud Key Management Service (KMS) key](https://cloud.google.com/kms/docs/encrypt-decrypt).
33+
- Set the `DLP_DEID_KEY_NAME` environment variable to the path-name of the Cloud KMS key you wrapped `DLP_DEID_WRAPPED_KEY` with.
34+
- [Create a Google Cloud Storage bucket](https://console.cloud.google.com/storage) and upload [test.txt](src/test/resources/test.txt).
35+
- Set the `GCS_PATH` environment variable to point to the path for the bucket.
36+
- Copy and paste the data below into a CSV file and [create a BigQuery table](https://cloud.google.com/bigquery/docs/loading-data-local) from the file:
37+
```$xslt
38+
Name,TelephoneNumber,Mystery,Age,Gender
39+
James,(567) 890-1234,8291 3627 8250 1234,19,Male
40+
Gandalf,(223) 456-7890,4231 5555 6781 9876,27,Male
41+
Dumbledore,(313) 337-1337,6291 8765 1095 7629,27,Male
42+
Joe,(452) 223-1234,3782 2288 1166 3030,35,Male
43+
Marie,(452) 223-1234,8291 3627 8250 1234,35,Female
44+
Carrie,(567) 890-1234,2253 5218 4251 4526,35,Female
45+
```
46+
- Set the `BIGQUERY_DATASET` and `BIGQUERY_TABLE` environment values.
47+
- [Create a Google Cloud Pub/Sub](https://console.cloud.google.com/datastore) topic and and a subscription that is subscribed to the topic.
48+
- Set the `PUB_SUB_TOPIC` and `PUB_SUB_SUBSCRIPTION` environment variables to the corresponding values.
49+
- [Create a Google Cloud Datastore](https://console.cloud.google.com/datastore) kind and add an entity with properties:
50+
- `property1` : [email protected]
51+
- `property2` : 343-343-3435
52+
- Update the Datastore kind in [InspectTests.java](src/test/java/dlp/snippets/InspectTests.java).
53+
54+
55+
### Run
56+
Run all tests:
57+
```
58+
mvn clean verify
59+
```

0 commit comments

Comments
 (0)