com.google.privacy.dlp.v2.ProjectName Java Examples

The following examples show how to use com.google.privacy.dlp.v2.ProjectName. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TextStreamingPipeline.java    From dlp-dataflow-deidentification with Apache License 2.0 6 votes vote down vote up
@ProcessElement
public void processElement(ProcessContext c) throws IOException {

  try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {

    ContentItem contentItem = ContentItem.newBuilder().setValue(c.element()).build();

    DeidentifyContentRequest request =
        DeidentifyContentRequest.newBuilder()
            .setParent(ProjectName.of(this.projectId).toString())
            .setDeidentifyTemplateName(this.deIdentifyTemplateName.get())
            .setInspectTemplateName(this.inspectTemplateName.get())
            .setItem(contentItem)
            .build();

    DeidentifyContentResponse response = dlpServiceClient.deidentifyContent(request);

    String encryptedData = response.getItem().getValue();
    LOG.info(
        "Successfully tokenized request size: " + request.toByteString().size() + " bytes");
    c.output(encryptedData);
  }
}
 
Example #2
Source File: DLPTextToBigQueryStreaming.java    From dlp-dataflow-deidentification with Apache License 2.0 6 votes vote down vote up
@Setup
public void setup() {
  if (this.inspectTemplateName.isAccessible()) {
    if (this.inspectTemplateName.get() != null) {
      this.inspectTemplateExist = true;
    }
  }
  if (this.deIdentifyTemplateName.isAccessible()) {
    if (this.deIdentifyTemplateName.get() != null) {
      this.requestBuilder =
          DeidentifyContentRequest.newBuilder()
              .setParent(ProjectName.of(this.dlpProjectId.get()).toString())
              .setDeidentifyTemplateName(this.deIdentifyTemplateName.get());
      if (this.inspectTemplateExist) {
        this.requestBuilder.setInspectTemplateName(this.inspectTemplateName.get());
      }
    }
  }
}
 
Example #3
Source File: DLPTokenizationDoFn.java    From dlp-dataflow-deidentification with Apache License 2.0 6 votes vote down vote up
public DeidentifyContentRequest buildDeidentifyContentRequest(ContentItem tableItem) {
  DeidentifyContentRequest request;
  if (this.inspectTemplateExist) {
    request =
        DeidentifyContentRequest.newBuilder()
            .setParent(ProjectName.of(this.projectId).toString())
            .setDeidentifyTemplateName(this.deIdentifyTemplateName.get())
            .setInspectTemplateName(this.inspectTemplateName.get())
            .setItem(tableItem)
            .build();
  } else {
    request =
        DeidentifyContentRequest.newBuilder()
            .setParent(ProjectName.of(this.projectId).toString())
            .setDeidentifyTemplateName(this.deIdentifyTemplateName.get())
            .setItem(tableItem)
            .build();
  }
  return request;
}
 
Example #4
Source File: DLPTextToBigQueryStreaming.java    From DataflowTemplates with Apache License 2.0 6 votes vote down vote up
@Setup
public void setup() {
  if (this.inspectTemplateName.isAccessible()) {
    if (this.inspectTemplateName.get() != null) {
      this.inspectTemplateExist = true;
    }
  }
  if (this.deIdentifyTemplateName.isAccessible()) {
    if (this.deIdentifyTemplateName.get() != null) {
      this.requestBuilder =
          DeidentifyContentRequest.newBuilder()
              .setParent(ProjectName.of(this.dlpProjectId.get()).toString())
              .setDeidentifyTemplateName(this.deIdentifyTemplateName.get());
      if (this.inspectTemplateExist) {
        this.requestBuilder.setInspectTemplateName(this.inspectTemplateName.get());
      }
    }
  }
}
 
Example #5
Source File: DLPDeidentifyText.java    From beam with Apache License 2.0 6 votes vote down vote up
@Setup
public void setup() throws IOException {
  requestBuilder =
      DeidentifyContentRequest.newBuilder().setParent(ProjectName.of(projectId).toString());
  if (inspectTemplateName != null) {
    requestBuilder.setInspectTemplateName(inspectTemplateName);
  }
  if (inspectConfig != null) {
    requestBuilder.setInspectConfig(inspectConfig);
  }
  if (deidentifyConfig != null) {
    requestBuilder.setDeidentifyConfig(deidentifyConfig);
  }
  if (deidentifyTemplateName != null) {
    requestBuilder.setDeidentifyTemplateName(deidentifyTemplateName);
  }
  dlpServiceClient = DlpServiceClient.create();
}
 
Example #6
Source File: DLPReidentifyText.java    From beam with Apache License 2.0 6 votes vote down vote up
@Setup
public void setup() throws IOException {
  requestBuilder =
      ReidentifyContentRequest.newBuilder().setParent(ProjectName.of(projectId).toString());
  if (inspectTemplateName != null) {
    requestBuilder.setInspectTemplateName(inspectTemplateName);
  }
  if (inspectConfig != null) {
    requestBuilder.setInspectConfig(inspectConfig);
  }
  if (reidentifyConfig != null) {
    requestBuilder.setReidentifyConfig(reidentifyConfig);
  }
  if (reidentifyTemplateName != null) {
    requestBuilder.setReidentifyTemplateName(reidentifyTemplateName);
  }
  dlpServiceClient = DlpServiceClient.create();
}
 
Example #7
Source File: S3Import.java    From dlp-dataflow-deidentification with Apache License 2.0 5 votes vote down vote up
@Setup
public void setup() {
  this.requestBuilder =
      InspectContentRequest.newBuilder()
          .setParent(ProjectName.of(this.projectId).toString())
          .setInspectTemplateName(this.inspectTemplateName);
}
 
Example #8
Source File: DLPInspectText.java    From beam with Apache License 2.0 5 votes vote down vote up
@Setup
public void setup() throws IOException {
  this.requestBuilder =
      InspectContentRequest.newBuilder().setParent(ProjectName.of(this.projectId).toString());
  if (inspectTemplateName != null) {
    requestBuilder.setInspectTemplateName(this.inspectTemplateName);
  }
  if (inspectConfig != null) {
    requestBuilder.setInspectConfig(inspectConfig);
  }
  dlpServiceClient = DlpServiceClient.create();
}
 
Example #9
Source File: DLPClient.java    From android-docs-samples with Apache License 2.0 4 votes vote down vote up
/**
 * Example showing how to inspect a string to identify names, phone number, and
 * credit card numbers.
 *
 * @param string text to analyze
 * @return a string describing what was identified in the string
 */
@NonNull
public String inspectString(@NonNull String string) {
    // set sources of information to identify
    List<InfoType> infoTypes = ImmutableList.of(
            InfoType.newBuilder().setName("PERSON_NAME").build(),
            InfoType.newBuilder().setName("CREDIT_CARD_NUMBER").build(),
            InfoType.newBuilder().setName("PHONE_NUMBER").build());

    // configuration for the request
    InspectConfig inspectConfig =
            InspectConfig.newBuilder()
                    .addAllInfoTypes(infoTypes)
                    .setMinLikelihood(Likelihood.LIKELIHOOD_UNSPECIFIED)
                    .setLimits(InspectConfig.FindingLimits.newBuilder()
                            .setMaxFindingsPerRequest(0)
                            .build())
                    .setIncludeQuote(true)
                    .build();

    // the content to be analyzed
    ContentItem contentItem = ContentItem.newBuilder()
            .setByteItem(ByteContentItem.newBuilder()
                    .setType(ByteContentItem.BytesType.TEXT_UTF8)
                    .setData(ByteString.copyFromUtf8(string))
                    .build())
            .build();

    // create a request
    InspectContentRequest request =
            InspectContentRequest.newBuilder()
                    .setParent(ProjectName.of(mProjectId).toString())
                    .setInspectConfig(inspectConfig)
                    .setItem(contentItem)
                    .build();

    // call the API
    InspectContentResponse response = mClient.inspectContent(request);

    // format response into a string
    StringBuilder sb = new StringBuilder("Findings:");
    if (response.getResult().getFindingsCount() > 0) {
        for (Finding finding : response.getResult().getFindingsList()) {
            sb.append("\n")
                    .append("  Quote: ").append(finding.getQuote())
                    .append("  Info type: ").append(finding.getInfoType().getName())
                    .append("  Likelihood: ").append(finding.getLikelihood());
        }
    } else {
        sb.append("No findings.");
    }
    return sb.toString();
}
 
Example #10
Source File: DLPClient.java    From android-docs-samples with Apache License 2.0 4 votes vote down vote up
/**
 * Example showing how to inspect an image to identify names, phone number, and
 * credit card numbers.
 *
 * @param inputImage image to analyze (PNG)
 * @return a redacted image
 */
@NonNull
public ByteString redactPhoto(@NonNull ByteString inputImage) {
    // set sources of information to identify
    List<InfoType> infoTypes = ImmutableList.of(
            InfoType.newBuilder().setName("PERSON_NAME").build(),
            InfoType.newBuilder().setName("CREDIT_CARD_NUMBER").build(),
            InfoType.newBuilder().setName("PHONE_NUMBER").build());

    // set sources of information that should be redacted (to match infoTypes)
    List<RedactImageRequest.ImageRedactionConfig> imageRedactionConfigs =
            infoTypes.stream().map(infoType ->
                    RedactImageRequest.ImageRedactionConfig.newBuilder()
                            .setInfoType(infoType)
                            .build())
                    .collect(Collectors.toList());

    // configuration for the request
    InspectConfig inspectConfig =
            InspectConfig.newBuilder()
                    .addAllInfoTypes(infoTypes)
                    .setMinLikelihood(Likelihood.POSSIBLE)
                    .build();

    // content to be redacted
    ByteContentItem byteContentItem =
            ByteContentItem.newBuilder()
                    .setType(ByteContentItem.BytesType.IMAGE_PNG)
                    .setData(inputImage)
                    .build();

    // create a request
    RedactImageRequest redactImageRequest =
            RedactImageRequest.newBuilder()
                    .setParent(ProjectName.of(mProjectId).toString())
                    .addAllImageRedactionConfigs(imageRedactionConfigs)
                    .setByteItem(byteContentItem)
                    .setInspectConfig(inspectConfig)
                    .build();

    // call the API and return the redacted image
    RedactImageResponse redactImageResponse = mClient.redactImage(redactImageRequest);
    return redactImageResponse.getRedactedImage();
}