in dlp/deIdentifyTableWithMultipleCryptoHash.js [73:151]
async function deIdentifyTableWithMultipleCryptoHash() {
// The type of info the inspection will look for.
const infoTypes = [{name: 'PHONE_NUMBER'}, {name: 'EMAIL_ADDRESS'}];
// The fields to be de-identified.
const fieldIds1 = [{name: 'userid'}];
const fieldIds2 = [{name: 'comments'}];
// Construct two primitive transformations using two different keys.
const primitiveTransformation1 = {
cryptoHashConfig: {
cryptoKey: {
transient: {
name: transientKey1,
},
},
},
};
const primitiveTransformation2 = {
cryptoHashConfig: {
cryptoKey: {
transient: {
name: transientKey2,
},
},
},
};
// Construct infoType transformation using transient key 2
const infoTypeTransformation = {
primitiveTransformation: primitiveTransformation2,
infoTypes: infoTypes,
};
// Associate each field with transformation defined above.
const fieldTransformations = [
{
fields: fieldIds1,
primitiveTransformation: primitiveTransformation1,
},
{
fields: fieldIds2,
infoTypeTransformations: {
transformations: [infoTypeTransformation],
},
},
];
// Use transformation confiugrations and construct de-identify configuration.
const deidentifyConfig = {
recordTransformations: {
fieldTransformations: fieldTransformations,
},
};
// Combine configurations into a request for the service.
const request = {
parent: `projects/${projectId}/locations/global`,
deidentifyConfig: deidentifyConfig,
inspectConfig: {
infoTypes: infoTypes,
},
item: {
table: tableToDeIdentify,
},
};
// Send the request and receive response from the service.
const [response] = await dlp.deidentifyContent(request);
const deidentifiedTable = response.item.table;
// Print the results.
console.log(
`Deidentified table: ${JSON.stringify(deidentifiedTable, null, 2)}`
);
}