Skip to content

Commit 2a22ffb

Browse files
authored
chore: refactor all DLP samples and tests (#520)
* chore: refactor all DLP samples and tests
1 parent bbaa1ce commit 2a22ffb

File tree

6 files changed

+577
-143
lines changed

6 files changed

+577
-143
lines changed

packages/google-privacy-dlp/README.md

+72-51
Original file line numberDiff line numberDiff line change
@@ -68,52 +68,55 @@ const dlp = new DLP.DlpServiceClient();
6868
const string = 'Robert Frost';
6969

7070
// The project ID to run the API call under
71-
const projectId = process.env.GCLOUD_PROJECT;
72-
73-
// The minimum likelihood required before returning a match
74-
const minLikelihood = 'LIKELIHOOD_UNSPECIFIED';
75-
76-
// The maximum number of findings to report (0 = server maximum)
77-
const maxFindings = 0;
78-
79-
// The infoTypes of information to match
80-
const infoTypes = [{name: 'PERSON_NAME'}, {name: 'US_STATE'}];
81-
82-
// Whether to include the matching string
83-
const includeQuote = true;
84-
85-
// Construct item to inspect
86-
const item = {value: string};
87-
88-
// Construct request
89-
const request = {
90-
parent: `projects/${projectId}/locations/global`,
91-
inspectConfig: {
92-
infoTypes: infoTypes,
93-
minLikelihood: minLikelihood,
94-
limits: {
95-
maxFindingsPerRequest: maxFindings,
71+
// const projectId = 'my-project';
72+
73+
async function quickStart() {
74+
// The minimum likelihood required before returning a match
75+
const minLikelihood = 'LIKELIHOOD_UNSPECIFIED';
76+
77+
// The maximum number of findings to report (0 = server maximum)
78+
const maxFindings = 0;
79+
80+
// The infoTypes of information to match
81+
const infoTypes = [{name: 'PERSON_NAME'}, {name: 'US_STATE'}];
82+
83+
// Whether to include the matching string
84+
const includeQuote = true;
85+
86+
// Construct item to inspect
87+
const item = {value: string};
88+
89+
// Construct request
90+
const request = {
91+
parent: `projects/${projectId}/locations/global`,
92+
inspectConfig: {
93+
infoTypes: infoTypes,
94+
minLikelihood: minLikelihood,
95+
limits: {
96+
maxFindingsPerRequest: maxFindings,
97+
},
98+
includeQuote: includeQuote,
9699
},
97-
includeQuote: includeQuote,
98-
},
99-
item: item,
100-
};
101-
102-
// Run request
103-
const [response] = await dlp.inspectContent(request);
104-
const findings = response.result.findings;
105-
if (findings.length > 0) {
106-
console.log('Findings:');
107-
findings.forEach(finding => {
108-
if (includeQuote) {
109-
console.log(`\tQuote: ${finding.quote}`);
110-
}
111-
console.log(`\tInfo type: ${finding.infoType.name}`);
112-
console.log(`\tLikelihood: ${finding.likelihood}`);
113-
});
114-
} else {
115-
console.log('No findings.');
100+
item: item,
101+
};
102+
103+
// Run request
104+
const [response] = await dlp.inspectContent(request);
105+
const findings = response.result.findings;
106+
if (findings.length > 0) {
107+
console.log('Findings:');
108+
findings.forEach(finding => {
109+
if (includeQuote) {
110+
console.log(`\tQuote: ${finding.quote}`);
111+
}
112+
console.log(`\tInfo type: ${finding.infoType.name}`);
113+
console.log(`\tLikelihood: ${finding.likelihood}`);
114+
});
115+
} else {
116+
console.log('No findings.');
117+
}
116118
}
119+
quickStart();
117120

118121
```
119122

@@ -126,15 +129,33 @@ has instructions for running the samples.
126129

127130
| Sample | Source Code | Try it |
128131
| --------------------------- | --------------------------------- | ------ |
129-
| Deid | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/deid.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/deid.js,samples/README.md) |
130-
| Inspect | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/inspect.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/inspect.js,samples/README.md) |
131-
| Job Management | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/jobs.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/jobs.js,samples/README.md) |
132+
| Categorical Risk Analysis | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/categoricalRiskAnalysis.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/categoricalRiskAnalysis.js,samples/README.md) |
133+
| Inspect Templates | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/createInspectTemplate.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/createInspectTemplate.js,samples/README.md) |
134+
| Job Triggers | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/createTrigger.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/createTrigger.js,samples/README.md) |
135+
| Deidentify with Date Shift | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/deidentifyWithDateShift.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/deidentifyWithDateShift.js,samples/README.md) |
136+
| Deidentify with FPE | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/deidentifyWithFpe.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/deidentifyWithFpe.js,samples/README.md) |
137+
| Deidentify with Mask | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/deidentifyWithMask.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/deidentifyWithMask.js,samples/README.md) |
138+
| Deidentify with Replacement | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/deidentifyWithReplacement.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/deidentifyWithReplacement.js,samples/README.md) |
139+
| Delete Inspect Templates | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/deleteInspectTemplate.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/deleteInspectTemplate.js,samples/README.md) |
140+
| Delete Job | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/deleteJob.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/deleteJob.js,samples/README.md) |
141+
| Delete Trigger | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/deleteTrigger.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/deleteTrigger.js,samples/README.md) |
142+
| Inspect Bigquery | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/inspectBigQuery.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/inspectBigQuery.js,samples/README.md) |
143+
| Inspect Datastore | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/inspectDatastore.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/inspectDatastore.js,samples/README.md) |
144+
| Inspect File | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/inspectFile.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/inspectFile.js,samples/README.md) |
145+
| Inspect GCS File | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/inspectGCSFile.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/inspectGCSFile.js,samples/README.md) |
146+
| Inspects strings | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/inspectString.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/inspectString.js,samples/README.md) |
147+
| kAnonymity Analysis | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/kAnonymityAnalysis.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/kAnonymityAnalysis.js,samples/README.md) |
148+
| kMap Estimation Analysis | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/kMapEstimationAnalysis.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/kMapEstimationAnalysis.js,samples/README.md) |
149+
| l Diversity Analysis | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/lDiversityAnalysis.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/lDiversityAnalysis.js,samples/README.md) |
150+
| List Inspect Templates | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/listInspectTemplates.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/listInspectTemplates.js,samples/README.md) |
151+
| List jobs | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/listJobs.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/listJobs.js,samples/README.md) |
152+
| List Triggers | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/listTriggers.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/listTriggers.js,samples/README.md) |
132153
| Metadata | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/metadata.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/metadata.js,samples/README.md) |
154+
| Numerical Risk Analysis | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/numericalRiskAnalysis.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/numericalRiskAnalysis.js,samples/README.md) |
133155
| Quickstart | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) |
134-
| Redact | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/redact.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/redact.js,samples/README.md) |
135-
| Risk Analysis | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/risk.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/risk.js,samples/README.md) |
136-
| Inspect Templates | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/templates.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/templates.js,samples/README.md) |
137-
| Job Triggers | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/triggers.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/triggers.js,samples/README.md) |
156+
| Redact Image | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/redactImage.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/redactImage.js,samples/README.md) |
157+
| Redact Text | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/redactText.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/redactText.js,samples/README.md) |
158+
| Reidentify with FPE | [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/reidentifyWithFpe.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dlp&page=editor&open_in_editor=samples/reidentifyWithFpe.js,samples/README.md) |
138159

139160

140161

packages/google-privacy-dlp/linkinator.config.json

+26-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,32 @@
33
"skip": [
44
"https://codecov.io/gh/googleapis/",
55
"www.googleapis.com",
6-
"img.shields.io"
6+
"img.shields.io",
7+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/deidentifyWithReplacement.js",
8+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/deleteInspectTemplate.js",
9+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/deleteJob.js",
10+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/deleteTrigger.js",
11+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/inspectBigQuery.js",
12+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/inspectDatastore.js",
13+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/inspectGCSFile.js",
14+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/inspectFile.js",
15+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/inspectString.js",
16+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/kAnonymityAnalysis.js",
17+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/kMapEstimationAnalysis.js",
18+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/lDiversityAnalysis.js",
19+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/listInspectTemplates.js",
20+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/listJobs.js",
21+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/listTriggers.js",
22+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/numericalRiskAnalysis.js",
23+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/redactImage.js",
24+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/redactText.js",
25+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/reidentifyWithFpe.js",
26+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/categoricalRiskAnalysis.js",
27+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/createInspectTemplate.js",
28+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/createTrigger.js",
29+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/deidentifyWithDateShift.js",
30+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/deidentifyWithFpe.js",
31+
"https://github.com/googleapis/nodejs-dlp/blob/master/samples/deidentifyWithMask.js"
732
],
833
"silent": true,
934
"concurrency": 10

0 commit comments

Comments
 (0)