MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

dlp/inspectGcsFileWithSampling.js:19–149  ·  view source on GitHub ↗
(projectId, gcsUri, topicId, subscriptionId, infoTypes)

Source from the content-addressed store, hash-verified

17// description: Inspects a text file stored on Google Cloud Storage with sampling, using Pub/Sub for job notifications.
18// usage: node inspectGcsFileWithSampling.js.js my-project gcsUri topicId subscriptionId infoTypes
19async function main(projectId, gcsUri, topicId, subscriptionId, infoTypes) {
20 infoTypes = transformCLI(infoTypes);
21
22 // [START dlp_inspect_gcs_with_sampling]
23 // Import the Google Cloud client libraries
24 const DLP = require('@google-cloud/dlp');
25 const {PubSub} = require('@google-cloud/pubsub');
26
27 // Instantiates clients
28 const dlp = new DLP.DlpServiceClient();
29 const pubsub = new PubSub();
30
31 // The project ID to run the API call under
32 // const projectId = 'my-project';
33
34 // The gcs file path
35 // const gcsUri = 'gs://" + "your-bucket-name" + "/path/to/your/file.txt';
36
37 // Specify the type of info the inspection will look for.
38 // See https://cloud.google.com/dlp/docs/infotypes-reference for complete list of info types
39 // const infoTypes = [{ name: 'PERSON_NAME' }];
40
41 // The name of the Pub/Sub topic to notify once the job completes
42 // TODO(developer): create a Pub/Sub topic to use for this
43 // const topicId = 'MY-PUBSUB-TOPIC'
44
45 // The name of the Pub/Sub subscription to use when listening for job
46 // completion notifications
47 // TODO(developer): create a Pub/Sub subscription to use for this
48 // const subscriptionId = 'MY-PUBSUB-SUBSCRIPTION'
49
50 // DLP Job max time (in milliseconds)
51 const DLP_JOB_WAIT_TIME = 15 * 1000 * 60;
52
53 async function inspectGcsFileSampling() {
54 // Specify the GCS file to be inspected and sampling configuration
55 const storageItemConfig = {
56 cloudStorageOptions: {
57 fileSet: {url: gcsUri},
58 bytesLimitPerFile: 200,
59 filesLimitPercent: 90,
60 fileTypes: [DLP.protos.google.privacy.dlp.v2.FileType.TEXT_FILE],
61 sampleMethod:
62 DLP.protos.google.privacy.dlp.v2.CloudStorageOptions.SampleMethod
63 .RANDOM_START,
64 },
65 };
66
67 // Specify how the content should be inspected.
68 const inspectConfig = {
69 infoTypes: infoTypes,
70 minLikelihood: DLP.protos.google.privacy.dlp.v2.Likelihood.POSSIBLE,
71 includeQuote: true,
72 excludeInfoTypes: true,
73 };
74
75 // Specify the action that is triggered when the job completes.
76 const actions = [

Callers

nothing calls this directly

Calls 2

inspectGcsFileSamplingFunction · 0.85
transformCLIFunction · 0.70

Tested by

no test coverage detected