( projectId, filepath, minLikelihood, maxFindings, infoTypes, customInfoTypes, includeQuote )
| 18 | // usage: node inspectFile.js my-project filepath minLikelihood maxFindings infoTypes customInfoTypes includeQuote |
| 19 | |
| 20 | function main( |
| 21 | projectId, |
| 22 | filepath, |
| 23 | minLikelihood, |
| 24 | maxFindings, |
| 25 | infoTypes, |
| 26 | customInfoTypes, |
| 27 | includeQuote |
| 28 | ) { |
| 29 | [infoTypes, customInfoTypes] = transformCLI(infoTypes, customInfoTypes); |
| 30 | |
| 31 | // [START dlp_inspect_file] |
| 32 | // Imports the Google Cloud Data Loss Prevention library |
| 33 | const DLP = require('@google-cloud/dlp'); |
| 34 | |
| 35 | // Import other required libraries |
| 36 | const fs = require('fs'); |
| 37 | const mime = require('mime'); |
| 38 | |
| 39 | // Instantiates a client |
| 40 | const dlp = new DLP.DlpServiceClient(); |
| 41 | |
| 42 | // The project ID to run the API call under |
| 43 | // const projectId = 'my-project'; |
| 44 | |
| 45 | // The path to a local file to inspect. Can be a text, JPG, or PNG file. |
| 46 | // const filepath = 'path/to/image.png'; |
| 47 | |
| 48 | // The minimum likelihood required before returning a match |
| 49 | // const minLikelihood = 'LIKELIHOOD_UNSPECIFIED'; |
| 50 | |
| 51 | // The maximum number of findings to report per request (0 = server maximum) |
| 52 | // const maxFindings = 0; |
| 53 | |
| 54 | // The infoTypes of information to match |
| 55 | // const infoTypes = [{ name: 'PHONE_NUMBER' }, { name: 'EMAIL_ADDRESS' }, { name: 'CREDIT_CARD_NUMBER' }]; |
| 56 | |
| 57 | // The customInfoTypes of information to match |
| 58 | // const customInfoTypes = [{ infoType: { name: 'DICT_TYPE' }, dictionary: { wordList: { words: ['foo', 'bar', 'baz']}}}, |
| 59 | // { infoType: { name: 'REGEX_TYPE' }, regex: {pattern: '\\(\\d{3}\\) \\d{3}-\\d{4}'}}]; |
| 60 | |
| 61 | // Whether to include the matching string |
| 62 | // const includeQuote = true; |
| 63 | |
| 64 | async function inspectFile() { |
| 65 | // Construct file data to inspect |
| 66 | const fileTypeConstant = |
| 67 | ['image/jpeg', 'image/bmp', 'image/png', 'image/svg'].indexOf( |
| 68 | mime.getType(filepath) |
| 69 | ) + 1; |
| 70 | const fileBytes = Buffer.from(fs.readFileSync(filepath)).toString('base64'); |
| 71 | const item = { |
| 72 | byteItem: { |
| 73 | type: fileTypeConstant, |
| 74 | data: fileBytes, |
| 75 | }, |
| 76 | }; |
| 77 |
no test coverage detected