我将Google DLP的请求体作为文本值。是否有任何方法可以配置用户定义的RedactConfig来修改输出。。?。有什么方法可以实现这一点吗。。?
{
"item":{
"value":"My name is Alicia Abernathy, and my email address is aabernathy@example.com."
},
"deidentifyConfig":{
"infoTypeTransformations":{
"transformations":[
{
"infoTypes":[
{
"name":"EMAIL_ADDRESS"
}
],
"primitiveTransformation":{
"replaceWithInfoTypeConfig":{
}
}
}
]
}
},
"inspectConfig":{
"infoTypes":[
{
"name":"EMAIL_ADDRESS"
}
]
}
}
是否有任何方法可以配置用户定义的RedactConfig来修改输出。。?
我需要以下来自谷歌DLP的O/p。
{
"item": {
"value": "My name is Alicia Abernathy, and my email address is {{__aabernathy@example.com__[EMAIL_ADDRESS]__}}."
},
"overview": {
"transformedBytes": "22",
"transformationSummaries": [
{
"infoType": {
"name": "EMAIL_ADDRESS"
},
"transformation": {
"replaceWithInfoTypeConfig": {}
},
"results": [
{
"count": "1",
"code": "SUCCESS"
}
],
"transformedBytes": "22"
}
]
}
}
所以您实际上并不想匿名化文本,只想向其中添加信息?此API不适用于此。。。您最好的选择是只使用inspectContent,并使用结果中的字节偏移量进行自己的转换。
伪代码中的类似内容。。。
私有静态最终无效标签StringWithFindings(字符串到标签,InspectContentResponse dlpResponse({StringBuilder输出=新StringBuilder((;final byte[]messageBytes=ByteString.copyFromUtf8(字符串到标签(.toByteArray((;ImmutableList sortedFindings=sort(dlpResponse.getResult((.getFindingsList(((;
int lastEnd = 0;
for (Finding finding : sortedFindings) {
String quote = Ascii.toLowerCase(finding.getQuote());
String infoType = finding.getInfoType().getName();
String surrogate = String.format("{{__%s__[%s]__}}",
quote, infoType);
final byte[] surrogateBytes = surrogate.getBytes(StandardCharsets.UTF_8);
int startIndex = (int) finding.getLocation().getByteRange().getStart();
int endIndex = (int) finding.getLocation().getByteRange().getEnd();
if (lastEnd == 0 || startIndex > lastEnd) {
output.write(messageBytes, lastEnd, startIndex - lastEnd);
output.write(surrogateBytes, 0, surrogate.length);
}
if (endIndex > lastEnd) {
lastEnd = endIndex;
}
}
if (messageBytes.length > lastEnd) {
output.write(messageBytes, lastEnd, messageBytes.length - lastEnd);
}
return output.toString();
}