0

我将 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 来修改输出..?

我需要来自 Google 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"
      }
    ]
  }
}

4

1 回答 1

0

所以您实际上并不想匿名化文本,您只想向其中添加信息?此 API 不适合……您最好的选择是仅使用 inspectContent 并使用结果中的字节偏移量进行您自己的转换。

像这样的伪代码......

私有静态最终无效标签StringWithFindings(String stringToLabel,InspectContentResponse dlpResponse){StringBuilder输出=新StringBuilder();最终字节[] 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();

}

于 2020-04-22T15:07:42.557 回答