(projectId)
| 19 | // description: Inspect a table for sensitive content such as Phone Number. |
| 20 | // usage: node inspectTable.js my-project |
| 21 | function main(projectId) { |
| 22 | // [START dlp_inspect_table] |
| 23 | // Imports the Google Cloud Data Loss Prevention library |
| 24 | const DLP = require('@google-cloud/dlp'); |
| 25 | |
| 26 | // Instantiates a client |
| 27 | const dlp = new DLP.DlpServiceClient(); |
| 28 | |
| 29 | // The project ID to run the API call under |
| 30 | // const projectId = 'my-project'; |
| 31 | |
| 32 | // The infoTypes of information to match |
| 33 | const infoTypes = [{name: 'PHONE_NUMBER'}]; |
| 34 | |
| 35 | // Table data |
| 36 | const tableData = { |
| 37 | headers: [{name: 'name'}, {name: 'phone'}], |
| 38 | rows: [ |
| 39 | { |
| 40 | values: [{stringValue: 'John Doe'}, {stringValue: '(206) 555-0123'}], |
| 41 | }, |
| 42 | ], |
| 43 | }; |
| 44 | |
| 45 | async function inspectTable() { |
| 46 | // Specify the table to be inspected. |
| 47 | const item = { |
| 48 | table: tableData, |
| 49 | }; |
| 50 | |
| 51 | // Construct the configuration for the Inspect request. |
| 52 | const inspectConfig = { |
| 53 | infoTypes: infoTypes, |
| 54 | includeQuote: true, |
| 55 | }; |
| 56 | |
| 57 | // Construct the Inspect request to be sent by the client. |
| 58 | const request = { |
| 59 | parent: `projects/${projectId}/locations/global`, |
| 60 | inspectConfig: inspectConfig, |
| 61 | item: item, |
| 62 | }; |
| 63 | |
| 64 | // Use the client to send the API request. |
| 65 | const [response] = await dlp.inspectContent(request); |
| 66 | |
| 67 | // Print findings. |
| 68 | const findings = response.result.findings; |
| 69 | if (findings.length > 0) { |
| 70 | console.log(`Findings: ${findings.length}\n`); |
| 71 | findings.forEach(finding => { |
| 72 | console.log(`InfoType: ${finding.infoType.name}`); |
| 73 | console.log(`\tQuote: ${finding.quote}`); |
| 74 | console.log(`\tLikelihood: ${finding.likelihood} \n`); |
| 75 | }); |
| 76 | } else { |
| 77 | console.log('No findings.'); |
| 78 | } |
no test coverage detected