Skip to content

Commit a6545c5

Browse files
feat: [google-cloud-webrisk] A new method_signature parent,submission is added to method SubmitUri in service WebRiskService (#13731)
- [ ] Regenerate this pull request now. BEGIN_COMMIT_OVERRIDE feat: A new method_signature `parent,submission` is added to method `SubmitUri` in service `WebRiskService` docs: A comment for message `ThreatInfo` is changed docs: A comment for message `SubmitUriMetadata` is changed END_COMMIT_OVERRIDE docs: A comment for message `ThreatInfo` is changed docs: A comment for message `SubmitUriMetadata` is changed PiperOrigin-RevId: 743172371 Source-Link: googleapis/googleapis@49235a9 Source-Link: googleapis/googleapis-gen@f01f471 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXdlYnJpc2svLk93bEJvdC55YW1sIiwiaCI6ImYwMWY0NzE5MTEzOGIxOWI5Njk1N2EyYTlkYTA1MjI0ZTg4YzdhYjQifQ== --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent c53d2e9 commit a6545c5

File tree

5 files changed

+238
-5
lines changed

5 files changed

+238
-5
lines changed

packages/google-cloud-webrisk/google/cloud/webrisk_v1/services/web_risk_service/async_client.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,8 @@ async def submit_uri(
812812
self,
813813
request: Optional[Union[webrisk.SubmitUriRequest, dict]] = None,
814814
*,
815+
parent: Optional[str] = None,
816+
submission: Optional[webrisk.Submission] = None,
815817
retry: OptionalRetry = gapic_v1.method.DEFAULT,
816818
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
817819
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
@@ -867,6 +869,21 @@ async def sample_submit_uri():
867869
request (Optional[Union[google.cloud.webrisk_v1.types.SubmitUriRequest, dict]]):
868870
The request object. Request to send a potentially
869871
malicious URI to WebRisk.
872+
parent (:class:`str`):
873+
Required. The name of the project that is making the
874+
submission. This string is in the format
875+
"projects/{project_number}".
876+
877+
This corresponds to the ``parent`` field
878+
on the ``request`` instance; if ``request`` is provided, this
879+
should not be set.
880+
submission (:class:`google.cloud.webrisk_v1.types.Submission`):
881+
Required. The submission that
882+
contains the URI to be scanned.
883+
884+
This corresponds to the ``submission`` field
885+
on the ``request`` instance; if ``request`` is provided, this
886+
should not be set.
870887
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
871888
should be retried.
872889
timeout (float): The timeout for this request.
@@ -885,11 +902,30 @@ async def sample_submit_uri():
885902
886903
"""
887904
# Create or coerce a protobuf request object.
905+
# - Quick check: If we got a request object, we should *not* have
906+
# gotten any keyword arguments that map to the request.
907+
flattened_params = [parent, submission]
908+
has_flattened_params = (
909+
len([param for param in flattened_params if param is not None]) > 0
910+
)
911+
if request is not None and has_flattened_params:
912+
raise ValueError(
913+
"If the `request` argument is set, then none of "
914+
"the individual field arguments should be set."
915+
)
916+
888917
# - Use the request object if provided (there's no risk of modifying the input as
889918
# there are no flattened fields), or create one.
890919
if not isinstance(request, webrisk.SubmitUriRequest):
891920
request = webrisk.SubmitUriRequest(request)
892921

922+
# If we have keyword arguments corresponding to fields on the
923+
# request, apply these.
924+
if parent is not None:
925+
request.parent = parent
926+
if submission is not None:
927+
request.submission = submission
928+
893929
# Wrap the RPC method; this adds retry and timeout information,
894930
# and friendly error handling.
895931
rpc = self._client._transport._wrapped_methods[

packages/google-cloud-webrisk/google/cloud/webrisk_v1/services/web_risk_service/client.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,8 @@ def submit_uri(
12031203
self,
12041204
request: Optional[Union[webrisk.SubmitUriRequest, dict]] = None,
12051205
*,
1206+
parent: Optional[str] = None,
1207+
submission: Optional[webrisk.Submission] = None,
12061208
retry: OptionalRetry = gapic_v1.method.DEFAULT,
12071209
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
12081210
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
@@ -1258,6 +1260,21 @@ def sample_submit_uri():
12581260
request (Union[google.cloud.webrisk_v1.types.SubmitUriRequest, dict]):
12591261
The request object. Request to send a potentially
12601262
malicious URI to WebRisk.
1263+
parent (str):
1264+
Required. The name of the project that is making the
1265+
submission. This string is in the format
1266+
"projects/{project_number}".
1267+
1268+
This corresponds to the ``parent`` field
1269+
on the ``request`` instance; if ``request`` is provided, this
1270+
should not be set.
1271+
submission (google.cloud.webrisk_v1.types.Submission):
1272+
Required. The submission that
1273+
contains the URI to be scanned.
1274+
1275+
This corresponds to the ``submission`` field
1276+
on the ``request`` instance; if ``request`` is provided, this
1277+
should not be set.
12611278
retry (google.api_core.retry.Retry): Designation of what errors, if any,
12621279
should be retried.
12631280
timeout (float): The timeout for this request.
@@ -1276,10 +1293,28 @@ def sample_submit_uri():
12761293
12771294
"""
12781295
# Create or coerce a protobuf request object.
1296+
# - Quick check: If we got a request object, we should *not* have
1297+
# gotten any keyword arguments that map to the request.
1298+
flattened_params = [parent, submission]
1299+
has_flattened_params = (
1300+
len([param for param in flattened_params if param is not None]) > 0
1301+
)
1302+
if request is not None and has_flattened_params:
1303+
raise ValueError(
1304+
"If the `request` argument is set, then none of "
1305+
"the individual field arguments should be set."
1306+
)
1307+
12791308
# - Use the request object if provided (there's no risk of modifying the input as
12801309
# there are no flattened fields), or create one.
12811310
if not isinstance(request, webrisk.SubmitUriRequest):
12821311
request = webrisk.SubmitUriRequest(request)
1312+
# If we have keyword arguments corresponding to fields on the
1313+
# request, apply these.
1314+
if parent is not None:
1315+
request.parent = parent
1316+
if submission is not None:
1317+
request.submission = submission
12831318

12841319
# Wrap the RPC method; this adds retry and timeout information,
12851320
# and friendly error handling.

packages/google-cloud-webrisk/google/cloud/webrisk_v1/types/webrisk.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,8 @@ class Submission(proto.Message):
578578

579579

580580
class ThreatInfo(proto.Message):
581-
r"""Context about the submission including the type of abuse found on
582-
the URI and supporting details. option
583-
(google.api.message_visibility).restriction = "TRUSTED_TESTER";
581+
r"""Context about the submission including the type of abuse
582+
found on the URI and supporting details.
584583
585584
Attributes:
586585
abuse_type (google.cloud.webrisk_v1.types.ThreatInfo.AbuseType):
@@ -835,8 +834,7 @@ class SubmitUriRequest(proto.Message):
835834

836835

837836
class SubmitUriMetadata(proto.Message):
838-
r"""Metadata for the Submit URI long-running operation. option
839-
(google.api.message_visibility).restriction = "TRUSTED_TESTER";
837+
r"""Metadata for the Submit URI long-running operation.
840838
841839
Attributes:
842840
state (google.cloud.webrisk_v1.types.SubmitUriMetadata.State):

packages/google-cloud-webrisk/samples/generated_samples/snippet_metadata_google.cloud.webrisk.v1.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,14 @@
717717
"name": "request",
718718
"type": "google.cloud.webrisk_v1.types.SubmitUriRequest"
719719
},
720+
{
721+
"name": "parent",
722+
"type": "str"
723+
},
724+
{
725+
"name": "submission",
726+
"type": "google.cloud.webrisk_v1.types.Submission"
727+
},
720728
{
721729
"name": "retry",
722730
"type": "google.api_core.retry.Retry"
@@ -793,6 +801,14 @@
793801
"name": "request",
794802
"type": "google.cloud.webrisk_v1.types.SubmitUriRequest"
795803
},
804+
{
805+
"name": "parent",
806+
"type": "str"
807+
},
808+
{
809+
"name": "submission",
810+
"type": "google.cloud.webrisk_v1.types.Submission"
811+
},
796812
{
797813
"name": "retry",
798814
"type": "google.api_core.retry.Retry"

packages/google-cloud-webrisk/tests/unit/gapic/webrisk_v1/test_web_risk_service.py

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2559,6 +2559,98 @@ async def test_submit_uri_field_headers_async():
25592559
) in kw["metadata"]
25602560

25612561

2562+
def test_submit_uri_flattened():
2563+
client = WebRiskServiceClient(
2564+
credentials=ga_credentials.AnonymousCredentials(),
2565+
)
2566+
2567+
# Mock the actual call within the gRPC stub, and fake the request.
2568+
with mock.patch.object(type(client.transport.submit_uri), "__call__") as call:
2569+
# Designate an appropriate return value for the call.
2570+
call.return_value = operations_pb2.Operation(name="operations/op")
2571+
# Call the method with a truthy value for each flattened field,
2572+
# using the keyword arguments to the method.
2573+
client.submit_uri(
2574+
parent="parent_value",
2575+
submission=webrisk.Submission(uri="uri_value"),
2576+
)
2577+
2578+
# Establish that the underlying call was made with the expected
2579+
# request object values.
2580+
assert len(call.mock_calls) == 1
2581+
_, args, _ = call.mock_calls[0]
2582+
arg = args[0].parent
2583+
mock_val = "parent_value"
2584+
assert arg == mock_val
2585+
arg = args[0].submission
2586+
mock_val = webrisk.Submission(uri="uri_value")
2587+
assert arg == mock_val
2588+
2589+
2590+
def test_submit_uri_flattened_error():
2591+
client = WebRiskServiceClient(
2592+
credentials=ga_credentials.AnonymousCredentials(),
2593+
)
2594+
2595+
# Attempting to call a method with both a request object and flattened
2596+
# fields is an error.
2597+
with pytest.raises(ValueError):
2598+
client.submit_uri(
2599+
webrisk.SubmitUriRequest(),
2600+
parent="parent_value",
2601+
submission=webrisk.Submission(uri="uri_value"),
2602+
)
2603+
2604+
2605+
@pytest.mark.asyncio
2606+
async def test_submit_uri_flattened_async():
2607+
client = WebRiskServiceAsyncClient(
2608+
credentials=async_anonymous_credentials(),
2609+
)
2610+
2611+
# Mock the actual call within the gRPC stub, and fake the request.
2612+
with mock.patch.object(type(client.transport.submit_uri), "__call__") as call:
2613+
# Designate an appropriate return value for the call.
2614+
call.return_value = operations_pb2.Operation(name="operations/op")
2615+
2616+
call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
2617+
operations_pb2.Operation(name="operations/spam")
2618+
)
2619+
# Call the method with a truthy value for each flattened field,
2620+
# using the keyword arguments to the method.
2621+
response = await client.submit_uri(
2622+
parent="parent_value",
2623+
submission=webrisk.Submission(uri="uri_value"),
2624+
)
2625+
2626+
# Establish that the underlying call was made with the expected
2627+
# request object values.
2628+
assert len(call.mock_calls)
2629+
_, args, _ = call.mock_calls[0]
2630+
arg = args[0].parent
2631+
mock_val = "parent_value"
2632+
assert arg == mock_val
2633+
arg = args[0].submission
2634+
mock_val = webrisk.Submission(uri="uri_value")
2635+
assert arg == mock_val
2636+
2637+
2638+
@pytest.mark.asyncio
2639+
async def test_submit_uri_flattened_error_async():
2640+
client = WebRiskServiceAsyncClient(
2641+
credentials=async_anonymous_credentials(),
2642+
)
2643+
2644+
# Attempting to call a method with both a request object and flattened
2645+
# fields is an error.
2646+
with pytest.raises(ValueError):
2647+
await client.submit_uri(
2648+
webrisk.SubmitUriRequest(),
2649+
parent="parent_value",
2650+
submission=webrisk.Submission(uri="uri_value"),
2651+
)
2652+
2653+
25622654
def test_compute_threat_list_diff_rest_use_cached_wrapped_rpc():
25632655
# Clients should use _prep_wrapped_messages to create cached wrapped rpcs,
25642656
# instead of constructing them on each call
@@ -3473,6 +3565,62 @@ def test_submit_uri_rest_unset_required_fields():
34733565
)
34743566

34753567

3568+
def test_submit_uri_rest_flattened():
3569+
client = WebRiskServiceClient(
3570+
credentials=ga_credentials.AnonymousCredentials(),
3571+
transport="rest",
3572+
)
3573+
3574+
# Mock the http request call within the method and fake a response.
3575+
with mock.patch.object(type(client.transport._session), "request") as req:
3576+
# Designate an appropriate value for the returned response.
3577+
return_value = operations_pb2.Operation(name="operations/spam")
3578+
3579+
# get arguments that satisfy an http rule for this method
3580+
sample_request = {"parent": "projects/sample1"}
3581+
3582+
# get truthy value for each flattened field
3583+
mock_args = dict(
3584+
parent="parent_value",
3585+
submission=webrisk.Submission(uri="uri_value"),
3586+
)
3587+
mock_args.update(sample_request)
3588+
3589+
# Wrap the value into a proper Response obj
3590+
response_value = Response()
3591+
response_value.status_code = 200
3592+
json_return_value = json_format.MessageToJson(return_value)
3593+
response_value._content = json_return_value.encode("UTF-8")
3594+
req.return_value = response_value
3595+
req.return_value.headers = {"header-1": "value-1", "header-2": "value-2"}
3596+
3597+
client.submit_uri(**mock_args)
3598+
3599+
# Establish that the underlying call was made with the expected
3600+
# request object values.
3601+
assert len(req.mock_calls) == 1
3602+
_, args, _ = req.mock_calls[0]
3603+
assert path_template.validate(
3604+
"%s/v1/{parent=projects/*}/uris:submit" % client.transport._host, args[1]
3605+
)
3606+
3607+
3608+
def test_submit_uri_rest_flattened_error(transport: str = "rest"):
3609+
client = WebRiskServiceClient(
3610+
credentials=ga_credentials.AnonymousCredentials(),
3611+
transport=transport,
3612+
)
3613+
3614+
# Attempting to call a method with both a request object and flattened
3615+
# fields is an error.
3616+
with pytest.raises(ValueError):
3617+
client.submit_uri(
3618+
webrisk.SubmitUriRequest(),
3619+
parent="parent_value",
3620+
submission=webrisk.Submission(uri="uri_value"),
3621+
)
3622+
3623+
34763624
def test_credentials_transport_error():
34773625
# It is an error to provide credentials and a transport instance.
34783626
transport = transports.WebRiskServiceGrpcTransport(

0 commit comments

Comments
 (0)