Google DLP пользовательский вывод для конфиденциальных данных - PullRequest
0 голосов
/ 21 апреля 2020

У меня есть это тело запроса для 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 для изменения вывода ..?

И мне нужно следующее O / P из Google DLP.

{
  "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"
      }
    ]
  }
}

1 Ответ

0 голосов
/ 22 апреля 2020

То есть вы не хотите анонимизировать текст, вы просто хотите добавить к нему информацию? Этот API не подходит для этого ... лучше всего использовать inspectContent, а смещения байтов в выводах выполнять собственные преобразования.

Что-то подобное в псевдокоде ...

личное состояние c окончательное пустое значение 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();

}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...