我的这个请求体为Google DLP的文本值。有没有办法配置用户定义的RedactConfig来修改输出...?有什么方法可以实现那个...?
{
"item":{
"value":"My name is Alicia Abernathy, and my email address is [email protected]."
},
"deidentifyConfig":{
"infoTypeTransformations":{
"transformations":[
{
"infoTypes":[
{
"name":"EMAIL_ADDRESS"
}
],
"primitiveTransformation":{
"replaceWithInfoTypeConfig":{
}
}
}
]
}
},
"inspectConfig":{
"infoTypes":[
{
"name":"EMAIL_ADDRESS"
}
]
}
}
有什么方法可以配置用户自定义RedactConfig来修改输出...?
我需要Google DLP的以下OP。
{
"item": {
"value": "My name is Alicia Abernathy, and my email address is {{[email protected]__[EMAIL_ADDRESS]__}}."
},
"overview": {
"transformedBytes": "22",
"transformationSummaries": [
{
"infoType": {
"name": "EMAIL_ADDRESS"
},
"transformation": {
"replaceWithInfoTypeConfig": {}
},
"results": [
{
"count": "1",
"code": "SUCCESS"
}
],
"transformedBytes": "22"
}
]
}
}
所以你其实并不想对文本进行匿名化处理,你只是想给文本添加信息?这个API并不适合......你最好的办法是使用 inspectContent,然后用发现中的字节偏移做你自己的转换。
像这样的伪代码......
private static final void labelStringWithFindings( String stringToLabel, InspectContentResponse dlpResponse) { StringBuilder output = new StringBuilder(); final byte[] messageBytes = ByteString.copyFromUtf8( stringToLabel).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();
}