Example #1
0
    def test_search_hashes(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = webrisk_pb2.SearchHashesResponse(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = webrisk_v1beta1.WebRiskServiceV1Beta1Client()

        response = client.search_hashes()
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = webrisk_pb2.SearchHashesRequest()
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Example #2
0
    def search_hashes(
        self,
        hash_prefix=None,
        threat_types=None,
        retry=google.api_core.gapic_v1.method.DEFAULT,
        timeout=google.api_core.gapic_v1.method.DEFAULT,
        metadata=None,
    ):
        """
        Gets the full hashes that match the requested hash prefix.
        This is used after a hash prefix is looked up in a threatList
        and there is a match. The client side threatList only holds partial hashes
        so the client must query this method to determine if there is a full
        hash match of a threat.

        Example:
            >>> from google.cloud import webrisk_v1beta1
            >>>
            >>> client = webrisk_v1beta1.WebRiskServiceV1Beta1Client()
            >>>
            >>> response = client.search_hashes()

        Args:
            hash_prefix (bytes): A hash prefix, consisting of the most significant 4-32 bytes of a SHA256
                hash. For JSON requests, this field is base64-encoded.
            threat_types (list[~google.cloud.webrisk_v1beta1.types.ThreatType]): Required. The ThreatLists to search in.
            retry (Optional[google.api_core.retry.Retry]):  A retry object used
                to retry requests. If ``None`` is specified, requests will not
                be retried.
            timeout (Optional[float]): The amount of time, in seconds, to wait
                for the request to complete. Note that if ``retry`` is
                specified, the timeout applies to each individual attempt.
            metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
                that is provided to the method.

        Returns:
            A :class:`~google.cloud.webrisk_v1beta1.types.SearchHashesResponse` instance.

        Raises:
            google.api_core.exceptions.GoogleAPICallError: If the request
                    failed for any reason.
            google.api_core.exceptions.RetryError: If the request failed due
                    to a retryable error and retry attempts failed.
            ValueError: If the parameters are invalid.
        """
        # Wrap the transport method to add retry and timeout logic.
        if "search_hashes" not in self._inner_api_calls:
            self._inner_api_calls[
                "search_hashes"] = google.api_core.gapic_v1.method.wrap_method(
                    self.transport.search_hashes,
                    default_retry=self._method_configs["SearchHashes"].retry,
                    default_timeout=self._method_configs["SearchHashes"].
                    timeout,
                    client_info=self._client_info,
                )

        request = webrisk_pb2.SearchHashesRequest(hash_prefix=hash_prefix,
                                                  threat_types=threat_types)
        return self._inner_api_calls["search_hashes"](request,
                                                      retry=retry,
                                                      timeout=timeout,
                                                      metadata=metadata)