*
* try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
- * String name = "EMAIL_ADDRESS";
- * InfoType infoTypesElement = InfoType.newBuilder()
- * .setName(name)
- * .build();
- * List<InfoType> infoTypes = Arrays.asList(infoTypesElement);
- * InspectConfig inspectConfig = InspectConfig.newBuilder()
- * .addAllInfoTypes(infoTypes)
- * .build();
- * String type = "text/plain";
- * String value = "My email is example{@literal @}example.com.";
- * ContentItem itemsElement = ContentItem.newBuilder()
- * .setType(type)
- * .setValue(value)
- * .build();
- * List<ContentItem> items = Arrays.asList(itemsElement);
- * InspectContentResponse response = dlpServiceClient.inspectContent(inspectConfig, items);
+ * DeidentifyConfig deidentifyConfig = DeidentifyConfig.newBuilder().build();
+ * InspectConfig inspectConfig = InspectConfig.newBuilder().build();
+ * List<ContentItem> items = new ArrayList<>();
+ * DeidentifyContentResponse response = dlpServiceClient.deidentifyContent(deidentifyConfig, inspectConfig, items);
* }
*
*
@@ -197,6 +193,209 @@ public final OperationsClient getOperationsClient() {
return operationsClient;
}
+ // AUTO-GENERATED DOCUMENTATION AND METHOD
+ /**
+ * De-identifies potentially sensitive info from a list of strings. This method has limits on
+ * input size and output size.
+ *
+ * Sample code: + * + *
+ * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
+ * DeidentifyConfig deidentifyConfig = DeidentifyConfig.newBuilder().build();
+ * InspectConfig inspectConfig = InspectConfig.newBuilder().build();
+ * List<ContentItem> items = new ArrayList<>();
+ * DeidentifyContentResponse response = dlpServiceClient.deidentifyContent(deidentifyConfig, inspectConfig, items);
+ * }
+ *
+ *
+ * @param deidentifyConfig Configuration for the de-identification of the list of content items.
+ * @param inspectConfig Configuration for the inspector.
+ * @param items The list of items to inspect. Up to 100 are allowed per request. All items will be
+ * treated as text/*.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final DeidentifyContentResponse deidentifyContent(
+ DeidentifyConfig deidentifyConfig, InspectConfig inspectConfig, ListSample code: + * + *
+ * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
+ * DeidentifyConfig deidentifyConfig = DeidentifyConfig.newBuilder().build();
+ * InspectConfig inspectConfig = InspectConfig.newBuilder().build();
+ * List<ContentItem> items = new ArrayList<>();
+ * DeidentifyContentRequest request = DeidentifyContentRequest.newBuilder()
+ * .setDeidentifyConfig(deidentifyConfig)
+ * .setInspectConfig(inspectConfig)
+ * .addAllItems(items)
+ * .build();
+ * DeidentifyContentResponse response = dlpServiceClient.deidentifyContent(request);
+ * }
+ *
+ *
+ * @param request The request object containing all of the parameters for the API call.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final DeidentifyContentResponse deidentifyContent(DeidentifyContentRequest request) {
+ return deidentifyContentCallable().call(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD
+ /**
+ * De-identifies potentially sensitive info from a list of strings. This method has limits on
+ * input size and output size.
+ *
+ * Sample code: + * + *
+ * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
+ * DeidentifyConfig deidentifyConfig = DeidentifyConfig.newBuilder().build();
+ * InspectConfig inspectConfig = InspectConfig.newBuilder().build();
+ * List<ContentItem> items = new ArrayList<>();
+ * DeidentifyContentRequest request = DeidentifyContentRequest.newBuilder()
+ * .setDeidentifyConfig(deidentifyConfig)
+ * .setInspectConfig(inspectConfig)
+ * .addAllItems(items)
+ * .build();
+ * ApiFuture<DeidentifyContentResponse> future = dlpServiceClient.deidentifyContentCallable().futureCall(request);
+ * // Do something
+ * DeidentifyContentResponse response = future.get();
+ * }
+ *
+ */
+ public final UnaryCallableSample code: + * + *
+ * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
+ * PrivacyMetric privacyMetric = PrivacyMetric.newBuilder().build();
+ * BigQueryTable sourceTable = BigQueryTable.newBuilder().build();
+ * RiskAnalysisOperationResult response = dlpServiceClient.analyzeDataSourceRiskAsync(privacyMetric, sourceTable).get();
+ * }
+ *
+ *
+ * @param privacyMetric Privacy metric to compute.
+ * @param sourceTable Input dataset to compute metrics over.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final OperationFuture<
+ RiskAnalysisOperationResult, RiskAnalysisOperationMetadata, Operation>
+ analyzeDataSourceRiskAsync(PrivacyMetric privacyMetric, BigQueryTable sourceTable) {
+
+ AnalyzeDataSourceRiskRequest request =
+ AnalyzeDataSourceRiskRequest.newBuilder()
+ .setPrivacyMetric(privacyMetric)
+ .setSourceTable(sourceTable)
+ .build();
+ return analyzeDataSourceRiskAsync(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD
+ /**
+ * Schedules a job to compute risk analysis metrics over content in a Google Cloud Platform
+ * repository.
+ *
+ * Sample code: + * + *
+ * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
+ * PrivacyMetric privacyMetric = PrivacyMetric.newBuilder().build();
+ * BigQueryTable sourceTable = BigQueryTable.newBuilder().build();
+ * AnalyzeDataSourceRiskRequest request = AnalyzeDataSourceRiskRequest.newBuilder()
+ * .setPrivacyMetric(privacyMetric)
+ * .setSourceTable(sourceTable)
+ * .build();
+ * RiskAnalysisOperationResult response = dlpServiceClient.analyzeDataSourceRiskAsync(request).get();
+ * }
+ *
+ *
+ * @param request The request object containing all of the parameters for the API call.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final OperationFuture<
+ RiskAnalysisOperationResult, RiskAnalysisOperationMetadata, Operation>
+ analyzeDataSourceRiskAsync(AnalyzeDataSourceRiskRequest request) {
+ return analyzeDataSourceRiskOperationCallable().futureCall(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD
+ /**
+ * Schedules a job to compute risk analysis metrics over content in a Google Cloud Platform
+ * repository.
+ *
+ * Sample code: + * + *
+ * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
+ * PrivacyMetric privacyMetric = PrivacyMetric.newBuilder().build();
+ * BigQueryTable sourceTable = BigQueryTable.newBuilder().build();
+ * AnalyzeDataSourceRiskRequest request = AnalyzeDataSourceRiskRequest.newBuilder()
+ * .setPrivacyMetric(privacyMetric)
+ * .setSourceTable(sourceTable)
+ * .build();
+ * OperationFuture<Operation> future = dlpServiceClient.analyzeDataSourceRiskOperationCallable().futureCall(request);
+ * // Do something
+ * RiskAnalysisOperationResult response = future.get();
+ * }
+ *
+ */
+ public final OperationCallable<
+ AnalyzeDataSourceRiskRequest, RiskAnalysisOperationResult, RiskAnalysisOperationMetadata,
+ Operation>
+ analyzeDataSourceRiskOperationCallable() {
+ return stub.analyzeDataSourceRiskOperationCallable();
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD
+ /**
+ * Schedules a job to compute risk analysis metrics over content in a Google Cloud Platform
+ * repository.
+ *
+ * Sample code: + * + *
+ * try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
+ * PrivacyMetric privacyMetric = PrivacyMetric.newBuilder().build();
+ * BigQueryTable sourceTable = BigQueryTable.newBuilder().build();
+ * AnalyzeDataSourceRiskRequest request = AnalyzeDataSourceRiskRequest.newBuilder()
+ * .setPrivacyMetric(privacyMetric)
+ * .setSourceTable(sourceTable)
+ * .build();
+ * ApiFuture<Operation> future = dlpServiceClient.analyzeDataSourceRiskCallable().futureCall(request);
+ * // Do something
+ * Operation response = future.get();
+ * }
+ *
+ */
+ public final UnaryCallableThe builder of this class is recursive, so contained classes are themselves builders. When * build() is called, the tree of builders is called to create the complete settings object. For - * example, to set the total timeout of inspectContent to 30 seconds: + * example, to set the total timeout of deidentifyContent to 30 seconds: * *
** DlpServiceSettings.Builder dlpServiceSettingsBuilder = * DlpServiceSettings.newBuilder(); - * dlpServiceSettingsBuilder.inspectContentSettings().getRetrySettingsBuilder() + * dlpServiceSettingsBuilder.deidentifyContentSettings().getRetrySettingsBuilder() * .setTotalTimeout(Duration.ofSeconds(30)); * DlpServiceSettings dlpServiceSettings = dlpServiceSettingsBuilder.build(); *@@ -102,6 +107,12 @@ public class DlpServiceSettings extends ClientSettings { private static String gapicVersion; + private final SimpleCallSettings+ deidentifyContentSettings; + private final OperationCallSettings< + AnalyzeDataSourceRiskRequest, RiskAnalysisOperationResult, RiskAnalysisOperationMetadata, + Operation> + analyzeDataSourceRiskSettings; private final SimpleCallSettings inspectContentSettings; private final SimpleCallSettings @@ -117,6 +128,20 @@ public class DlpServiceSettings extends ClientSettings { private final SimpleCallSettings listRootCategoriesSettings; + /** Returns the object with the settings used for calls to deidentifyContent. */ + public SimpleCallSettings + deidentifyContentSettings() { + return deidentifyContentSettings; + } + + /** Returns the object with the settings used for calls to analyzeDataSourceRisk. */ + public OperationCallSettings< + AnalyzeDataSourceRiskRequest, RiskAnalysisOperationResult, RiskAnalysisOperationMetadata, + Operation> + analyzeDataSourceRiskSettings() { + return analyzeDataSourceRiskSettings; + } + /** Returns the object with the settings used for calls to inspectContent. */ public SimpleCallSettings inspectContentSettings() { @@ -246,6 +271,8 @@ private DlpServiceSettings(Builder settingsBuilder) throws IOException { settingsBuilder.getCredentialsProvider(), settingsBuilder.getClock()); + deidentifyContentSettings = settingsBuilder.deidentifyContentSettings().build(); + analyzeDataSourceRiskSettings = settingsBuilder.analyzeDataSourceRiskSettings().build(); inspectContentSettings = settingsBuilder.inspectContentSettings().build(); redactContentSettings = settingsBuilder.redactContentSettings().build(); createInspectOperationSettings = settingsBuilder.createInspectOperationSettings().build(); @@ -258,6 +285,12 @@ private DlpServiceSettings(Builder settingsBuilder) throws IOException { public static class Builder extends ClientSettings.Builder { private final ImmutableList unaryMethodSettingsBuilders; + private final SimpleCallSettings.Builder + deidentifyContentSettings; + private final OperationCallSettings.Builder< + AnalyzeDataSourceRiskRequest, RiskAnalysisOperationResult, + RiskAnalysisOperationMetadata, Operation> + analyzeDataSourceRiskSettings; private final SimpleCallSettings.Builder inspectContentSettings; private final SimpleCallSettings.Builder @@ -314,6 +347,10 @@ private Builder() { private Builder(ClientContext clientContext) { super(clientContext); + deidentifyContentSettings = SimpleCallSettings.newBuilder(); + + analyzeDataSourceRiskSettings = OperationCallSettings.newBuilder(); + inspectContentSettings = SimpleCallSettings.newBuilder(); redactContentSettings = SimpleCallSettings.newBuilder(); @@ -328,6 +365,7 @@ private Builder(ClientContext clientContext) { unaryMethodSettingsBuilders = ImmutableList. of( + deidentifyContentSettings, inspectContentSettings, redactContentSettings, listInspectFindingsSettings, @@ -346,6 +384,11 @@ private static Builder createDefault() { private static Builder initDefaults(Builder builder) { + builder + .deidentifyContentSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + builder .inspectContentSettings() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")) @@ -370,6 +413,26 @@ private static Builder initDefaults(Builder builder) { .listRootCategoriesSettings() .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + builder + .analyzeDataSourceRiskSettings() + .setInitialCallSettings( + SimpleCallSettings. newBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")) + .build()) + .setResponseClass(RiskAnalysisOperationResult.class) + .setMetadataClass(RiskAnalysisOperationMetadata.class) + .setPollingAlgorithm( + OperationTimedPollAlgorithm.create( + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(20000L)) + .setRetryDelayMultiplier(1.5) + .setMaxRetryDelay(Duration.ofMillis(45000L)) + .setInitialRpcTimeout(Duration.ZERO) // ignored + .setRpcTimeoutMultiplier(1.0) // ignored + .setMaxRpcTimeout(Duration.ZERO) // ignored + .setTotalTimeout(Duration.ofMillis(86400000L)) + .build())); builder .createInspectOperationSettings() .setInitialCallSettings( @@ -397,6 +460,8 @@ private static Builder initDefaults(Builder builder) { private Builder(DlpServiceSettings settings) { super(settings); + deidentifyContentSettings = settings.deidentifyContentSettings.toBuilder(); + analyzeDataSourceRiskSettings = settings.analyzeDataSourceRiskSettings.toBuilder(); inspectContentSettings = settings.inspectContentSettings.toBuilder(); redactContentSettings = settings.redactContentSettings.toBuilder(); createInspectOperationSettings = settings.createInspectOperationSettings.toBuilder(); @@ -406,6 +471,7 @@ private Builder(DlpServiceSettings settings) { unaryMethodSettingsBuilders = ImmutableList. of( + deidentifyContentSettings, inspectContentSettings, redactContentSettings, listInspectFindingsSettings, @@ -442,6 +508,20 @@ public Builder applyToAllUnaryMethods( return this; } + /** Returns the builder for the settings used for calls to deidentifyContent. */ + public SimpleCallSettings.Builder + deidentifyContentSettings() { + return deidentifyContentSettings; + } + + /** Returns the builder for the settings used for calls to analyzeDataSourceRisk. */ + public OperationCallSettings.Builder< + AnalyzeDataSourceRiskRequest, RiskAnalysisOperationResult, + RiskAnalysisOperationMetadata, Operation> + analyzeDataSourceRiskSettings() { + return analyzeDataSourceRiskSettings; + } + /** Returns the builder for the settings used for calls to inspectContent. */ public SimpleCallSettings.Builder inspectContentSettings() { diff --git a/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/package-info.java b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/package-info.java index 3e8f0195f071..b9dd9c19221f 100644 --- a/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/package-info.java +++ b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/package-info.java @@ -31,22 +31,10 @@ * *diff --git a/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/stub/DlpServiceStub.java b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/stub/DlpServiceStub.java index 04ea4402ec09..3dc321f7873c 100644 --- a/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/stub/DlpServiceStub.java +++ b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/stub/DlpServiceStub.java @@ -21,7 +21,10 @@ import com.google.api.gax.rpc.UnaryCallable; import com.google.longrunning.Operation; import com.google.longrunning.stub.OperationsStub; +import com.google.privacy.dlp.v2beta1.AnalyzeDataSourceRiskRequest; import com.google.privacy.dlp.v2beta1.CreateInspectOperationRequest; +import com.google.privacy.dlp.v2beta1.DeidentifyContentRequest; +import com.google.privacy.dlp.v2beta1.DeidentifyContentResponse; import com.google.privacy.dlp.v2beta1.InspectContentRequest; import com.google.privacy.dlp.v2beta1.InspectContentResponse; import com.google.privacy.dlp.v2beta1.InspectOperationMetadata; @@ -34,6 +37,8 @@ import com.google.privacy.dlp.v2beta1.ListRootCategoriesResponse; import com.google.privacy.dlp.v2beta1.RedactContentRequest; import com.google.privacy.dlp.v2beta1.RedactContentResponse; +import com.google.privacy.dlp.v2beta1.RiskAnalysisOperationMetadata; +import com.google.privacy.dlp.v2beta1.RiskAnalysisOperationResult; import javax.annotation.Generated; // AUTO-GENERATED DOCUMENTATION AND CLASS @@ -50,6 +55,23 @@ public OperationsStub getOperationsStub() { throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); } + public UnaryCallable* try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) { - * String name = "EMAIL_ADDRESS"; - * InfoType infoTypesElement = InfoType.newBuilder() - * .setName(name) - * .build(); - * List<InfoType> infoTypes = Arrays.asList(infoTypesElement); - * InspectConfig inspectConfig = InspectConfig.newBuilder() - * .addAllInfoTypes(infoTypes) - * .build(); - * String type = "text/plain"; - * String value = "My email is example{@literal @}example.com."; - * ContentItem itemsElement = ContentItem.newBuilder() - * .setType(type) - * .setValue(value) - * .build(); - * List<ContentItem> items = Arrays.asList(itemsElement); - * InspectContentResponse response = dlpServiceClient.inspectContent(inspectConfig, items); + * DeidentifyConfig deidentifyConfig = DeidentifyConfig.newBuilder().build(); + * InspectConfig inspectConfig = InspectConfig.newBuilder().build(); + * List<ContentItem> items = new ArrayList<>(); + * DeidentifyContentResponse response = dlpServiceClient.deidentifyContent(deidentifyConfig, inspectConfig, items); * } **+ deidentifyContentCallable() { + throw new UnsupportedOperationException("Not implemented: deidentifyContentCallable()"); + } + + public OperationCallable< + AnalyzeDataSourceRiskRequest, RiskAnalysisOperationResult, RiskAnalysisOperationMetadata, + Operation> + analyzeDataSourceRiskOperationCallable() { + throw new UnsupportedOperationException( + "Not implemented: analyzeDataSourceRiskOperationCallable()"); + } + + public UnaryCallable analyzeDataSourceRiskCallable() { + throw new UnsupportedOperationException("Not implemented: analyzeDataSourceRiskCallable()"); + } + public UnaryCallable inspectContentCallable() { throw new UnsupportedOperationException("Not implemented: inspectContentCallable()"); } diff --git a/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/stub/GrpcDlpServiceStub.java b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/stub/GrpcDlpServiceStub.java index 0e1b5cf78925..0b1aafb2275f 100644 --- a/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/stub/GrpcDlpServiceStub.java +++ b/google-cloud-dlp/src/main/java/com/google/cloud/dlp/v2beta1/stub/GrpcDlpServiceStub.java @@ -25,7 +25,10 @@ import com.google.cloud.dlp.v2beta1.DlpServiceSettings; import com.google.longrunning.Operation; import com.google.longrunning.stub.GrpcOperationsStub; +import com.google.privacy.dlp.v2beta1.AnalyzeDataSourceRiskRequest; import com.google.privacy.dlp.v2beta1.CreateInspectOperationRequest; +import com.google.privacy.dlp.v2beta1.DeidentifyContentRequest; +import com.google.privacy.dlp.v2beta1.DeidentifyContentResponse; import com.google.privacy.dlp.v2beta1.InspectContentRequest; import com.google.privacy.dlp.v2beta1.InspectContentResponse; import com.google.privacy.dlp.v2beta1.InspectOperationMetadata; @@ -38,6 +41,8 @@ import com.google.privacy.dlp.v2beta1.ListRootCategoriesResponse; import com.google.privacy.dlp.v2beta1.RedactContentRequest; import com.google.privacy.dlp.v2beta1.RedactContentResponse; +import com.google.privacy.dlp.v2beta1.RiskAnalysisOperationMetadata; +import com.google.privacy.dlp.v2beta1.RiskAnalysisOperationResult; import java.io.IOException; import java.util.concurrent.TimeUnit; import javax.annotation.Generated; @@ -51,6 +56,25 @@ @Generated("by GAPIC v0.0.5") @BetaApi public class GrpcDlpServiceStub extends DlpServiceStub { + private static final UnaryCallable + directDeidentifyContentCallable = + GrpcCallableFactory.createDirectCallable( + io.grpc.MethodDescriptor.create( + io.grpc.MethodDescriptor.MethodType.UNARY, + "google.privacy.dlp.v2beta1.DlpService/DeidentifyContent", + io.grpc.protobuf.ProtoUtils.marshaller( + DeidentifyContentRequest.getDefaultInstance()), + io.grpc.protobuf.ProtoUtils.marshaller( + DeidentifyContentResponse.getDefaultInstance()))); + private static final UnaryCallable + directAnalyzeDataSourceRiskCallable = + GrpcCallableFactory.createDirectCallable( + io.grpc.MethodDescriptor.create( + io.grpc.MethodDescriptor.MethodType.UNARY, + "google.privacy.dlp.v2beta1.DlpService/AnalyzeDataSourceRisk", + io.grpc.protobuf.ProtoUtils.marshaller( + AnalyzeDataSourceRiskRequest.getDefaultInstance()), + io.grpc.protobuf.ProtoUtils.marshaller(Operation.getDefaultInstance()))); private static final UnaryCallable directInspectContentCallable = GrpcCallableFactory.createDirectCallable( @@ -112,6 +136,14 @@ public class GrpcDlpServiceStub extends DlpServiceStub { private final BackgroundResource backgroundResources; private final GrpcOperationsStub operationsStub; + private final UnaryCallable + deidentifyContentCallable; + private final UnaryCallable + analyzeDataSourceRiskCallable; + private final OperationCallable< + AnalyzeDataSourceRiskRequest, RiskAnalysisOperationResult, RiskAnalysisOperationMetadata, + Operation> + analyzeDataSourceRiskOperationCallable; private final UnaryCallable inspectContentCallable; private final UnaryCallable redactContentCallable; private final UnaryCallable @@ -143,6 +175,20 @@ protected GrpcDlpServiceStub(DlpServiceSettings settings, ClientContext clientCo throws IOException { this.operationsStub = GrpcOperationsStub.create(clientContext); + this.deidentifyContentCallable = + GrpcCallableFactory.create( + directDeidentifyContentCallable, settings.deidentifyContentSettings(), clientContext); + this.analyzeDataSourceRiskCallable = + GrpcCallableFactory.create( + directAnalyzeDataSourceRiskCallable, + settings.analyzeDataSourceRiskSettings().getInitialCallSettings(), + clientContext); + this.analyzeDataSourceRiskOperationCallable = + GrpcCallableFactory.create( + directAnalyzeDataSourceRiskCallable, + settings.analyzeDataSourceRiskSettings(), + clientContext, + this.operationsStub); this.inspectContentCallable = GrpcCallableFactory.create( directInspectContentCallable, settings.inspectContentSettings(), clientContext); @@ -179,6 +225,22 @@ public GrpcOperationsStub getOperationsStub() { return operationsStub; } + public UnaryCallable + deidentifyContentCallable() { + return deidentifyContentCallable; + } + + public OperationCallable< + AnalyzeDataSourceRiskRequest, RiskAnalysisOperationResult, RiskAnalysisOperationMetadata, + Operation> + analyzeDataSourceRiskOperationCallable() { + return analyzeDataSourceRiskOperationCallable; + } + + public UnaryCallable analyzeDataSourceRiskCallable() { + return analyzeDataSourceRiskCallable; + } + public UnaryCallable inspectContentCallable() { return inspectContentCallable; } diff --git a/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2beta1/DlpServiceClientTest.java b/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2beta1/DlpServiceClientTest.java index 26ee21b51d08..958a931136d2 100644 --- a/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2beta1/DlpServiceClientTest.java +++ b/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2beta1/DlpServiceClientTest.java @@ -22,10 +22,15 @@ import com.google.api.gax.grpc.testing.MockServiceHelper; import com.google.api.gax.rpc.InvalidArgumentException; import com.google.longrunning.Operation; +import com.google.privacy.dlp.v2beta1.AnalyzeDataSourceRiskRequest; +import com.google.privacy.dlp.v2beta1.BigQueryTable; import com.google.privacy.dlp.v2beta1.CloudStorageOptions; import com.google.privacy.dlp.v2beta1.CloudStorageOptions.FileSet; import com.google.privacy.dlp.v2beta1.ContentItem; import com.google.privacy.dlp.v2beta1.CreateInspectOperationRequest; +import com.google.privacy.dlp.v2beta1.DeidentifyConfig; +import com.google.privacy.dlp.v2beta1.DeidentifyContentRequest; +import com.google.privacy.dlp.v2beta1.DeidentifyContentResponse; import com.google.privacy.dlp.v2beta1.InfoType; import com.google.privacy.dlp.v2beta1.InspectConfig; import com.google.privacy.dlp.v2beta1.InspectContentRequest; @@ -38,16 +43,19 @@ import com.google.privacy.dlp.v2beta1.ListRootCategoriesRequest; import com.google.privacy.dlp.v2beta1.ListRootCategoriesResponse; import com.google.privacy.dlp.v2beta1.OutputStorageConfig; +import com.google.privacy.dlp.v2beta1.PrivacyMetric; import com.google.privacy.dlp.v2beta1.RedactContentRequest; import com.google.privacy.dlp.v2beta1.RedactContentRequest.ReplaceConfig; import com.google.privacy.dlp.v2beta1.RedactContentResponse; import com.google.privacy.dlp.v2beta1.ResultName; +import com.google.privacy.dlp.v2beta1.RiskAnalysisOperationResult; import com.google.privacy.dlp.v2beta1.StorageConfig; import com.google.protobuf.Any; import com.google.protobuf.GeneratedMessageV3; import io.grpc.Status; import io.grpc.StatusRuntimeException; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.ExecutionException; @@ -96,6 +104,96 @@ public void tearDown() throws Exception { client.close(); } + @Test + @SuppressWarnings("all") + public void deidentifyContentTest() { + DeidentifyContentResponse expectedResponse = DeidentifyContentResponse.newBuilder().build(); + mockDlpService.addResponse(expectedResponse); + + DeidentifyConfig deidentifyConfig = DeidentifyConfig.newBuilder().build(); + InspectConfig inspectConfig = InspectConfig.newBuilder().build(); + List items = new ArrayList<>(); + + DeidentifyContentResponse actualResponse = + client.deidentifyContent(deidentifyConfig, inspectConfig, items); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockDlpService.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeidentifyContentRequest actualRequest = (DeidentifyContentRequest) actualRequests.get(0); + + Assert.assertEquals(deidentifyConfig, actualRequest.getDeidentifyConfig()); + Assert.assertEquals(inspectConfig, actualRequest.getInspectConfig()); + Assert.assertEquals(items, actualRequest.getItemsList()); + } + + @Test + @SuppressWarnings("all") + public void deidentifyContentExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockDlpService.addException(exception); + + try { + DeidentifyConfig deidentifyConfig = DeidentifyConfig.newBuilder().build(); + InspectConfig inspectConfig = InspectConfig.newBuilder().build(); + List items = new ArrayList<>(); + + client.deidentifyContent(deidentifyConfig, inspectConfig, items); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + + @Test + @SuppressWarnings("all") + public void analyzeDataSourceRiskTest() throws Exception { + RiskAnalysisOperationResult expectedResponse = RiskAnalysisOperationResult.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("analyzeDataSourceRiskTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockDlpService.addResponse(resultOperation); + + PrivacyMetric privacyMetric = PrivacyMetric.newBuilder().build(); + BigQueryTable sourceTable = BigQueryTable.newBuilder().build(); + + RiskAnalysisOperationResult actualResponse = + client.analyzeDataSourceRiskAsync(privacyMetric, sourceTable).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockDlpService.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + AnalyzeDataSourceRiskRequest actualRequest = + (AnalyzeDataSourceRiskRequest) actualRequests.get(0); + + Assert.assertEquals(privacyMetric, actualRequest.getPrivacyMetric()); + Assert.assertEquals(sourceTable, actualRequest.getSourceTable()); + } + + @Test + @SuppressWarnings("all") + public void analyzeDataSourceRiskExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockDlpService.addException(exception); + + try { + PrivacyMetric privacyMetric = PrivacyMetric.newBuilder().build(); + BigQueryTable sourceTable = BigQueryTable.newBuilder().build(); + + client.analyzeDataSourceRiskAsync(privacyMetric, sourceTable).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); + InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); + Assert.assertEquals( + Status.INVALID_ARGUMENT.getCode(), + ((GrpcStatusCode) apiException.getStatusCode()).getCode()); + } + } + @Test @SuppressWarnings("all") public void inspectContentTest() { diff --git a/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2beta1/MockDlpServiceImpl.java b/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2beta1/MockDlpServiceImpl.java index b1fba1a185c1..4598c2a68537 100644 --- a/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2beta1/MockDlpServiceImpl.java +++ b/google-cloud-dlp/src/test/java/com/google/cloud/dlp/v2beta1/MockDlpServiceImpl.java @@ -16,7 +16,10 @@ package com.google.cloud.dlp.v2beta1; import com.google.longrunning.Operation; +import com.google.privacy.dlp.v2beta1.AnalyzeDataSourceRiskRequest; import com.google.privacy.dlp.v2beta1.CreateInspectOperationRequest; +import com.google.privacy.dlp.v2beta1.DeidentifyContentRequest; +import com.google.privacy.dlp.v2beta1.DeidentifyContentResponse; import com.google.privacy.dlp.v2beta1.DlpServiceGrpc.DlpServiceImplBase; import com.google.privacy.dlp.v2beta1.InspectContentRequest; import com.google.privacy.dlp.v2beta1.InspectContentResponse; @@ -96,6 +99,22 @@ public void redactContent( } } + @Override + public void deidentifyContent( + DeidentifyContentRequest request, + StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof DeidentifyContentResponse) { + requests.add(request); + responseObserver.onNext((DeidentifyContentResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + @Override public void createInspectOperation( CreateInspectOperationRequest request, StreamObserver responseObserver) { @@ -111,6 +130,21 @@ public void createInspectOperation( } } + @Override + public void analyzeDataSourceRisk( + AnalyzeDataSourceRiskRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof Operation) { + requests.add(request); + responseObserver.onNext((Operation) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + @Override public void listInspectFindings( ListInspectFindingsRequest request, diff --git a/pom.xml b/pom.xml index 651b9d144056..8dae81b1a957 100644 --- a/pom.xml +++ b/pom.xml @@ -142,7 +142,7 @@ 1.1.0 1.9.0 0.26.0 -0.1.20 +0.1.21 0.8.0 1.6.1 20.0