in dlp/inspectWithHotwordRules.js [67:139]
async function inspectWithHotwordRule() {
// Construct item to inspect
const item = {
byteItem: {
type: DLP.protos.google.privacy.dlp.v2.ByteContentItem.BytesType
.TEXT_UTF8,
data: Buffer.from(string, 'utf-8'),
},
};
// Construct a hot word rule
const hotwordRule = {
hotwordRegex: {
pattern: hotwordRegexPattern,
},
proximity: {
windowBefore: 10,
},
likelihoodAdjustment: {
fixedLikelihood:
DLP.protos.google.privacy.dlp.v2.Likelihood.VERY_LIKELY,
},
};
// Construct a hotword inspection rule
const inpectionRuleSet = [
{
infoTypes: customInfoTypes.map(
customInfoType => customInfoType.infoType
),
rules: [{hotwordRule: hotwordRule}],
},
];
// Assigns likelihood to each match
customInfoTypes = customInfoTypes.map(customInfoType => {
customInfoType.likelihood =
DLP.protos.google.privacy.dlp.v2.Likelihood.POSSIBLE;
return customInfoType;
});
// Construct request
const request = {
parent: `projects/${projectId}/locations/global`,
inspectConfig: {
infoTypes: infoTypes,
customInfoTypes: customInfoTypes,
minLikelihood: minLikelihood,
includeQuote: includeQuote,
limits: {
maxFindingsPerRequest: maxFindings,
},
ruleSet: inpectionRuleSet,
},
item: item,
};
// Run request
const [response] = await dlp.inspectContent(request);
const findings = response.result.findings;
if (findings.length > 0) {
console.log('Findings:');
findings.forEach(finding => {
if (includeQuote) {
console.log(`\tQuote: ${finding.quote}`);
}
console.log(`\tInfo type: ${finding.infoType.name}`);
console.log(`\tLikelihood: ${finding.likelihood}`);
});
} else {
console.log('No findings.');
}
}