diff --git a/packages/google-privacy-dlp/README.md b/packages/google-privacy-dlp/README.md index b161410b059..110ae8690fa 100644 --- a/packages/google-privacy-dlp/README.md +++ b/packages/google-privacy-dlp/README.md @@ -68,52 +68,55 @@ const dlp = new DLP.DlpServiceClient(); const string = 'Robert Frost'; // The project ID to run the API call under -const projectId = process.env.GCLOUD_PROJECT; - -// The minimum likelihood required before returning a match -const minLikelihood = 'LIKELIHOOD_UNSPECIFIED'; - -// The maximum number of findings to report (0 = server maximum) -const maxFindings = 0; - -// The infoTypes of information to match -const infoTypes = [{name: 'PERSON_NAME'}, {name: 'US_STATE'}]; - -// Whether to include the matching string -const includeQuote = true; - -// Construct item to inspect -const item = {value: string}; - -// Construct request -const request = { - parent: `projects/${projectId}/locations/global`, - inspectConfig: { - infoTypes: infoTypes, - minLikelihood: minLikelihood, - limits: { - maxFindingsPerRequest: maxFindings, +// const projectId = 'my-project'; + +async function quickStart() { + // The minimum likelihood required before returning a match + const minLikelihood = 'LIKELIHOOD_UNSPECIFIED'; + + // The maximum number of findings to report (0 = server maximum) + const maxFindings = 0; + + // The infoTypes of information to match + const infoTypes = [{name: 'PERSON_NAME'}, {name: 'US_STATE'}]; + + // Whether to include the matching string + const includeQuote = true; + + // Construct item to inspect + const item = {value: string}; + + // Construct request + const request = { + parent: `projects/${projectId}/locations/global`, + inspectConfig: { + infoTypes: infoTypes, + minLikelihood: minLikelihood, + limits: { + maxFindingsPerRequest: maxFindings, + }, + includeQuote: includeQuote, }, - includeQuote: includeQuote, - }, - item: item, -}; - -// Run request -const [response] = await dlp.inspectContent(request); -const findings = response.result.findings; -if (findings.length > 0) { - console.log('Findings:'); - findings.forEach(finding => { - if (includeQuote) { - console.log(`\tQuote: ${finding.quote}`); - } - console.log(`\tInfo type: ${finding.infoType.name}`); - console.log(`\tLikelihood: ${finding.likelihood}`); - }); -} else { - console.log('No findings.'); + item: item, + }; + + // Run request + const [response] = await dlp.inspectContent(request); + const findings = response.result.findings; + if (findings.length > 0) { + console.log('Findings:'); + findings.forEach(finding => { + if (includeQuote) { + console.log(`\tQuote: ${finding.quote}`); + } + console.log(`\tInfo type: ${finding.infoType.name}`); + console.log(`\tLikelihood: ${finding.likelihood}`); + }); + } else { + console.log('No findings.'); + } } +quickStart(); ``` @@ -126,15 +129,33 @@ has instructions for running the samples. | Sample | Source Code | Try it | | --------------------------- | --------------------------------- | ------ | -| 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) | -| 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) | -| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | +| 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) | | 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) | +| 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) | | 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) | -| 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) | -| 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) | -| 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) | -| 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) | +| 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) | +| 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) | +| 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) | diff --git a/packages/google-privacy-dlp/linkinator.config.json b/packages/google-privacy-dlp/linkinator.config.json index 29a223b6db6..6acae6d75bd 100644 --- a/packages/google-privacy-dlp/linkinator.config.json +++ b/packages/google-privacy-dlp/linkinator.config.json @@ -3,7 +3,32 @@ "skip": [ "https://codecov.io/gh/googleapis/", "www.googleapis.com", - "img.shields.io" + "img.shields.io", + "https://github.com/googleapis/nodejs-dlp/blob/master/samples/deidentifyWithReplacement.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/deleteInspectTemplate.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/deleteJob.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/deleteTrigger.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/inspectBigQuery.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/inspectDatastore.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/inspectGCSFile.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/inspectFile.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/inspectString.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/kAnonymityAnalysis.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/kMapEstimationAnalysis.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/lDiversityAnalysis.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/listInspectTemplates.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/listJobs.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/listTriggers.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/numericalRiskAnalysis.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/redactImage.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/redactText.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/reidentifyWithFpe.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/categoricalRiskAnalysis.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/createInspectTemplate.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/createTrigger.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/deidentifyWithDateShift.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/deidentifyWithFpe.js", +"https://github.com/googleapis/nodejs-dlp/blob/master/samples/deidentifyWithMask.js" ], "silent": true, "concurrency": 10 diff --git a/packages/google-privacy-dlp/samples/README.md b/packages/google-privacy-dlp/samples/README.md index 8c18ebb4177..4a08fe0d3f5 100644 --- a/packages/google-privacy-dlp/samples/README.md +++ b/packages/google-privacy-dlp/samples/README.md @@ -14,15 +14,33 @@ data in unstructured data streams. * [Before you begin](#before-you-begin) * [Samples](#samples) - * [Deid](#deid) - * [Inspect](#inspect) - * [Job Management](#job-management) - * [Metadata](#metadata) - * [Quickstart](#quickstart) - * [Redact](#redact) - * [Risk Analysis](#risk-analysis) + * [Categorical Risk Analysis](#categorical-risk-analysis) * [Inspect Templates](#inspect-templates) * [Job Triggers](#job-triggers) + * [Deidentify with Date Shift](#deidentify-with-date-shift) + * [Deidentify with FPE](#deidentify-with-fpe) + * [Deidentify with Mask](#deidentify-with-mask) + * [Deidentify with Replacement](#deidentify-with-replacement) + * [Delete Inspect Templates](#delete-inspect-templates) + * [Delete Job](#delete-job) + * [Delete Trigger](#delete-trigger) + * [Inspect Bigquery](#inspect-bigquery) + * [Inspect Datastore](#inspect-datastore) + * [Inspect File](#inspect-file) + * [Inspect GCS File](#inspect-gcs-file) + * [Inspects strings](#inspects-strings) + * [kAnonymity Analysis](#kanonymity-analysis) + * [kMap Estimation Analysis](#kmap-estimation-analysis) + * [l Diversity Analysis](#l-diversity-analysis) + * [List Inspect Templates](#list-inspect-templates) + * [List jobs](#list-jobs) + * [List Triggers](#list-triggers) + * [Metadata](#metadata) + * [Numerical Risk Analysis](#numerical-risk-analysis) + * [Quickstart](#quickstart) + * [Redact Image](#redact-image) + * [Redact Text](#redact-text) + * [Reidentify with FPE](#reidentify-with-fpe) ## Before you begin @@ -39,16 +57,113 @@ Before running the samples, make sure you've followed the steps outlined in -### Deid +### Categorical Risk Analysis + +Computes risk metrics of a column of data in a Google BigQuery table. + +View the [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) + +__Usage:__ + + +`node categoricalRiskAnalysis.js my-project nhtsa_traffic_fatalities accident_2015 state_name my-topic my-subscription bigquery-public-data` + + +----- + + + + +### Inspect Templates + +Create a new DLP inspection configuration template. + +View the [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) + +__Usage:__ + + +`node createInspectTemplate.js my-project VERY_LIKELY PERSON_NAME 5 false my-template-id` + + +----- + + + + +### Job Triggers + +Create a Data Loss Prevention API job trigger. + +View the [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) + +__Usage:__ + + +`node createTrigger.js my-project triggerId displayName description bucketName autoPopulateTimespan scanPeriod infoTypes minLikelihood maxFindings` + + +----- + + + + +### Deidentify with Date Shift + +Deidentify dates in a CSV file by pseudorandomly shifting them. + +View the [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) + +__Usage:__ + + +`node deidentifyWithDateShift.js my-project dates.csv dates-shifted.csv 30 30 birth_date register_date [ projects/my-project/locations/global/keyrings/my-keyring]` + + +----- + + + + +### Deidentify with FPE + +Deidentify sensitive data in a string using Format Preserving Encryption (FPE). + +View the [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) + +__Usage:__ + + +`node deidentifyWithFpe.js my-project "My SSN is 372819127" projects/my-project/locations/global/keyrings/my-keyring SSN_TOKEN` + + +----- + + -View the [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) +### Deidentify with Mask + +Deidentify sensitive data in a string by masking it with a character. + +View the [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) __Usage:__ -`node samples/deid.js` +`node deidentifyWithMask.js my-project string maskingCharacter numberToMask` ----- @@ -56,16 +171,18 @@ __Usage:__ -### Inspect +### Deidentify with Replacement + +Deidentify sensitive data in a string by replacing it with a given replacement string. -View the [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/inspect.js). +View the [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/inspect.js,samples/README.md) +[![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) __Usage:__ -`node samples/inspect.js` +`node deidentifyWithMask.js my-project string replacement` ----- @@ -73,16 +190,265 @@ __Usage:__ -### Job Management +### Delete Inspect Templates -View the [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/jobs.js). +Delete the DLP inspection configuration template with the specified name. -[![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) +View the [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) __Usage:__ -`node samples/jobs.js` +`node deleteInspectTemplates.js my-project projects/my-project/inspectTemplates/` + + +----- + + + + +### Delete Job + +Delete results of a Data Loss Prevention API job. + +View the [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) + +__Usage:__ + + +`node deleteJob.js my-project projects/YOUR_GCLOUD_PROJECT/dlpJobs/X-` + + +----- + + + + +### Delete Trigger + +Delete results of a Data Loss Prevention API job. + +View the [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) + +__Usage:__ + + +`node deleteTrigger.js my-rpoject projects/my-project/jobTriggers/my-trigger` + + +----- + + + + +### Inspect Bigquery + +Inspects a BigQuery table using the Data Loss Prevention API using Pub/Sub for job notifications. + +View the [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) + +__Usage:__ + + +`node inspectBigQuery.js my-project dataProjectId datasetId tableId topicId subscriptionId minLikelihood maxFindings infoTypes customInfoTypes` + + +----- + + + + +### Inspect Datastore + +Inspect a Datastore instance using the Data Loss Prevention API using Pub/Sub for job notifications. + +View the [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) + +__Usage:__ + + +`node inspectDatastore.js my-project dataProjectId namespaceId kind topicId subscriptionId minLikelihood maxFindings infoTypes customInfoTypes` + + +----- + + + + +### Inspect File + +Inspects a local text, PNG, or JPEG file using the Data Loss Prevention API. + +View the [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) + +__Usage:__ + + +`node inspectFile.js my-project filepath minLikelihood maxFindings infoTypes customInfoTypes includeQuote` + + +----- + + + + +### Inspect GCS File + +Inspects a text file stored on Google Cloud Storage with the Data Loss Prevention API, using Pub/Sub for job notifications. + +View the [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) + +__Usage:__ + + +`node inspectGCSFile.js my-project filepath minLikelihood maxFindings infoTypes customInfoTypes includeQuote` + + +----- + + + + +### Inspects strings + +Inspect a string using the Data Loss Prevention API. + +View the [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) + +__Usage:__ + + +`node inspectString.js my-project string minLikelihood maxFindings infoTypes customInfoTypes includeQuote` + + +----- + + + + +### kAnonymity Analysis + +Computes the k-anonymity of a column set in a Google BigQuery table + +View the [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) + +__Usage:__ + + +`node kAnonymityAnalysis.js my-project tableProjectId datasetId tableId topicId subscriptionId quasiIds` + + +----- + + + + +### kMap Estimation Analysis + +Computes the k-map risk estimation of a column set in a Google BigQuery table. + +View the [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) + +__Usage:__ + + +`node kMapEstimationAnalysis.js my-project tableProjectId datasetId tableId topicId subscriptionId regionCode quasiIds` + + +----- + + + + +### l Diversity Analysis + +Computes the l-diversity of a column set in a Google BigQuery table. + +View the [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) + +__Usage:__ + + +`node lDiversityAnalysis.js my-project tableProjectId datasetId tableId topicId subscriptionId sensitiveAttribute quasiIds` + + +----- + + + + +### List Inspect Templates + +List DLP inspection configuration templates. + +View the [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) + +__Usage:__ + + +`node listInspectTemplates.js my-project` + + +----- + + + + +### List jobs + +List Data Loss Prevention API jobs corresponding to a given filter. + +View the [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) + +__Usage:__ + + +`node listJobs.js my-project filter jobType` + + +----- + + + + +### List Triggers + +List Data Loss Prevention API job triggers. + +View the [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) + +__Usage:__ + + +`node listTriggers.js my-project` ----- @@ -92,6 +458,8 @@ __Usage:__ ### Metadata +List the types of sensitive information the DLP API supports + View the [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) @@ -99,7 +467,7 @@ View the [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samp __Usage:__ -`node samples/metadata.js` +`node metadata.js my-project langaugeCode filter` ----- @@ -107,16 +475,18 @@ __Usage:__ -### Quickstart +### Numerical Risk Analysis -View the [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/quickstart.js). +Computes risk metrics of a column of numbers in a Google BigQuery table. -[![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) +View the [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) __Usage:__ -`node samples/quickstart.js` +`node numericalRiskAnalysis.js my-project tableProjectId datasetId tableId columnName topicId subscriptionId` ----- @@ -124,16 +494,18 @@ __Usage:__ -### Redact +### Quickstart -View the [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/redact.js). +Inspects and assesses a string. -[![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) +View the [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) __Usage:__ -`node samples/redact.js` +`node quickstart.js my-project` ----- @@ -141,16 +513,18 @@ __Usage:__ -### Risk Analysis +### Redact Image + +Redact sensitive data from an image using the Data Loss Prevention API. -View the [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/risk.js). +View the [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/risk.js,samples/README.md) +[![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) __Usage:__ -`node samples/risk.js` +`node redactImage.js my-project filepath minLikelihood infoTypes outputPath` ----- @@ -158,16 +532,18 @@ __Usage:__ -### Inspect Templates +### Redact Text + +Redact sensitive data from text using the Data Loss Prevention API. -View the [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/templates.js). +View the [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/templates.js,samples/README.md) +[![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) __Usage:__ -`node samples/templates.js` +`node redactText.js my-project string minLikelihood infoTypes` ----- @@ -175,16 +551,18 @@ __Usage:__ -### Job Triggers +### Reidentify with FPE + +Reidentify sensitive data in a string using Format Preserving Encryption (FPE). -View the [source code](https://github.com/googleapis/nodejs-dlp/blob/master/samples/triggers.js). +View the [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/triggers.js,samples/README.md) +[![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) __Usage:__ -`node samples/triggers.js` +`node reidentifyWithFpe.js my-project string alphabet surrogateType keyName wrappedKey` diff --git a/packages/google-privacy-dlp/samples/quickstart.js b/packages/google-privacy-dlp/samples/quickstart.js index 637de7d5659..0d60c0e4339 100644 --- a/packages/google-privacy-dlp/samples/quickstart.js +++ b/packages/google-privacy-dlp/samples/quickstart.js @@ -1,4 +1,4 @@ -// Copyright 2017 Google LLC +// Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -14,10 +14,15 @@ 'use strict'; -// Imports the Google Cloud Data Loss Prevention library -const DLP = require('@google-cloud/dlp'); +// sample-metadata: +// title: Quickstart +// description: Inspects and assesses a string. +// usage: node quickstart.js my-project + +function main(projectId) { + // Imports the Google Cloud Data Loss Prevention library + const DLP = require('@google-cloud/dlp'); -async function quickStart() { // [START dlp_quickstart] // Instantiates a client @@ -27,54 +32,60 @@ async function quickStart() { const string = 'Robert Frost'; // The project ID to run the API call under - const projectId = process.env.GCLOUD_PROJECT; + // const projectId = 'my-project'; - // The minimum likelihood required before returning a match - const minLikelihood = 'LIKELIHOOD_UNSPECIFIED'; + async function quickStart() { + // The minimum likelihood required before returning a match + const minLikelihood = 'LIKELIHOOD_UNSPECIFIED'; - // The maximum number of findings to report (0 = server maximum) - const maxFindings = 0; + // The maximum number of findings to report (0 = server maximum) + const maxFindings = 0; - // The infoTypes of information to match - const infoTypes = [{name: 'PERSON_NAME'}, {name: 'US_STATE'}]; + // The infoTypes of information to match + const infoTypes = [{name: 'PERSON_NAME'}, {name: 'US_STATE'}]; - // Whether to include the matching string - const includeQuote = true; + // Whether to include the matching string + const includeQuote = true; - // Construct item to inspect - const item = {value: string}; + // Construct item to inspect + const item = {value: string}; - // Construct request - const request = { - parent: `projects/${projectId}/locations/global`, - inspectConfig: { - infoTypes: infoTypes, - minLikelihood: minLikelihood, - limits: { - maxFindingsPerRequest: maxFindings, + // Construct request + const request = { + parent: `projects/${projectId}/locations/global`, + inspectConfig: { + infoTypes: infoTypes, + minLikelihood: minLikelihood, + limits: { + maxFindingsPerRequest: maxFindings, + }, + includeQuote: includeQuote, }, - includeQuote: includeQuote, - }, - item: item, - }; + item: item, + }; - // Run request - const [response] = await dlp.inspectContent(request); - const findings = response.result.findings; - if (findings.length > 0) { - console.log('Findings:'); - findings.forEach(finding => { - if (includeQuote) { - console.log(`\tQuote: ${finding.quote}`); - } - console.log(`\tInfo type: ${finding.infoType.name}`); - console.log(`\tLikelihood: ${finding.likelihood}`); - }); - } else { - console.log('No findings.'); + // Run request + const [response] = await dlp.inspectContent(request); + const findings = response.result.findings; + if (findings.length > 0) { + console.log('Findings:'); + findings.forEach(finding => { + if (includeQuote) { + console.log(`\tQuote: ${finding.quote}`); + } + console.log(`\tInfo type: ${finding.infoType.name}`); + console.log(`\tLikelihood: ${finding.likelihood}`); + }); + } else { + console.log('No findings.'); + } } + quickStart(); // [END dlp_quickstart] } -quickStart().catch(err => { - console.error(`Error in inspectString: ${err.message || err}`); + +main(...process.argv.slice(2)); +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; }); diff --git a/packages/google-privacy-dlp/src/v2/dlp_service_client.ts b/packages/google-privacy-dlp/src/v2/dlp_service_client.ts index 587db74dee1..503a187447a 100644 --- a/packages/google-privacy-dlp/src/v2/dlp_service_client.ts +++ b/packages/google-privacy-dlp/src/v2/dlp_service_client.ts @@ -356,12 +356,11 @@ export class DlpServiceClient { } ); + const descriptor = this.descriptors.page[methodName] || undefined; const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], - this.descriptors.page[methodName] || - this.descriptors.stream[methodName] || - this.descriptors.longrunning[methodName] + descriptor ); this.innerApiCalls[methodName] = apiCall; diff --git a/packages/google-privacy-dlp/synth.metadata b/packages/google-privacy-dlp/synth.metadata index 9002523f6e6..b9bc83753a1 100644 --- a/packages/google-privacy-dlp/synth.metadata +++ b/packages/google-privacy-dlp/synth.metadata @@ -3,23 +3,23 @@ { "git": { "name": ".", - "remote": "https://github.com/googleapis/nodejs-dlp.git", - "sha": "62e1b645d48f8ac6e5c09da4a45eae2fb5fc7a76" + "remote": "git@github.com:googleapis/nodejs-dlp.git", + "sha": "cd14096541ea63caca0f355b56a289e58c9bb52c" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "4f4aa3a03e470f1390758b9d89eb1aa88837a5be", - "internalRef": "320300472" + "sha": "393d03088e368d79c8f4cd5e3610c7df0bb118bf", + "internalRef": "326067016" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "94421c47802f56a44c320257b2b4c190dc7d6b68" + "sha": "bd0deaa1113b588d70449535ab9cbf0f2bd0e72f" } } ],