diff --git a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise/__init__.py b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise/__init__.py index 74085402cea4..cab44f14d8ed 100644 --- a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise/__init__.py +++ b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise/__init__.py @@ -57,6 +57,8 @@ Key, ListFirewallPoliciesRequest, ListFirewallPoliciesResponse, + ListIpOverridesRequest, + ListIpOverridesResponse, ListKeysRequest, ListKeysResponse, ListRelatedAccountGroupMembershipsRequest, @@ -69,6 +71,8 @@ PrivatePasswordLeakVerification, RelatedAccountGroup, RelatedAccountGroupMembership, + RemoveIpOverrideRequest, + RemoveIpOverrideResponse, ReorderFirewallPoliciesRequest, ReorderFirewallPoliciesResponse, RetrieveLegacySecretKeyRequest, @@ -126,6 +130,8 @@ "Key", "ListFirewallPoliciesRequest", "ListFirewallPoliciesResponse", + "ListIpOverridesRequest", + "ListIpOverridesResponse", "ListKeysRequest", "ListKeysResponse", "ListRelatedAccountGroupMembershipsRequest", @@ -138,6 +144,8 @@ "PrivatePasswordLeakVerification", "RelatedAccountGroup", "RelatedAccountGroupMembership", + "RemoveIpOverrideRequest", + "RemoveIpOverrideResponse", "ReorderFirewallPoliciesRequest", "ReorderFirewallPoliciesResponse", "RetrieveLegacySecretKeyRequest", diff --git a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise/gapic_version.py b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise/gapic_version.py index c8313abd74cb..558c8aab67c5 100644 --- a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise/gapic_version.py +++ b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.23.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/__init__.py b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/__init__.py index 872b50ab387a..648463089928 100644 --- a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/__init__.py +++ b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/__init__.py @@ -55,6 +55,8 @@ Key, ListFirewallPoliciesRequest, ListFirewallPoliciesResponse, + ListIpOverridesRequest, + ListIpOverridesResponse, ListKeysRequest, ListKeysResponse, ListRelatedAccountGroupMembershipsRequest, @@ -67,6 +69,8 @@ PrivatePasswordLeakVerification, RelatedAccountGroup, RelatedAccountGroupMembership, + RemoveIpOverrideRequest, + RemoveIpOverrideResponse, ReorderFirewallPoliciesRequest, ReorderFirewallPoliciesResponse, RetrieveLegacySecretKeyRequest, @@ -123,6 +127,8 @@ "Key", "ListFirewallPoliciesRequest", "ListFirewallPoliciesResponse", + "ListIpOverridesRequest", + "ListIpOverridesResponse", "ListKeysRequest", "ListKeysResponse", "ListRelatedAccountGroupMembershipsRequest", @@ -136,6 +142,8 @@ "RecaptchaEnterpriseServiceClient", "RelatedAccountGroup", "RelatedAccountGroupMembership", + "RemoveIpOverrideRequest", + "RemoveIpOverrideResponse", "ReorderFirewallPoliciesRequest", "ReorderFirewallPoliciesResponse", "RetrieveLegacySecretKeyRequest", diff --git a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/gapic_metadata.json b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/gapic_metadata.json index 8722f66f3086..fc9061dcda44 100644 --- a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/gapic_metadata.json +++ b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/gapic_metadata.json @@ -65,6 +65,11 @@ "list_firewall_policies" ] }, + "ListIpOverrides": { + "methods": [ + "list_ip_overrides" + ] + }, "ListKeys": { "methods": [ "list_keys" @@ -85,6 +90,11 @@ "migrate_key" ] }, + "RemoveIpOverride": { + "methods": [ + "remove_ip_override" + ] + }, "ReorderFirewallPolicies": { "methods": [ "reorder_firewall_policies" @@ -170,6 +180,11 @@ "list_firewall_policies" ] }, + "ListIpOverrides": { + "methods": [ + "list_ip_overrides" + ] + }, "ListKeys": { "methods": [ "list_keys" @@ -190,6 +205,11 @@ "migrate_key" ] }, + "RemoveIpOverride": { + "methods": [ + "remove_ip_override" + ] + }, "ReorderFirewallPolicies": { "methods": [ "reorder_firewall_policies" diff --git a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/gapic_version.py b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/gapic_version.py index c8313abd74cb..558c8aab67c5 100644 --- a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/gapic_version.py +++ b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/gapic_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. # -__version__ = "1.23.0" # {x-release-please-version} +__version__ = "0.0.0" # {x-release-please-version} diff --git a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/async_client.py b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/async_client.py index 1ae940ad5ff1..4350a7dc29ac 100644 --- a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/async_client.py +++ b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/async_client.py @@ -705,7 +705,7 @@ async def sample_list_keys(): The request object. The list keys request message. parent (:class:`str`): Required. The name of the project that contains the keys - that are listed, in the format ``projects/{project}``. + that is listed, in the format ``projects/{project}``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -1424,6 +1424,256 @@ async def sample_add_ip_override(): # Done; return the response. return response + async def remove_ip_override( + self, + request: Optional[ + Union[recaptchaenterprise.RemoveIpOverrideRequest, dict] + ] = None, + *, + name: Optional[str] = None, + ip_override_data: Optional[recaptchaenterprise.IpOverrideData] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> recaptchaenterprise.RemoveIpOverrideResponse: + r"""Removes an IP override from a key. The following restrictions + hold: + + - If the IP isn't found in an existing IP override, a + ``NOT_FOUND`` error is returned. + - If the IP is found in an existing IP override, but the + override type does not match, a ``NOT_FOUND`` error is + returned. + + .. code-block:: python + + # 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://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import recaptchaenterprise_v1 + + async def sample_remove_ip_override(): + # Create a client + client = recaptchaenterprise_v1.RecaptchaEnterpriseServiceAsyncClient() + + # Initialize request argument(s) + ip_override_data = recaptchaenterprise_v1.IpOverrideData() + ip_override_data.ip = "ip_value" + ip_override_data.override_type = "ALLOW" + + request = recaptchaenterprise_v1.RemoveIpOverrideRequest( + name="name_value", + ip_override_data=ip_override_data, + ) + + # Make the request + response = await client.remove_ip_override(request=request) + + # Handle the response + print(response) + + Args: + request (Optional[Union[google.cloud.recaptchaenterprise_v1.types.RemoveIpOverrideRequest, dict]]): + The request object. The removeIpOverride request message. + name (:class:`str`): + Required. The name of the key from which the IP override + is removed, in the format + ``projects/{project}/keys/{key}``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + ip_override_data (:class:`google.cloud.recaptchaenterprise_v1.types.IpOverrideData`): + Required. IP override to be removed + from the key. + + This corresponds to the ``ip_override_data`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.recaptchaenterprise_v1.types.RemoveIpOverrideResponse: + Response for RemoveIpOverride. + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name, ip_override_data]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, recaptchaenterprise.RemoveIpOverrideRequest): + request = recaptchaenterprise.RemoveIpOverrideRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if ip_override_data is not None: + request.ip_override_data = ip_override_data + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._client._transport._wrapped_methods[ + self._client._transport.remove_ip_override + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Validate the universe domain. + self._client._validate_universe_domain() + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_ip_overrides( + self, + request: Optional[ + Union[recaptchaenterprise.ListIpOverridesRequest, dict] + ] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListIpOverridesAsyncPager: + r"""Lists all IP overrides for a key. + + .. code-block:: python + + # 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://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import recaptchaenterprise_v1 + + async def sample_list_ip_overrides(): + # Create a client + client = recaptchaenterprise_v1.RecaptchaEnterpriseServiceAsyncClient() + + # Initialize request argument(s) + request = recaptchaenterprise_v1.ListIpOverridesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_ip_overrides(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Optional[Union[google.cloud.recaptchaenterprise_v1.types.ListIpOverridesRequest, dict]]): + The request object. The ListIpOverrides request message. + parent (:class:`str`): + Required. The parent key for which the IP overrides are + listed, in the format ``projects/{project}/keys/{key}``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListIpOverridesAsyncPager: + Response for ListIpOverrides. + + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, recaptchaenterprise.ListIpOverridesRequest): + request = recaptchaenterprise.ListIpOverridesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._client._transport._wrapped_methods[ + self._client._transport.list_ip_overrides + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Validate the universe domain. + self._client._validate_universe_domain() + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListIpOverridesAsyncPager( + method=rpc, + request=request, + response=response, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + async def get_metrics( self, request: Optional[Union[recaptchaenterprise.GetMetricsRequest, dict]] = None, @@ -1575,7 +1825,7 @@ async def sample_create_firewall_policy(): The request object. The create firewall policy request message. parent (:class:`str`): - Required. The name of the project this policy will apply + Required. The name of the project this policy applies to, in the format ``projects/{project}``. This corresponds to the ``parent`` field diff --git a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/client.py b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/client.py index bd62b5ca1e8c..90e133f2dacc 100644 --- a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/client.py +++ b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/client.py @@ -1181,7 +1181,7 @@ def sample_list_keys(): The request object. The list keys request message. parent (str): Required. The name of the project that contains the keys - that are listed, in the format ``projects/{project}``. + that is listed, in the format ``projects/{project}``. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -1884,6 +1884,250 @@ def sample_add_ip_override(): # Done; return the response. return response + def remove_ip_override( + self, + request: Optional[ + Union[recaptchaenterprise.RemoveIpOverrideRequest, dict] + ] = None, + *, + name: Optional[str] = None, + ip_override_data: Optional[recaptchaenterprise.IpOverrideData] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> recaptchaenterprise.RemoveIpOverrideResponse: + r"""Removes an IP override from a key. The following restrictions + hold: + + - If the IP isn't found in an existing IP override, a + ``NOT_FOUND`` error is returned. + - If the IP is found in an existing IP override, but the + override type does not match, a ``NOT_FOUND`` error is + returned. + + .. code-block:: python + + # 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://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import recaptchaenterprise_v1 + + def sample_remove_ip_override(): + # Create a client + client = recaptchaenterprise_v1.RecaptchaEnterpriseServiceClient() + + # Initialize request argument(s) + ip_override_data = recaptchaenterprise_v1.IpOverrideData() + ip_override_data.ip = "ip_value" + ip_override_data.override_type = "ALLOW" + + request = recaptchaenterprise_v1.RemoveIpOverrideRequest( + name="name_value", + ip_override_data=ip_override_data, + ) + + # Make the request + response = client.remove_ip_override(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.recaptchaenterprise_v1.types.RemoveIpOverrideRequest, dict]): + The request object. The removeIpOverride request message. + name (str): + Required. The name of the key from which the IP override + is removed, in the format + ``projects/{project}/keys/{key}``. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + ip_override_data (google.cloud.recaptchaenterprise_v1.types.IpOverrideData): + Required. IP override to be removed + from the key. + + This corresponds to the ``ip_override_data`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.recaptchaenterprise_v1.types.RemoveIpOverrideResponse: + Response for RemoveIpOverride. + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name, ip_override_data]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, recaptchaenterprise.RemoveIpOverrideRequest): + request = recaptchaenterprise.RemoveIpOverrideRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if ip_override_data is not None: + request.ip_override_data = ip_override_data + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.remove_ip_override] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Validate the universe domain. + self._validate_universe_domain() + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_ip_overrides( + self, + request: Optional[ + Union[recaptchaenterprise.ListIpOverridesRequest, dict] + ] = None, + *, + parent: Optional[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListIpOverridesPager: + r"""Lists all IP overrides for a key. + + .. code-block:: python + + # 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://googleapis.dev/python/google-api-core/latest/client_options.html + from google.cloud import recaptchaenterprise_v1 + + def sample_list_ip_overrides(): + # Create a client + client = recaptchaenterprise_v1.RecaptchaEnterpriseServiceClient() + + # Initialize request argument(s) + request = recaptchaenterprise_v1.ListIpOverridesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_ip_overrides(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.recaptchaenterprise_v1.types.ListIpOverridesRequest, dict]): + The request object. The ListIpOverrides request message. + parent (str): + Required. The parent key for which the IP overrides are + listed, in the format ``projects/{project}/keys/{key}``. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListIpOverridesPager: + Response for ListIpOverrides. + + Iterating over this object will yield + results and resolve additional pages + automatically. + + """ + # Create or coerce a protobuf request object. + # - Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # - Use the request object if provided (there's no risk of modifying the input as + # there are no flattened fields), or create one. + if not isinstance(request, recaptchaenterprise.ListIpOverridesRequest): + request = recaptchaenterprise.ListIpOverridesRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_ip_overrides] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Validate the universe domain. + self._validate_universe_domain() + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListIpOverridesPager( + method=rpc, + request=request, + response=response, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + def get_metrics( self, request: Optional[Union[recaptchaenterprise.GetMetricsRequest, dict]] = None, @@ -2032,7 +2276,7 @@ def sample_create_firewall_policy(): The request object. The create firewall policy request message. parent (str): - Required. The name of the project this policy will apply + Required. The name of the project this policy applies to, in the format ``projects/{project}``. This corresponds to the ``parent`` field diff --git a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/pagers.py b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/pagers.py index 7f66f86b07f5..f50c54e13244 100644 --- a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/pagers.py +++ b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/pagers.py @@ -193,6 +193,158 @@ def __repr__(self) -> str: return "{0}<{1!r}>".format(self.__class__.__name__, self._response) +class ListIpOverridesPager: + """A pager for iterating through ``list_ip_overrides`` requests. + + This class thinly wraps an initial + :class:`google.cloud.recaptchaenterprise_v1.types.ListIpOverridesResponse` object, and + provides an ``__iter__`` method to iterate through its + ``ip_overrides`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListIpOverrides`` requests and continue to iterate + through the ``ip_overrides`` field on the + corresponding responses. + + All the usual :class:`google.cloud.recaptchaenterprise_v1.types.ListIpOverridesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., recaptchaenterprise.ListIpOverridesResponse], + request: recaptchaenterprise.ListIpOverridesRequest, + response: recaptchaenterprise.ListIpOverridesResponse, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.recaptchaenterprise_v1.types.ListIpOverridesRequest): + The initial request object. + response (google.cloud.recaptchaenterprise_v1.types.ListIpOverridesResponse): + The initial response object. + retry (google.api_core.retry.Retry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = recaptchaenterprise.ListIpOverridesRequest(request) + self._response = response + self._retry = retry + self._timeout = timeout + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[recaptchaenterprise.ListIpOverridesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method( + self._request, + retry=self._retry, + timeout=self._timeout, + metadata=self._metadata, + ) + yield self._response + + def __iter__(self) -> Iterator[recaptchaenterprise.IpOverrideData]: + for page in self.pages: + yield from page.ip_overrides + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListIpOverridesAsyncPager: + """A pager for iterating through ``list_ip_overrides`` requests. + + This class thinly wraps an initial + :class:`google.cloud.recaptchaenterprise_v1.types.ListIpOverridesResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``ip_overrides`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListIpOverrides`` requests and continue to iterate + through the ``ip_overrides`` field on the + corresponding responses. + + All the usual :class:`google.cloud.recaptchaenterprise_v1.types.ListIpOverridesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[recaptchaenterprise.ListIpOverridesResponse]], + request: recaptchaenterprise.ListIpOverridesRequest, + response: recaptchaenterprise.ListIpOverridesResponse, + *, + retry: OptionalAsyncRetry = gapic_v1.method.DEFAULT, + timeout: Union[float, object] = gapic_v1.method.DEFAULT, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.recaptchaenterprise_v1.types.ListIpOverridesRequest): + The initial request object. + response (google.cloud.recaptchaenterprise_v1.types.ListIpOverridesResponse): + The initial response object. + retry (google.api_core.retry.AsyncRetry): Designation of what errors, + if any, should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = recaptchaenterprise.ListIpOverridesRequest(request) + self._response = response + self._retry = retry + self._timeout = timeout + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[recaptchaenterprise.ListIpOverridesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method( + self._request, + retry=self._retry, + timeout=self._timeout, + metadata=self._metadata, + ) + yield self._response + + def __aiter__(self) -> AsyncIterator[recaptchaenterprise.IpOverrideData]: + async def async_generator(): + async for page in self.pages: + for response in page.ip_overrides: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + class ListFirewallPoliciesPager: """A pager for iterating through ``list_firewall_policies`` requests. diff --git a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/transports/base.py b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/transports/base.py index 1d997dedd2b7..0da7cf8f3ec3 100644 --- a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/transports/base.py +++ b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/transports/base.py @@ -179,6 +179,16 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), + self.remove_ip_override: gapic_v1.method.wrap_method( + self.remove_ip_override, + default_timeout=None, + client_info=client_info, + ), + self.list_ip_overrides: gapic_v1.method.wrap_method( + self.list_ip_overrides, + default_timeout=None, + client_info=client_info, + ), self.get_metrics: gapic_v1.method.wrap_method( self.get_metrics, default_timeout=None, @@ -344,6 +354,30 @@ def add_ip_override( ]: raise NotImplementedError() + @property + def remove_ip_override( + self, + ) -> Callable[ + [recaptchaenterprise.RemoveIpOverrideRequest], + Union[ + recaptchaenterprise.RemoveIpOverrideResponse, + Awaitable[recaptchaenterprise.RemoveIpOverrideResponse], + ], + ]: + raise NotImplementedError() + + @property + def list_ip_overrides( + self, + ) -> Callable[ + [recaptchaenterprise.ListIpOverridesRequest], + Union[ + recaptchaenterprise.ListIpOverridesResponse, + Awaitable[recaptchaenterprise.ListIpOverridesResponse], + ], + ]: + raise NotImplementedError() + @property def get_metrics( self, diff --git a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/transports/grpc.py b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/transports/grpc.py index bb598e78465f..687afe06080c 100644 --- a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/transports/grpc.py +++ b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/transports/grpc.py @@ -524,6 +524,71 @@ def add_ip_override( ) return self._stubs["add_ip_override"] + @property + def remove_ip_override( + self, + ) -> Callable[ + [recaptchaenterprise.RemoveIpOverrideRequest], + recaptchaenterprise.RemoveIpOverrideResponse, + ]: + r"""Return a callable for the remove ip override method over gRPC. + + Removes an IP override from a key. The following restrictions + hold: + + - If the IP isn't found in an existing IP override, a + ``NOT_FOUND`` error is returned. + - If the IP is found in an existing IP override, but the + override type does not match, a ``NOT_FOUND`` error is + returned. + + Returns: + Callable[[~.RemoveIpOverrideRequest], + ~.RemoveIpOverrideResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "remove_ip_override" not in self._stubs: + self._stubs["remove_ip_override"] = self.grpc_channel.unary_unary( + "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/RemoveIpOverride", + request_serializer=recaptchaenterprise.RemoveIpOverrideRequest.serialize, + response_deserializer=recaptchaenterprise.RemoveIpOverrideResponse.deserialize, + ) + return self._stubs["remove_ip_override"] + + @property + def list_ip_overrides( + self, + ) -> Callable[ + [recaptchaenterprise.ListIpOverridesRequest], + recaptchaenterprise.ListIpOverridesResponse, + ]: + r"""Return a callable for the list ip overrides method over gRPC. + + Lists all IP overrides for a key. + + Returns: + Callable[[~.ListIpOverridesRequest], + ~.ListIpOverridesResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_ip_overrides" not in self._stubs: + self._stubs["list_ip_overrides"] = self.grpc_channel.unary_unary( + "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/ListIpOverrides", + request_serializer=recaptchaenterprise.ListIpOverridesRequest.serialize, + response_deserializer=recaptchaenterprise.ListIpOverridesResponse.deserialize, + ) + return self._stubs["list_ip_overrides"] + @property def get_metrics( self, diff --git a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/transports/grpc_asyncio.py b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/transports/grpc_asyncio.py index 1de0e29e087c..d1ca99fffd9b 100644 --- a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/transports/grpc_asyncio.py +++ b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/services/recaptcha_enterprise_service/transports/grpc_asyncio.py @@ -544,6 +544,71 @@ def add_ip_override( ) return self._stubs["add_ip_override"] + @property + def remove_ip_override( + self, + ) -> Callable[ + [recaptchaenterprise.RemoveIpOverrideRequest], + Awaitable[recaptchaenterprise.RemoveIpOverrideResponse], + ]: + r"""Return a callable for the remove ip override method over gRPC. + + Removes an IP override from a key. The following restrictions + hold: + + - If the IP isn't found in an existing IP override, a + ``NOT_FOUND`` error is returned. + - If the IP is found in an existing IP override, but the + override type does not match, a ``NOT_FOUND`` error is + returned. + + Returns: + Callable[[~.RemoveIpOverrideRequest], + Awaitable[~.RemoveIpOverrideResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "remove_ip_override" not in self._stubs: + self._stubs["remove_ip_override"] = self.grpc_channel.unary_unary( + "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/RemoveIpOverride", + request_serializer=recaptchaenterprise.RemoveIpOverrideRequest.serialize, + response_deserializer=recaptchaenterprise.RemoveIpOverrideResponse.deserialize, + ) + return self._stubs["remove_ip_override"] + + @property + def list_ip_overrides( + self, + ) -> Callable[ + [recaptchaenterprise.ListIpOverridesRequest], + Awaitable[recaptchaenterprise.ListIpOverridesResponse], + ]: + r"""Return a callable for the list ip overrides method over gRPC. + + Lists all IP overrides for a key. + + Returns: + Callable[[~.ListIpOverridesRequest], + Awaitable[~.ListIpOverridesResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_ip_overrides" not in self._stubs: + self._stubs["list_ip_overrides"] = self.grpc_channel.unary_unary( + "/google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService/ListIpOverrides", + request_serializer=recaptchaenterprise.ListIpOverridesRequest.serialize, + response_deserializer=recaptchaenterprise.ListIpOverridesResponse.deserialize, + ) + return self._stubs["list_ip_overrides"] + @property def get_metrics( self, @@ -895,6 +960,16 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), + self.remove_ip_override: self._wrap_method( + self.remove_ip_override, + default_timeout=None, + client_info=client_info, + ), + self.list_ip_overrides: self._wrap_method( + self.list_ip_overrides, + default_timeout=None, + client_info=client_info, + ), self.get_metrics: self._wrap_method( self.get_metrics, default_timeout=None, diff --git a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/types/__init__.py b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/types/__init__.py index 230f8d821762..21b3c2cfa07e 100644 --- a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/types/__init__.py +++ b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/types/__init__.py @@ -46,6 +46,8 @@ Key, ListFirewallPoliciesRequest, ListFirewallPoliciesResponse, + ListIpOverridesRequest, + ListIpOverridesResponse, ListKeysRequest, ListKeysResponse, ListRelatedAccountGroupMembershipsRequest, @@ -58,6 +60,8 @@ PrivatePasswordLeakVerification, RelatedAccountGroup, RelatedAccountGroupMembership, + RemoveIpOverrideRequest, + RemoveIpOverrideResponse, ReorderFirewallPoliciesRequest, ReorderFirewallPoliciesResponse, RetrieveLegacySecretKeyRequest, @@ -113,6 +117,8 @@ "Key", "ListFirewallPoliciesRequest", "ListFirewallPoliciesResponse", + "ListIpOverridesRequest", + "ListIpOverridesResponse", "ListKeysRequest", "ListKeysResponse", "ListRelatedAccountGroupMembershipsRequest", @@ -125,6 +131,8 @@ "PrivatePasswordLeakVerification", "RelatedAccountGroup", "RelatedAccountGroupMembership", + "RemoveIpOverrideRequest", + "RemoveIpOverrideResponse", "ReorderFirewallPoliciesRequest", "ReorderFirewallPoliciesResponse", "RetrieveLegacySecretKeyRequest", diff --git a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/types/recaptchaenterprise.py b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/types/recaptchaenterprise.py index 129df8657cdd..2683e3f38156 100644 --- a/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/types/recaptchaenterprise.py +++ b/packages/google-cloud-recaptcha-enterprise/google/cloud/recaptchaenterprise_v1/types/recaptchaenterprise.py @@ -84,6 +84,10 @@ "SearchRelatedAccountGroupMembershipsResponse", "AddIpOverrideRequest", "AddIpOverrideResponse", + "RemoveIpOverrideRequest", + "RemoveIpOverrideResponse", + "ListIpOverridesRequest", + "ListIpOverridesResponse", "RelatedAccountGroupMembership", "RelatedAccountGroup", "WafSettings", @@ -786,7 +790,7 @@ class Event(proto.Message): express (bool): Optional. Flag for a reCAPTCHA express request for an assessment without a token. If enabled, ``site_key`` must - reference an express key. + reference an Express site key. requested_uri (str): Optional. The URI resource the user requested that triggered an assessment. @@ -808,9 +812,9 @@ class Event(proto.Message): transaction_data (google.cloud.recaptchaenterprise_v1.types.TransactionData): Optional. Data describing a payment transaction to be assessed. Sending this data - enables reCAPTCHA Fraud Prevention and the - FraudPreventionAssessment component in the - response. + enables reCAPTCHA Enterprise Fraud Prevention + and the FraudPreventionAssessment component in + the response. user_info (google.cloud.recaptchaenterprise_v1.types.UserInfo): Optional. Information about the user that generates this event, when they can be @@ -1766,7 +1770,7 @@ class ListKeysRequest(proto.Message): Attributes: parent (str): Required. The name of the project that contains the keys - that are listed, in the format ``projects/{project}``. + that is listed, in the format ``projects/{project}``. page_size (int): Optional. The maximum number of keys to return. Default is 10. Max limit is 1000. @@ -1889,8 +1893,8 @@ class CreateFirewallPolicyRequest(proto.Message): Attributes: parent (str): - Required. The name of the project this policy will apply to, - in the format ``projects/{project}``. + Required. The name of the project this policy applies to, in + the format ``projects/{project}``. firewall_policy (google.cloud.recaptchaenterprise_v1.types.FirewallPolicy): Required. Information to create the policy. """ @@ -2106,8 +2110,8 @@ class Metrics(proto.Message): challenge_metrics (MutableSequence[google.cloud.recaptchaenterprise_v1.types.ChallengeMetrics]): Metrics are continuous and in order by dates, and in the granularity of day. Only - challenge-based keys (CHECKBOX, INVISIBLE), will - have challenge-based data. + challenge-based keys (CHECKBOX, INVISIBLE) have + challenge-based data. """ name: str = proto.Field( @@ -2185,8 +2189,8 @@ class Key(proto.Message): This field is a member of `oneof`_ ``platform_settings``. express_settings (google.cloud.recaptchaenterprise_v1.types.ExpressKeySettings): - Settings specific to keys that can be used - for reCAPTCHA Express. + Settings for keys that can be used by + reCAPTCHA Express. This field is a member of `oneof`_ ``platform_settings``. labels (MutableMapping[str, str]): @@ -2261,15 +2265,14 @@ class TestingOptions(proto.Message): Attributes: testing_score (float): - Optional. All assessments for this Key will - return this score. Must be between 0 (likely not + Optional. All assessments for this Key return + this score. Must be between 0 (likely not legitimate) and 1 (likely legitimate) inclusive. testing_challenge (google.cloud.recaptchaenterprise_v1.types.TestingOptions.TestingChallenge): Optional. For challenge-based keys only (CHECKBOX, INVISIBLE), all challenge requests - for this site will return nocaptcha if - NOCAPTCHA, or an unsolvable challenge if - CHALLENGE. + for this site return nocaptcha if NOCAPTCHA, or + an unsolvable challenge if CHALLENGE. """ class TestingChallenge(proto.Enum): @@ -2308,8 +2311,8 @@ class WebKeySettings(proto.Message): Attributes: allow_all_domains (bool): - Optional. If set to true, it means allowed_domains will not - be enforced. + Optional. If set to true, it means allowed_domains are not + enforced. allowed_domains (MutableSequence[str]): Optional. Domains or subdomains of websites allowed to use the key. All subdomains of an @@ -2327,10 +2330,10 @@ class WebKeySettings(proto.Message): Required. Describes how this key is integrated with the website. challenge_security_preference (google.cloud.recaptchaenterprise_v1.types.WebKeySettings.ChallengeSecurityPreference): - Optional. Settings for the frequency and - difficulty at which this key triggers captcha - challenges. This should only be specified for - IntegrationTypes CHECKBOX and INVISIBLE. + Optional. Settings for the frequency and difficulty at which + this key triggers captcha challenges. This should only be + specified for IntegrationTypes CHECKBOX and INVISIBLE and + SCORE_AND_CHALLENGE. """ class IntegrationType(proto.Enum): @@ -2451,12 +2454,11 @@ class IOSKeySettings(proto.Message): apple_developer_id (google.cloud.recaptchaenterprise_v1.types.AppleDeveloperId): Optional. Apple Developer account details for the app that is protected by the reCAPTCHA Key. - reCAPTCHA Enterprise leverages platform-specific - checks like Apple App Attest and Apple - DeviceCheck to protect your app from abuse. - Providing these fields allows reCAPTCHA - Enterprise to get a better assessment of the - integrity of your app. + reCAPTCHA leverages platform-specific checks + like Apple App Attest and Apple DeviceCheck to + protect your app from abuse. Providing these + fields allows reCAPTCHA to get a better + assessment of the integrity of your app. """ allow_all_bundle_ids: bool = proto.Field( @@ -2644,30 +2646,28 @@ class FirewallAction(proto.Message): This field is a member of `oneof`_ ``firewall_action_oneof``. block (google.cloud.recaptchaenterprise_v1.types.FirewallAction.BlockAction): - This action will deny access to a given page. - The user will get an HTTP error code. + This action denies access to a given page. + The user gets an HTTP error code. This field is a member of `oneof`_ ``firewall_action_oneof``. include_recaptcha_script (google.cloud.recaptchaenterprise_v1.types.FirewallAction.IncludeRecaptchaScriptAction): - This action will inject reCAPTCHA JavaScript - code into the HTML page returned by the site - backend. + This action injects reCAPTCHA JavaScript code + into the HTML page returned by the site backend. This field is a member of `oneof`_ ``firewall_action_oneof``. redirect (google.cloud.recaptchaenterprise_v1.types.FirewallAction.RedirectAction): - This action will redirect the request to a - ReCaptcha interstitial to attach a token. + This action redirects the request to a + reCAPTCHA interstitial to attach a token. This field is a member of `oneof`_ ``firewall_action_oneof``. substitute (google.cloud.recaptchaenterprise_v1.types.FirewallAction.SubstituteAction): - This action will transparently serve a - different page to an offending user. + This action transparently serves a different + page to an offending user. This field is a member of `oneof`_ ``firewall_action_oneof``. set_header (google.cloud.recaptchaenterprise_v1.types.FirewallAction.SetHeaderAction): - This action will set a custom header but - allow the request to continue to the customer - backend. + This action sets a custom header but allow + the request to continue to the customer backend. This field is a member of `oneof`_ ``firewall_action_oneof``. """ @@ -2693,7 +2693,7 @@ class IncludeRecaptchaScriptAction(proto.Message): class RedirectAction(proto.Message): r"""A redirect action returns a 307 (temporary redirect) - response, pointing the user to a ReCaptcha interstitial page to + response, pointing the user to a reCAPTCHA interstitial page to attach a token. """ @@ -3089,6 +3089,91 @@ class AddIpOverrideResponse(proto.Message): r"""Response for AddIpOverride.""" +class RemoveIpOverrideRequest(proto.Message): + r"""The removeIpOverride request message. + + Attributes: + name (str): + Required. The name of the key from which the IP override is + removed, in the format ``projects/{project}/keys/{key}``. + ip_override_data (google.cloud.recaptchaenterprise_v1.types.IpOverrideData): + Required. IP override to be removed from the + key. + """ + + name: str = proto.Field( + proto.STRING, + number=1, + ) + ip_override_data: "IpOverrideData" = proto.Field( + proto.MESSAGE, + number=2, + message="IpOverrideData", + ) + + +class RemoveIpOverrideResponse(proto.Message): + r"""Response for RemoveIpOverride.""" + + +class ListIpOverridesRequest(proto.Message): + r"""The ListIpOverrides request message. + + Attributes: + parent (str): + Required. The parent key for which the IP overrides are + listed, in the format ``projects/{project}/keys/{key}``. + page_size (int): + Optional. The maximum number of overrides to return. Default + is 10. Max limit is 100. If the number of overrides is less + than the page_size, all overrides are returned. If the page + size is more than 100, it is coerced to 100. + page_token (str): + Optional. The next_page_token value returned from a previous + ListIpOverridesRequest, if any. + """ + + parent: str = proto.Field( + proto.STRING, + number=1, + ) + page_size: int = proto.Field( + proto.INT32, + number=2, + ) + page_token: str = proto.Field( + proto.STRING, + number=3, + ) + + +class ListIpOverridesResponse(proto.Message): + r"""Response for ListIpOverrides. + + Attributes: + ip_overrides (MutableSequence[google.cloud.recaptchaenterprise_v1.types.IpOverrideData]): + IP Overrides details. + next_page_token (str): + Token to retrieve the next page of results. + If this field is empty, no keys remain in the + results. + """ + + @property + def raw_page(self): + return self + + ip_overrides: MutableSequence["IpOverrideData"] = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="IpOverrideData", + ) + next_page_token: str = proto.Field( + proto.STRING, + number=2, + ) + + class RelatedAccountGroupMembership(proto.Message): r"""A membership in a group of related accounts. @@ -3179,7 +3264,7 @@ class WafFeature(proto.Enum): EXPRESS = 5 class WafService(proto.Enum): - r"""Web Application Firewalls supported by reCAPTCHA Enterprise. + r"""Web Application Firewalls supported by reCAPTCHA. Values: WAF_SERVICE_UNSPECIFIED (0): @@ -3190,11 +3275,14 @@ class WafService(proto.Enum): Fastly CLOUDFLARE (4): Cloudflare + AKAMAI (5): + Akamai """ WAF_SERVICE_UNSPECIFIED = 0 CA = 1 FASTLY = 3 CLOUDFLARE = 4 + AKAMAI = 5 waf_service: WafService = proto.Field( proto.ENUM, diff --git a/packages/google-cloud-recaptcha-enterprise/samples/generated_samples/recaptchaenterprise_v1_generated_recaptcha_enterprise_service_list_ip_overrides_async.py b/packages/google-cloud-recaptcha-enterprise/samples/generated_samples/recaptchaenterprise_v1_generated_recaptcha_enterprise_service_list_ip_overrides_async.py new file mode 100644 index 000000000000..a12de57ccb10 --- /dev/null +++ b/packages/google-cloud-recaptcha-enterprise/samples/generated_samples/recaptchaenterprise_v1_generated_recaptcha_enterprise_service_list_ip_overrides_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListIpOverrides +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-recaptcha-enterprise + + +# [START recaptchaenterprise_v1_generated_RecaptchaEnterpriseService_ListIpOverrides_async] +# 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://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import recaptchaenterprise_v1 + + +async def sample_list_ip_overrides(): + # Create a client + client = recaptchaenterprise_v1.RecaptchaEnterpriseServiceAsyncClient() + + # Initialize request argument(s) + request = recaptchaenterprise_v1.ListIpOverridesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_ip_overrides(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END recaptchaenterprise_v1_generated_RecaptchaEnterpriseService_ListIpOverrides_async] diff --git a/packages/google-cloud-recaptcha-enterprise/samples/generated_samples/recaptchaenterprise_v1_generated_recaptcha_enterprise_service_list_ip_overrides_sync.py b/packages/google-cloud-recaptcha-enterprise/samples/generated_samples/recaptchaenterprise_v1_generated_recaptcha_enterprise_service_list_ip_overrides_sync.py new file mode 100644 index 000000000000..b1daef7ff847 --- /dev/null +++ b/packages/google-cloud-recaptcha-enterprise/samples/generated_samples/recaptchaenterprise_v1_generated_recaptcha_enterprise_service_list_ip_overrides_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListIpOverrides +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-recaptcha-enterprise + + +# [START recaptchaenterprise_v1_generated_RecaptchaEnterpriseService_ListIpOverrides_sync] +# 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://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import recaptchaenterprise_v1 + + +def sample_list_ip_overrides(): + # Create a client + client = recaptchaenterprise_v1.RecaptchaEnterpriseServiceClient() + + # Initialize request argument(s) + request = recaptchaenterprise_v1.ListIpOverridesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_ip_overrides(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END recaptchaenterprise_v1_generated_RecaptchaEnterpriseService_ListIpOverrides_sync] diff --git a/packages/google-cloud-recaptcha-enterprise/samples/generated_samples/recaptchaenterprise_v1_generated_recaptcha_enterprise_service_remove_ip_override_async.py b/packages/google-cloud-recaptcha-enterprise/samples/generated_samples/recaptchaenterprise_v1_generated_recaptcha_enterprise_service_remove_ip_override_async.py new file mode 100644 index 000000000000..0afc90fd3a36 --- /dev/null +++ b/packages/google-cloud-recaptcha-enterprise/samples/generated_samples/recaptchaenterprise_v1_generated_recaptcha_enterprise_service_remove_ip_override_async.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RemoveIpOverride +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-recaptcha-enterprise + + +# [START recaptchaenterprise_v1_generated_RecaptchaEnterpriseService_RemoveIpOverride_async] +# 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://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import recaptchaenterprise_v1 + + +async def sample_remove_ip_override(): + # Create a client + client = recaptchaenterprise_v1.RecaptchaEnterpriseServiceAsyncClient() + + # Initialize request argument(s) + ip_override_data = recaptchaenterprise_v1.IpOverrideData() + ip_override_data.ip = "ip_value" + ip_override_data.override_type = "ALLOW" + + request = recaptchaenterprise_v1.RemoveIpOverrideRequest( + name="name_value", + ip_override_data=ip_override_data, + ) + + # Make the request + response = await client.remove_ip_override(request=request) + + # Handle the response + print(response) + +# [END recaptchaenterprise_v1_generated_RecaptchaEnterpriseService_RemoveIpOverride_async] diff --git a/packages/google-cloud-recaptcha-enterprise/samples/generated_samples/recaptchaenterprise_v1_generated_recaptcha_enterprise_service_remove_ip_override_sync.py b/packages/google-cloud-recaptcha-enterprise/samples/generated_samples/recaptchaenterprise_v1_generated_recaptcha_enterprise_service_remove_ip_override_sync.py new file mode 100644 index 000000000000..da8d58b09bd8 --- /dev/null +++ b/packages/google-cloud-recaptcha-enterprise/samples/generated_samples/recaptchaenterprise_v1_generated_recaptcha_enterprise_service_remove_ip_override_sync.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RemoveIpOverride +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-recaptcha-enterprise + + +# [START recaptchaenterprise_v1_generated_RecaptchaEnterpriseService_RemoveIpOverride_sync] +# 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://googleapis.dev/python/google-api-core/latest/client_options.html +from google.cloud import recaptchaenterprise_v1 + + +def sample_remove_ip_override(): + # Create a client + client = recaptchaenterprise_v1.RecaptchaEnterpriseServiceClient() + + # Initialize request argument(s) + ip_override_data = recaptchaenterprise_v1.IpOverrideData() + ip_override_data.ip = "ip_value" + ip_override_data.override_type = "ALLOW" + + request = recaptchaenterprise_v1.RemoveIpOverrideRequest( + name="name_value", + ip_override_data=ip_override_data, + ) + + # Make the request + response = client.remove_ip_override(request=request) + + # Handle the response + print(response) + +# [END recaptchaenterprise_v1_generated_RecaptchaEnterpriseService_RemoveIpOverride_sync] diff --git a/packages/google-cloud-recaptcha-enterprise/samples/generated_samples/snippet_metadata_google.cloud.recaptchaenterprise.v1.json b/packages/google-cloud-recaptcha-enterprise/samples/generated_samples/snippet_metadata_google.cloud.recaptchaenterprise.v1.json index 1702e3084776..0d14f8e6deb6 100644 --- a/packages/google-cloud-recaptcha-enterprise/samples/generated_samples/snippet_metadata_google.cloud.recaptchaenterprise.v1.json +++ b/packages/google-cloud-recaptcha-enterprise/samples/generated_samples/snippet_metadata_google.cloud.recaptchaenterprise.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-recaptcha-enterprise", - "version": "1.23.0" + "version": "0.1.0" }, "snippets": [ { @@ -1810,6 +1810,167 @@ ], "title": "recaptchaenterprise_v1_generated_recaptcha_enterprise_service_list_firewall_policies_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.recaptchaenterprise_v1.RecaptchaEnterpriseServiceAsyncClient", + "shortName": "RecaptchaEnterpriseServiceAsyncClient" + }, + "fullName": "google.cloud.recaptchaenterprise_v1.RecaptchaEnterpriseServiceAsyncClient.list_ip_overrides", + "method": { + "fullName": "google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService.ListIpOverrides", + "service": { + "fullName": "google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService", + "shortName": "RecaptchaEnterpriseService" + }, + "shortName": "ListIpOverrides" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.recaptchaenterprise_v1.types.ListIpOverridesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListIpOverridesAsyncPager", + "shortName": "list_ip_overrides" + }, + "description": "Sample for ListIpOverrides", + "file": "recaptchaenterprise_v1_generated_recaptcha_enterprise_service_list_ip_overrides_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "recaptchaenterprise_v1_generated_RecaptchaEnterpriseService_ListIpOverrides_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "recaptchaenterprise_v1_generated_recaptcha_enterprise_service_list_ip_overrides_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.recaptchaenterprise_v1.RecaptchaEnterpriseServiceClient", + "shortName": "RecaptchaEnterpriseServiceClient" + }, + "fullName": "google.cloud.recaptchaenterprise_v1.RecaptchaEnterpriseServiceClient.list_ip_overrides", + "method": { + "fullName": "google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService.ListIpOverrides", + "service": { + "fullName": "google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService", + "shortName": "RecaptchaEnterpriseService" + }, + "shortName": "ListIpOverrides" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.recaptchaenterprise_v1.types.ListIpOverridesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListIpOverridesPager", + "shortName": "list_ip_overrides" + }, + "description": "Sample for ListIpOverrides", + "file": "recaptchaenterprise_v1_generated_recaptcha_enterprise_service_list_ip_overrides_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "recaptchaenterprise_v1_generated_RecaptchaEnterpriseService_ListIpOverrides_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 45, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 46, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "recaptchaenterprise_v1_generated_recaptcha_enterprise_service_list_ip_overrides_sync.py" + }, { "canonical": true, "clientMethod": { @@ -2446,6 +2607,175 @@ ], "title": "recaptchaenterprise_v1_generated_recaptcha_enterprise_service_migrate_key_sync.py" }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.recaptchaenterprise_v1.RecaptchaEnterpriseServiceAsyncClient", + "shortName": "RecaptchaEnterpriseServiceAsyncClient" + }, + "fullName": "google.cloud.recaptchaenterprise_v1.RecaptchaEnterpriseServiceAsyncClient.remove_ip_override", + "method": { + "fullName": "google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService.RemoveIpOverride", + "service": { + "fullName": "google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService", + "shortName": "RecaptchaEnterpriseService" + }, + "shortName": "RemoveIpOverride" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.recaptchaenterprise_v1.types.RemoveIpOverrideRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "ip_override_data", + "type": "google.cloud.recaptchaenterprise_v1.types.IpOverrideData" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.recaptchaenterprise_v1.types.RemoveIpOverrideResponse", + "shortName": "remove_ip_override" + }, + "description": "Sample for RemoveIpOverride", + "file": "recaptchaenterprise_v1_generated_recaptcha_enterprise_service_remove_ip_override_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "recaptchaenterprise_v1_generated_RecaptchaEnterpriseService_RemoveIpOverride_async", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 50, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 51, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "recaptchaenterprise_v1_generated_recaptcha_enterprise_service_remove_ip_override_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.recaptchaenterprise_v1.RecaptchaEnterpriseServiceClient", + "shortName": "RecaptchaEnterpriseServiceClient" + }, + "fullName": "google.cloud.recaptchaenterprise_v1.RecaptchaEnterpriseServiceClient.remove_ip_override", + "method": { + "fullName": "google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService.RemoveIpOverride", + "service": { + "fullName": "google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService", + "shortName": "RecaptchaEnterpriseService" + }, + "shortName": "RemoveIpOverride" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.recaptchaenterprise_v1.types.RemoveIpOverrideRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "ip_override_data", + "type": "google.cloud.recaptchaenterprise_v1.types.IpOverrideData" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.recaptchaenterprise_v1.types.RemoveIpOverrideResponse", + "shortName": "remove_ip_override" + }, + "description": "Sample for RemoveIpOverride", + "file": "recaptchaenterprise_v1_generated_recaptcha_enterprise_service_remove_ip_override_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "recaptchaenterprise_v1_generated_RecaptchaEnterpriseService_RemoveIpOverride_sync", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 40, + "start": 38, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 50, + "start": 41, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 51, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "recaptchaenterprise_v1_generated_recaptcha_enterprise_service_remove_ip_override_sync.py" + }, { "canonical": true, "clientMethod": { diff --git a/packages/google-cloud-recaptcha-enterprise/scripts/fixup_recaptchaenterprise_v1_keywords.py b/packages/google-cloud-recaptcha-enterprise/scripts/fixup_recaptchaenterprise_v1_keywords.py index 36e16174f78a..f3a45648c28e 100644 --- a/packages/google-cloud-recaptcha-enterprise/scripts/fixup_recaptchaenterprise_v1_keywords.py +++ b/packages/google-cloud-recaptcha-enterprise/scripts/fixup_recaptchaenterprise_v1_keywords.py @@ -50,10 +50,12 @@ class recaptchaenterpriseCallTransformer(cst.CSTTransformer): 'get_key': ('name', ), 'get_metrics': ('name', ), 'list_firewall_policies': ('parent', 'page_size', 'page_token', ), + 'list_ip_overrides': ('parent', 'page_size', 'page_token', ), 'list_keys': ('parent', 'page_size', 'page_token', ), 'list_related_account_group_memberships': ('parent', 'page_size', 'page_token', ), 'list_related_account_groups': ('parent', 'page_size', 'page_token', ), 'migrate_key': ('name', 'skip_billing_check', ), + 'remove_ip_override': ('name', 'ip_override_data', ), 'reorder_firewall_policies': ('parent', 'names', ), 'retrieve_legacy_secret_key': ('key', ), 'search_related_account_group_memberships': ('project', 'account_id', 'hashed_account_id', 'page_size', 'page_token', ), diff --git a/packages/google-cloud-recaptcha-enterprise/tests/unit/gapic/recaptchaenterprise_v1/test_recaptcha_enterprise_service.py b/packages/google-cloud-recaptcha-enterprise/tests/unit/gapic/recaptchaenterprise_v1/test_recaptcha_enterprise_service.py index cab29893173f..7bcde7cb5cf5 100644 --- a/packages/google-cloud-recaptcha-enterprise/tests/unit/gapic/recaptchaenterprise_v1/test_recaptcha_enterprise_service.py +++ b/packages/google-cloud-recaptcha-enterprise/tests/unit/gapic/recaptchaenterprise_v1/test_recaptcha_enterprise_service.py @@ -4609,6 +4609,896 @@ async def test_add_ip_override_flattened_error_async(): ) +@pytest.mark.parametrize( + "request_type", + [ + recaptchaenterprise.RemoveIpOverrideRequest, + dict, + ], +) +def test_remove_ip_override(request_type, transport: str = "grpc"): + client = RecaptchaEnterpriseServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.remove_ip_override), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = recaptchaenterprise.RemoveIpOverrideResponse() + response = client.remove_ip_override(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = recaptchaenterprise.RemoveIpOverrideRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, recaptchaenterprise.RemoveIpOverrideResponse) + + +def test_remove_ip_override_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = RecaptchaEnterpriseServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = recaptchaenterprise.RemoveIpOverrideRequest( + name="name_value", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.remove_ip_override), "__call__" + ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client.remove_ip_override(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == recaptchaenterprise.RemoveIpOverrideRequest( + name="name_value", + ) + + +def test_remove_ip_override_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = RecaptchaEnterpriseServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._transport.remove_ip_override in client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.remove_ip_override + ] = mock_rpc + request = {} + client.remove_ip_override(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.remove_ip_override(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +@pytest.mark.asyncio +async def test_remove_ip_override_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = RecaptchaEnterpriseServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.remove_ip_override + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.AsyncMock() + mock_rpc.return_value = mock.Mock() + client._client._transport._wrapped_methods[ + client._client._transport.remove_ip_override + ] = mock_rpc + + request = {} + await client.remove_ip_override(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + await client.remove_ip_override(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +@pytest.mark.asyncio +async def test_remove_ip_override_async( + transport: str = "grpc_asyncio", + request_type=recaptchaenterprise.RemoveIpOverrideRequest, +): + client = RecaptchaEnterpriseServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.remove_ip_override), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + recaptchaenterprise.RemoveIpOverrideResponse() + ) + response = await client.remove_ip_override(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = recaptchaenterprise.RemoveIpOverrideRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, recaptchaenterprise.RemoveIpOverrideResponse) + + +@pytest.mark.asyncio +async def test_remove_ip_override_async_from_dict(): + await test_remove_ip_override_async(request_type=dict) + + +def test_remove_ip_override_field_headers(): + client = RecaptchaEnterpriseServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = recaptchaenterprise.RemoveIpOverrideRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.remove_ip_override), "__call__" + ) as call: + call.return_value = recaptchaenterprise.RemoveIpOverrideResponse() + client.remove_ip_override(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_remove_ip_override_field_headers_async(): + client = RecaptchaEnterpriseServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = recaptchaenterprise.RemoveIpOverrideRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.remove_ip_override), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + recaptchaenterprise.RemoveIpOverrideResponse() + ) + await client.remove_ip_override(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_remove_ip_override_flattened(): + client = RecaptchaEnterpriseServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.remove_ip_override), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = recaptchaenterprise.RemoveIpOverrideResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.remove_ip_override( + name="name_value", + ip_override_data=recaptchaenterprise.IpOverrideData(ip="ip_value"), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].ip_override_data + mock_val = recaptchaenterprise.IpOverrideData(ip="ip_value") + assert arg == mock_val + + +def test_remove_ip_override_flattened_error(): + client = RecaptchaEnterpriseServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.remove_ip_override( + recaptchaenterprise.RemoveIpOverrideRequest(), + name="name_value", + ip_override_data=recaptchaenterprise.IpOverrideData(ip="ip_value"), + ) + + +@pytest.mark.asyncio +async def test_remove_ip_override_flattened_async(): + client = RecaptchaEnterpriseServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.remove_ip_override), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = recaptchaenterprise.RemoveIpOverrideResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + recaptchaenterprise.RemoveIpOverrideResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.remove_ip_override( + name="name_value", + ip_override_data=recaptchaenterprise.IpOverrideData(ip="ip_value"), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].ip_override_data + mock_val = recaptchaenterprise.IpOverrideData(ip="ip_value") + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_remove_ip_override_flattened_error_async(): + client = RecaptchaEnterpriseServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.remove_ip_override( + recaptchaenterprise.RemoveIpOverrideRequest(), + name="name_value", + ip_override_data=recaptchaenterprise.IpOverrideData(ip="ip_value"), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + recaptchaenterprise.ListIpOverridesRequest, + dict, + ], +) +def test_list_ip_overrides(request_type, transport: str = "grpc"): + client = RecaptchaEnterpriseServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_ip_overrides), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = recaptchaenterprise.ListIpOverridesResponse( + next_page_token="next_page_token_value", + ) + response = client.list_ip_overrides(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + request = recaptchaenterprise.ListIpOverridesRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListIpOverridesPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_ip_overrides_non_empty_request_with_auto_populated_field(): + # This test is a coverage failsafe to make sure that UUID4 fields are + # automatically populated, according to AIP-4235, with non-empty requests. + client = RecaptchaEnterpriseServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Populate all string fields in the request which are not UUID4 + # since we want to check that UUID4 are populated automatically + # if they meet the requirements of AIP 4235. + request = recaptchaenterprise.ListIpOverridesRequest( + parent="parent_value", + page_token="page_token_value", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_ip_overrides), "__call__" + ) as call: + call.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client.list_ip_overrides(request=request) + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == recaptchaenterprise.ListIpOverridesRequest( + parent="parent_value", + page_token="page_token_value", + ) + + +def test_list_ip_overrides_use_cached_wrapped_rpc(): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method.wrap_method") as wrapper_fn: + client = RecaptchaEnterpriseServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert client._transport.list_ip_overrides in client._transport._wrapped_methods + + # Replace cached wrapped function with mock + mock_rpc = mock.Mock() + mock_rpc.return_value.name = ( + "foo" # operation_request.operation in compute client(s) expect a string. + ) + client._transport._wrapped_methods[ + client._transport.list_ip_overrides + ] = mock_rpc + request = {} + client.list_ip_overrides(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + client.list_ip_overrides(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +@pytest.mark.asyncio +async def test_list_ip_overrides_async_use_cached_wrapped_rpc( + transport: str = "grpc_asyncio", +): + # Clients should use _prep_wrapped_messages to create cached wrapped rpcs, + # instead of constructing them on each call + with mock.patch("google.api_core.gapic_v1.method_async.wrap_method") as wrapper_fn: + client = RecaptchaEnterpriseServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Should wrap all calls on client creation + assert wrapper_fn.call_count > 0 + wrapper_fn.reset_mock() + + # Ensure method has been cached + assert ( + client._client._transport.list_ip_overrides + in client._client._transport._wrapped_methods + ) + + # Replace cached wrapped function with mock + mock_rpc = mock.AsyncMock() + mock_rpc.return_value = mock.Mock() + client._client._transport._wrapped_methods[ + client._client._transport.list_ip_overrides + ] = mock_rpc + + request = {} + await client.list_ip_overrides(request) + + # Establish that the underlying gRPC stub method was called. + assert mock_rpc.call_count == 1 + + await client.list_ip_overrides(request) + + # Establish that a new wrapper was not created for this call + assert wrapper_fn.call_count == 0 + assert mock_rpc.call_count == 2 + + +@pytest.mark.asyncio +async def test_list_ip_overrides_async( + transport: str = "grpc_asyncio", + request_type=recaptchaenterprise.ListIpOverridesRequest, +): + client = RecaptchaEnterpriseServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_ip_overrides), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + recaptchaenterprise.ListIpOverridesResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_ip_overrides(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + request = recaptchaenterprise.ListIpOverridesRequest() + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListIpOverridesAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_ip_overrides_async_from_dict(): + await test_list_ip_overrides_async(request_type=dict) + + +def test_list_ip_overrides_field_headers(): + client = RecaptchaEnterpriseServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = recaptchaenterprise.ListIpOverridesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_ip_overrides), "__call__" + ) as call: + call.return_value = recaptchaenterprise.ListIpOverridesResponse() + client.list_ip_overrides(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_ip_overrides_field_headers_async(): + client = RecaptchaEnterpriseServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = recaptchaenterprise.ListIpOverridesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_ip_overrides), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + recaptchaenterprise.ListIpOverridesResponse() + ) + await client.list_ip_overrides(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_ip_overrides_flattened(): + client = RecaptchaEnterpriseServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_ip_overrides), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = recaptchaenterprise.ListIpOverridesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_ip_overrides( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_ip_overrides_flattened_error(): + client = RecaptchaEnterpriseServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_ip_overrides( + recaptchaenterprise.ListIpOverridesRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_ip_overrides_flattened_async(): + client = RecaptchaEnterpriseServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_ip_overrides), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = recaptchaenterprise.ListIpOverridesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + recaptchaenterprise.ListIpOverridesResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_ip_overrides( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_ip_overrides_flattened_error_async(): + client = RecaptchaEnterpriseServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_ip_overrides( + recaptchaenterprise.ListIpOverridesRequest(), + parent="parent_value", + ) + + +def test_list_ip_overrides_pager(transport_name: str = "grpc"): + client = RecaptchaEnterpriseServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_ip_overrides), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + recaptchaenterprise.ListIpOverridesResponse( + ip_overrides=[ + recaptchaenterprise.IpOverrideData(), + recaptchaenterprise.IpOverrideData(), + recaptchaenterprise.IpOverrideData(), + ], + next_page_token="abc", + ), + recaptchaenterprise.ListIpOverridesResponse( + ip_overrides=[], + next_page_token="def", + ), + recaptchaenterprise.ListIpOverridesResponse( + ip_overrides=[ + recaptchaenterprise.IpOverrideData(), + ], + next_page_token="ghi", + ), + recaptchaenterprise.ListIpOverridesResponse( + ip_overrides=[ + recaptchaenterprise.IpOverrideData(), + recaptchaenterprise.IpOverrideData(), + ], + ), + RuntimeError, + ) + + expected_metadata = () + retry = retries.Retry() + timeout = 5 + expected_metadata = tuple(expected_metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_ip_overrides(request={}, retry=retry, timeout=timeout) + + assert pager._metadata == expected_metadata + assert pager._retry == retry + assert pager._timeout == timeout + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, recaptchaenterprise.IpOverrideData) for i in results) + + +def test_list_ip_overrides_pages(transport_name: str = "grpc"): + client = RecaptchaEnterpriseServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_ip_overrides), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + recaptchaenterprise.ListIpOverridesResponse( + ip_overrides=[ + recaptchaenterprise.IpOverrideData(), + recaptchaenterprise.IpOverrideData(), + recaptchaenterprise.IpOverrideData(), + ], + next_page_token="abc", + ), + recaptchaenterprise.ListIpOverridesResponse( + ip_overrides=[], + next_page_token="def", + ), + recaptchaenterprise.ListIpOverridesResponse( + ip_overrides=[ + recaptchaenterprise.IpOverrideData(), + ], + next_page_token="ghi", + ), + recaptchaenterprise.ListIpOverridesResponse( + ip_overrides=[ + recaptchaenterprise.IpOverrideData(), + recaptchaenterprise.IpOverrideData(), + ], + ), + RuntimeError, + ) + pages = list(client.list_ip_overrides(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_ip_overrides_async_pager(): + client = RecaptchaEnterpriseServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_ip_overrides), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + recaptchaenterprise.ListIpOverridesResponse( + ip_overrides=[ + recaptchaenterprise.IpOverrideData(), + recaptchaenterprise.IpOverrideData(), + recaptchaenterprise.IpOverrideData(), + ], + next_page_token="abc", + ), + recaptchaenterprise.ListIpOverridesResponse( + ip_overrides=[], + next_page_token="def", + ), + recaptchaenterprise.ListIpOverridesResponse( + ip_overrides=[ + recaptchaenterprise.IpOverrideData(), + ], + next_page_token="ghi", + ), + recaptchaenterprise.ListIpOverridesResponse( + ip_overrides=[ + recaptchaenterprise.IpOverrideData(), + recaptchaenterprise.IpOverrideData(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_ip_overrides( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, recaptchaenterprise.IpOverrideData) for i in responses) + + +@pytest.mark.asyncio +async def test_list_ip_overrides_async_pages(): + client = RecaptchaEnterpriseServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_ip_overrides), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + recaptchaenterprise.ListIpOverridesResponse( + ip_overrides=[ + recaptchaenterprise.IpOverrideData(), + recaptchaenterprise.IpOverrideData(), + recaptchaenterprise.IpOverrideData(), + ], + next_page_token="abc", + ), + recaptchaenterprise.ListIpOverridesResponse( + ip_overrides=[], + next_page_token="def", + ), + recaptchaenterprise.ListIpOverridesResponse( + ip_overrides=[ + recaptchaenterprise.IpOverrideData(), + ], + next_page_token="ghi", + ), + recaptchaenterprise.ListIpOverridesResponse( + ip_overrides=[ + recaptchaenterprise.IpOverrideData(), + recaptchaenterprise.IpOverrideData(), + ], + ), + RuntimeError, + ) + pages = [] + # Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch` + # See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372 + async for page_ in ( # pragma: no branch + await client.list_ip_overrides(request={}) + ).pages: + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + @pytest.mark.parametrize( "request_type", [ @@ -9253,6 +10143,52 @@ def test_add_ip_override_empty_call_grpc(): assert args[0] == request_msg +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_remove_ip_override_empty_call_grpc(): + client = RecaptchaEnterpriseServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.remove_ip_override), "__call__" + ) as call: + call.return_value = recaptchaenterprise.RemoveIpOverrideResponse() + client.remove_ip_override(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = recaptchaenterprise.RemoveIpOverrideRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +def test_list_ip_overrides_empty_call_grpc(): + client = RecaptchaEnterpriseServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_ip_overrides), "__call__" + ) as call: + call.return_value = recaptchaenterprise.ListIpOverridesResponse() + client.list_ip_overrides(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = recaptchaenterprise.ListIpOverridesRequest() + + assert args[0] == request_msg + + # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. def test_get_metrics_empty_call_grpc(): @@ -9771,6 +10707,62 @@ async def test_add_ip_override_empty_call_grpc_asyncio(): assert args[0] == request_msg +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_remove_ip_override_empty_call_grpc_asyncio(): + client = RecaptchaEnterpriseServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.remove_ip_override), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + recaptchaenterprise.RemoveIpOverrideResponse() + ) + await client.remove_ip_override(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = recaptchaenterprise.RemoveIpOverrideRequest() + + assert args[0] == request_msg + + +# This test is a coverage failsafe to make sure that totally empty calls, +# i.e. request == None and no flattened fields passed, work. +@pytest.mark.asyncio +async def test_list_ip_overrides_empty_call_grpc_asyncio(): + client = RecaptchaEnterpriseServiceAsyncClient( + credentials=async_anonymous_credentials(), + transport="grpc_asyncio", + ) + + # Mock the actual call, and fake the request. + with mock.patch.object( + type(client.transport.list_ip_overrides), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + recaptchaenterprise.ListIpOverridesResponse( + next_page_token="next_page_token_value", + ) + ) + await client.list_ip_overrides(request=None) + + # Establish that the underlying stub method was called. + call.assert_called() + _, args, _ = call.mock_calls[0] + request_msg = recaptchaenterprise.ListIpOverridesRequest() + + assert args[0] == request_msg + + # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. @pytest.mark.asyncio @@ -10105,6 +11097,8 @@ def test_recaptcha_enterprise_service_base_transport(): "delete_key", "migrate_key", "add_ip_override", + "remove_ip_override", + "list_ip_overrides", "get_metrics", "create_firewall_policy", "list_firewall_policies",