Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [webrisk] add SubmitUri endpoint #9443

Merged
merged 2 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions java-webrisk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ If you are using Maven with [BOM][libraries-bom], add this to your pom.xml file:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>26.11.0</version>
<version>26.15.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -195,7 +195,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/google-cloud-java/java11.html
[stability-image]: https://img.shields.io/badge/stability-stable-green
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-webrisk.svg
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-webrisk/2.13.0
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-webrisk/2.16.0
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@

package com.google.cloud.webrisk.v1;

import com.google.api.core.BetaApi;
import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.httpjson.longrunning.OperationsClient;
import com.google.api.gax.longrunning.OperationFuture;
import com.google.api.gax.rpc.OperationCallable;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.webrisk.v1.stub.WebRiskServiceStub;
import com.google.cloud.webrisk.v1.stub.WebRiskServiceStubSettings;
import com.google.longrunning.Operation;
import com.google.protobuf.ByteString;
import com.google.webrisk.v1.ComputeThreatListDiffRequest;
import com.google.webrisk.v1.ComputeThreatListDiffResponse;
Expand All @@ -30,6 +35,8 @@
import com.google.webrisk.v1.SearchUrisRequest;
import com.google.webrisk.v1.SearchUrisResponse;
import com.google.webrisk.v1.Submission;
import com.google.webrisk.v1.SubmitUriMetadata;
import com.google.webrisk.v1.SubmitUriRequest;
import com.google.webrisk.v1.ThreatType;
import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -134,6 +141,8 @@
public class WebRiskServiceClient implements BackgroundResource {
private final WebRiskServiceSettings settings;
private final WebRiskServiceStub stub;
private final OperationsClient httpJsonOperationsClient;
private final com.google.longrunning.OperationsClient operationsClient;

/** Constructs an instance of WebRiskServiceClient with default settings. */
public static final WebRiskServiceClient create() throws IOException {
Expand Down Expand Up @@ -165,11 +174,17 @@ public static final WebRiskServiceClient create(WebRiskServiceStub stub) {
protected WebRiskServiceClient(WebRiskServiceSettings settings) throws IOException {
this.settings = settings;
this.stub = ((WebRiskServiceStubSettings) settings.getStubSettings()).createStub();
this.operationsClient =
com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
}

protected WebRiskServiceClient(WebRiskServiceStub stub) {
this.settings = null;
this.stub = stub;
this.operationsClient =
com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
}

public final WebRiskServiceSettings getSettings() {
Expand All @@ -180,6 +195,23 @@ public WebRiskServiceStub getStub() {
return stub;
}

/**
* Returns the OperationsClient that can be used to query the status of a long-running operation
* returned by another API method call.
*/
public final com.google.longrunning.OperationsClient getOperationsClient() {
return operationsClient;
}

/**
* Returns the OperationsClient that can be used to query the status of a long-running operation
* returned by another API method call.
*/
@BetaApi
public final OperationsClient getHttpJsonOperationsClient() {
return httpJsonOperationsClient;
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Gets the most recent threat list diffs. These diffs should be applied to a local database of
Expand Down Expand Up @@ -640,6 +672,121 @@ public final UnaryCallable<CreateSubmissionRequest, Submission> createSubmission
return stub.createSubmissionCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Submits a URI suspected of containing malicious content to be reviewed. Returns a
* google.longrunning.Operation which, once the review is complete, is updated with its result.
* You can use the [Pub/Sub API] (https://cloud.google.com/pubsub) to receive notifications for
* the returned Operation. If the result verifies the existence of malicious content, the site
* will be added to the [Google's Social Engineering lists]
* (https://support.google.com/webmasters/answer/6350487/) in order to protect users that could
* get exposed to this threat in the future. Only allowlisted projects can use this method during
* Early Access. Please reach out to Sales or your customer engineer to obtain access.
*
* <p>Sample code:
*
* <pre>{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (WebRiskServiceClient webRiskServiceClient = WebRiskServiceClient.create()) {
* SubmitUriRequest request =
* SubmitUriRequest.newBuilder()
* .setParent(ProjectName.of("[PROJECT]").toString())
* .setSubmission(Submission.newBuilder().build())
* .setThreatInfo(ThreatInfo.newBuilder().build())
* .setThreatDiscovery(ThreatDiscovery.newBuilder().build())
* .build();
* Submission response = webRiskServiceClient.submitUriAsync(request).get();
* }
* }</pre>
*
* @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<Submission, SubmitUriMetadata> submitUriAsync(
SubmitUriRequest request) {
return submitUriOperationCallable().futureCall(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Submits a URI suspected of containing malicious content to be reviewed. Returns a
* google.longrunning.Operation which, once the review is complete, is updated with its result.
* You can use the [Pub/Sub API] (https://cloud.google.com/pubsub) to receive notifications for
* the returned Operation. If the result verifies the existence of malicious content, the site
* will be added to the [Google's Social Engineering lists]
* (https://support.google.com/webmasters/answer/6350487/) in order to protect users that could
* get exposed to this threat in the future. Only allowlisted projects can use this method during
* Early Access. Please reach out to Sales or your customer engineer to obtain access.
*
* <p>Sample code:
*
* <pre>{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (WebRiskServiceClient webRiskServiceClient = WebRiskServiceClient.create()) {
* SubmitUriRequest request =
* SubmitUriRequest.newBuilder()
* .setParent(ProjectName.of("[PROJECT]").toString())
* .setSubmission(Submission.newBuilder().build())
* .setThreatInfo(ThreatInfo.newBuilder().build())
* .setThreatDiscovery(ThreatDiscovery.newBuilder().build())
* .build();
* OperationFuture<Submission, SubmitUriMetadata> future =
* webRiskServiceClient.submitUriOperationCallable().futureCall(request);
* // Do something.
* Submission response = future.get();
* }
* }</pre>
*/
public final OperationCallable<SubmitUriRequest, Submission, SubmitUriMetadata>
submitUriOperationCallable() {
return stub.submitUriOperationCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Submits a URI suspected of containing malicious content to be reviewed. Returns a
* google.longrunning.Operation which, once the review is complete, is updated with its result.
* You can use the [Pub/Sub API] (https://cloud.google.com/pubsub) to receive notifications for
* the returned Operation. If the result verifies the existence of malicious content, the site
* will be added to the [Google's Social Engineering lists]
* (https://support.google.com/webmasters/answer/6350487/) in order to protect users that could
* get exposed to this threat in the future. Only allowlisted projects can use this method during
* Early Access. Please reach out to Sales or your customer engineer to obtain access.
*
* <p>Sample code:
*
* <pre>{@code
* // This snippet has been automatically generated and should be regarded as a code template only.
* // It will require modifications to work:
* // - It may require correct/in-range values for request initialization.
* // - It may require specifying regional endpoints when creating the service client as shown in
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (WebRiskServiceClient webRiskServiceClient = WebRiskServiceClient.create()) {
* SubmitUriRequest request =
* SubmitUriRequest.newBuilder()
* .setParent(ProjectName.of("[PROJECT]").toString())
* .setSubmission(Submission.newBuilder().build())
* .setThreatInfo(ThreatInfo.newBuilder().build())
* .setThreatDiscovery(ThreatDiscovery.newBuilder().build())
* .build();
* ApiFuture<Operation> future = webRiskServiceClient.submitUriCallable().futureCall(request);
* // Do something.
* Operation response = future.get();
* }
* }</pre>
*/
public final UnaryCallable<SubmitUriRequest, Operation> submitUriCallable() {
return stub.submitUriCallable();
}

@Override
public final void close() {
stub.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import com.google.api.gax.rpc.ApiClientHeaderProvider;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.ClientSettings;
import com.google.api.gax.rpc.OperationCallSettings;
import com.google.api.gax.rpc.TransportChannelProvider;
import com.google.api.gax.rpc.UnaryCallSettings;
import com.google.cloud.webrisk.v1.stub.WebRiskServiceStubSettings;
import com.google.longrunning.Operation;
import com.google.webrisk.v1.ComputeThreatListDiffRequest;
import com.google.webrisk.v1.ComputeThreatListDiffResponse;
import com.google.webrisk.v1.CreateSubmissionRequest;
Expand All @@ -36,6 +38,8 @@
import com.google.webrisk.v1.SearchUrisRequest;
import com.google.webrisk.v1.SearchUrisResponse;
import com.google.webrisk.v1.Submission;
import com.google.webrisk.v1.SubmitUriMetadata;
import com.google.webrisk.v1.SubmitUriRequest;
import java.io.IOException;
import java.util.List;
import javax.annotation.Generated;
Expand Down Expand Up @@ -101,6 +105,17 @@ public UnaryCallSettings<CreateSubmissionRequest, Submission> createSubmissionSe
return ((WebRiskServiceStubSettings) getStubSettings()).createSubmissionSettings();
}

/** Returns the object with the settings used for calls to submitUri. */
public UnaryCallSettings<SubmitUriRequest, Operation> submitUriSettings() {
return ((WebRiskServiceStubSettings) getStubSettings()).submitUriSettings();
}

/** Returns the object with the settings used for calls to submitUri. */
public OperationCallSettings<SubmitUriRequest, Submission, SubmitUriMetadata>
submitUriOperationSettings() {
return ((WebRiskServiceStubSettings) getStubSettings()).submitUriOperationSettings();
}

public static final WebRiskServiceSettings create(WebRiskServiceStubSettings stub)
throws IOException {
return new WebRiskServiceSettings.Builder(stub.toBuilder()).build();
Expand Down Expand Up @@ -239,6 +254,17 @@ public UnaryCallSettings.Builder<SearchUrisRequest, SearchUrisResponse> searchUr
return getStubSettingsBuilder().createSubmissionSettings();
}

/** Returns the builder for the settings used for calls to submitUri. */
public UnaryCallSettings.Builder<SubmitUriRequest, Operation> submitUriSettings() {
return getStubSettingsBuilder().submitUriSettings();
}

/** Returns the builder for the settings used for calls to submitUri. */
public OperationCallSettings.Builder<SubmitUriRequest, Submission, SubmitUriMetadata>
submitUriOperationSettings() {
return getStubSettingsBuilder().submitUriOperationSettings();
}

@Override
public WebRiskServiceSettings build() throws IOException {
return new WebRiskServiceSettings(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
},
"SearchUris": {
"methods": ["searchUris", "searchUris", "searchUrisCallable"]
},
"SubmitUri": {
"methods": ["submitUriAsync", "submitUriOperationCallable", "submitUriCallable"]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import com.google.api.gax.grpc.GrpcCallSettings;
import com.google.api.gax.grpc.GrpcStubCallableFactory;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.OperationCallable;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.common.collect.ImmutableMap;
import com.google.longrunning.Operation;
import com.google.longrunning.stub.GrpcOperationsStub;
import com.google.webrisk.v1.ComputeThreatListDiffRequest;
import com.google.webrisk.v1.ComputeThreatListDiffResponse;
Expand All @@ -32,6 +34,8 @@
import com.google.webrisk.v1.SearchUrisRequest;
import com.google.webrisk.v1.SearchUrisResponse;
import com.google.webrisk.v1.Submission;
import com.google.webrisk.v1.SubmitUriMetadata;
import com.google.webrisk.v1.SubmitUriRequest;
import io.grpc.MethodDescriptor;
import io.grpc.protobuf.ProtoUtils;
import java.io.IOException;
Expand Down Expand Up @@ -86,11 +90,22 @@ public class GrpcWebRiskServiceStub extends WebRiskServiceStub {
.setResponseMarshaller(ProtoUtils.marshaller(Submission.getDefaultInstance()))
.build();

private static final MethodDescriptor<SubmitUriRequest, Operation> submitUriMethodDescriptor =
MethodDescriptor.<SubmitUriRequest, Operation>newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("google.cloud.webrisk.v1.WebRiskService/SubmitUri")
.setRequestMarshaller(ProtoUtils.marshaller(SubmitUriRequest.getDefaultInstance()))
.setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance()))
.build();

private final UnaryCallable<ComputeThreatListDiffRequest, ComputeThreatListDiffResponse>
computeThreatListDiffCallable;
private final UnaryCallable<SearchUrisRequest, SearchUrisResponse> searchUrisCallable;
private final UnaryCallable<SearchHashesRequest, SearchHashesResponse> searchHashesCallable;
private final UnaryCallable<CreateSubmissionRequest, Submission> createSubmissionCallable;
private final UnaryCallable<SubmitUriRequest, Operation> submitUriCallable;
private final OperationCallable<SubmitUriRequest, Submission, SubmitUriMetadata>
submitUriOperationCallable;

private final BackgroundResource backgroundResources;
private final GrpcOperationsStub operationsStub;
Expand Down Expand Up @@ -160,6 +175,16 @@ protected GrpcWebRiskServiceStub(
return params.build();
})
.build();
GrpcCallSettings<SubmitUriRequest, Operation> submitUriTransportSettings =
GrpcCallSettings.<SubmitUriRequest, Operation>newBuilder()
.setMethodDescriptor(submitUriMethodDescriptor)
.setParamsExtractor(
request -> {
ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
params.put("parent", String.valueOf(request.getParent()));
return params.build();
})
.build();

this.computeThreatListDiffCallable =
callableFactory.createUnaryCallable(
Expand All @@ -175,6 +200,15 @@ protected GrpcWebRiskServiceStub(
this.createSubmissionCallable =
callableFactory.createUnaryCallable(
createSubmissionTransportSettings, settings.createSubmissionSettings(), clientContext);
this.submitUriCallable =
callableFactory.createUnaryCallable(
submitUriTransportSettings, settings.submitUriSettings(), clientContext);
this.submitUriOperationCallable =
callableFactory.createOperationCallable(
submitUriTransportSettings,
settings.submitUriOperationSettings(),
clientContext,
operationsStub);

this.backgroundResources =
new BackgroundResourceAggregation(clientContext.getBackgroundResources());
Expand Down Expand Up @@ -205,6 +239,17 @@ public UnaryCallable<CreateSubmissionRequest, Submission> createSubmissionCallab
return createSubmissionCallable;
}

@Override
public UnaryCallable<SubmitUriRequest, Operation> submitUriCallable() {
return submitUriCallable;
}

@Override
public OperationCallable<SubmitUriRequest, Submission, SubmitUriMetadata>
submitUriOperationCallable() {
return submitUriOperationCallable;
}

@Override
public final void close() {
try {
Expand Down
Loading