(projectId, string, minLikelihood, infoTypes)
| 18 | // usage: node redactText.js my-project string minLikelihood infoTypes |
| 19 | |
| 20 | function main(projectId, string, minLikelihood, infoTypes) { |
| 21 | infoTypes = transformCLI(infoTypes); |
| 22 | // [START dlp_redact_text] |
| 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 | // Construct transformation config which replaces sensitive info with its info type. |
| 33 | // E.g., "Her email is xxx@example.com" => "Her email is [EMAIL_ADDRESS]" |
| 34 | const replaceWithInfoTypeTransformation = { |
| 35 | primitiveTransformation: { |
| 36 | replaceWithInfoTypeConfig: {}, |
| 37 | }, |
| 38 | }; |
| 39 | |
| 40 | async function redactText() { |
| 41 | // Construct redaction request |
| 42 | const request = { |
| 43 | parent: `projects/${projectId}/locations/global`, |
| 44 | item: { |
| 45 | value: string, |
| 46 | }, |
| 47 | deidentifyConfig: { |
| 48 | infoTypeTransformations: { |
| 49 | transformations: [replaceWithInfoTypeTransformation], |
| 50 | }, |
| 51 | }, |
| 52 | inspectConfig: { |
| 53 | minLikelihood: minLikelihood, |
| 54 | infoTypes: infoTypes, |
| 55 | }, |
| 56 | }; |
| 57 | |
| 58 | // Run string redaction |
| 59 | const [response] = await dlp.deidentifyContent(request); |
| 60 | const resultString = response.item.value; |
| 61 | console.log(`Redacted text: ${resultString}`); |
| 62 | } |
| 63 | redactText(); |
| 64 | // [END dlp_redact_text] |
| 65 | } |
| 66 | |
| 67 | main(...process.argv.slice(2)); |
| 68 | process.on('unhandledRejection', err => { |
no test coverage detected