(projectId, string, maskingCharacter, numberToMask)
| 20 | // usage: node deidentifyWithMask.js my-project string maskingCharacter numberToMask |
| 21 | |
| 22 | function main(projectId, string, maskingCharacter, numberToMask) { |
| 23 | // [START dlp_deidentify_masking] |
| 24 | // Imports the Google Cloud Data Loss Prevention library |
| 25 | const DLP = require('@google-cloud/dlp'); |
| 26 | |
| 27 | // Instantiates a client |
| 28 | const dlp = new DLP.DlpServiceClient(); |
| 29 | |
| 30 | // The project ID to run the API call under |
| 31 | // const projectId = 'my-project-id'; |
| 32 | |
| 33 | // The string to deidentify |
| 34 | // const string = 'My SSN is 372819127'; |
| 35 | |
| 36 | // (Optional) The maximum number of sensitive characters to mask in a match |
| 37 | // If omitted from the request or set to 0, the API will mask any matching characters |
| 38 | // const numberToMask = 5; |
| 39 | |
| 40 | // (Optional) The character to mask matching sensitive data with |
| 41 | // const maskingCharacter = 'x'; |
| 42 | |
| 43 | // Construct deidentification request |
| 44 | const item = {value: string}; |
| 45 | |
| 46 | async function deidentifyWithMask() { |
| 47 | const request = { |
| 48 | parent: `projects/${projectId}/locations/global`, |
| 49 | deidentifyConfig: { |
| 50 | infoTypeTransformations: { |
| 51 | transformations: [ |
| 52 | { |
| 53 | primitiveTransformation: { |
| 54 | characterMaskConfig: { |
| 55 | maskingCharacter: maskingCharacter, |
| 56 | numberToMask: numberToMask, |
| 57 | }, |
| 58 | }, |
| 59 | }, |
| 60 | ], |
| 61 | }, |
| 62 | }, |
| 63 | item: item, |
| 64 | }; |
| 65 | |
| 66 | // Run deidentification request |
| 67 | const [response] = await dlp.deidentifyContent(request); |
| 68 | const deidentifiedItem = response.item; |
| 69 | console.log(deidentifiedItem.value); |
| 70 | } |
| 71 | |
| 72 | deidentifyWithMask(); |
| 73 | // [END dlp_deidentify_masking] |
| 74 | } |
| 75 | |
| 76 | main(...process.argv.slice(2)); |
| 77 | process.on('unhandledRejection', err => { |
no test coverage detected