def test_flatten_repeated_list(): obj = { "a": { "b": { "c": [["e", "f"], ["g", "h"]] } }, "d": "uvw", } with pytest.raises(ValueError): rest_helpers.flatten_query_params(obj)
def test_flatten_repeated_dict(): obj = { "a": { "b": { "c": [{ "v": 1 }, { "v": 2 }] } }, "d": "uvw", } with pytest.raises(ValueError): rest_helpers.flatten_query_params(obj)
def __call__( self, request: logging_metrics.DeleteLogMetricRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ): r"""Call the delete log metric method over HTTP. Args: request (~.logging_metrics.DeleteLogMetricRequest): The request object. The parameters to DeleteLogMetric. 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. """ http_options: List[Dict[str, str]] = [ { 'method': 'delete', 'uri': '/v2/{metric_name=projects/*/metrics/*}', }, ] request, metadata = self._interceptor.pre_delete_log_metric( request, metadata) request_kwargs = logging_metrics.DeleteLogMetricRequest.to_dict( request) transcoded_request = path_template.transcode( http_options, **request_kwargs) uri = transcoded_request['uri'] method = transcoded_request['method'] # Jsonify the query params query_params = json.loads( logging_metrics.DeleteLogMetricRequest.to_json( logging_metrics.DeleteLogMetricRequest( transcoded_request['query_params']), including_default_value_fields=False, use_integers_for_enums=False)) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers['Content-Type'] = 'application/json' response = getattr(self._session, method)( "{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response)
def test_flatten_simple_dict(): assert rest_helpers.flatten_query_params({ "a": "abc", "b": "def" }) == [ ("a", "abc"), ("b", "def"), ]
def __call__( self, request: compute.GetHealthCheckRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.HealthCheck: r"""Call the get method over HTTP. Args: request (~.compute.GetHealthCheckRequest): The request object. A request message for HealthChecks.Get. See the method description for details. 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: ~.compute.HealthCheck: Represents a Health Check resource. Google Compute Engine has two Health Check resources: \* `Global </compute/docs/reference/rest/v1/healthChecks>`__ \* `Regional </compute/docs/reference/rest/v1/regionHealthChecks>`__ Internal HTTP(S) load balancers must use regional health checks (``compute.v1.regionHealthChecks``). Traffic Director must use global health checks (``compute.v1.HealthChecks``). Internal TCP/UDP load balancers can use either regional or global health checks (``compute.v1.regionHealthChecks`` or ``compute.v1.HealthChecks``). External HTTP(S), TCP proxy, and SSL proxy load balancers as well as managed instance group auto-healing must use global health checks (``compute.v1.HealthChecks``). Backend service-based network load balancers must use regional health checks (``compute.v1.regionHealthChecks``). Target pool-based network load balancers must use legacy HTTP health checks (``compute.v1.httpHealthChecks``). For more information, see Health checks overview. """ http_options = [ { "method": "get", "uri": "/compute/v1/projects/{project}/global/healthChecks/{health_check}", }, ] request_kwargs = compute.GetHealthCheckRequest.to_dict(request) transcoded_request = path_template.transcode( http_options, **request_kwargs) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.GetHealthCheckRequest.to_json( compute.GetHealthCheckRequest( transcoded_request["query_params"]), including_default_value_fields=False, use_integers_for_enums=False, )) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.HealthCheck.from_json(response.content, ignore_unknown_fields=True)
def __call__( self, request: compute.GetGlobalForwardingRuleRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.ForwardingRule: r"""Call the get method over HTTP. Args: request (~.compute.GetGlobalForwardingRuleRequest): The request object. A request message for GlobalForwardingRules.Get. See the method description for details. 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: ~.compute.ForwardingRule: Represents a Forwarding Rule resource. Forwarding rule resources in Google Cloud can be either regional or global in scope: \* `Global <https://cloud.google.com/compute/docs/reference/rest/v1/globalForwardingRules>`__ \* `Regional <https://cloud.google.com/compute/docs/reference/rest/v1/forwardingRules>`__ A forwarding rule and its corresponding IP address represent the frontend configuration of a Google Cloud Platform load balancer. Forwarding rules can also reference target instances and Cloud VPN Classic gateways (targetVpnGateway). For more information, read Forwarding rule concepts and Using protocol forwarding. """ http_options = [ { "method": "get", "uri": "/compute/v1/projects/{project}/global/forwardingRules/{forwarding_rule}", }, ] request_kwargs = compute.GetGlobalForwardingRuleRequest.to_dict( request) transcoded_request = path_template.transcode( http_options, **request_kwargs) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.GetGlobalForwardingRuleRequest.to_json( compute.GetGlobalForwardingRuleRequest( transcoded_request["query_params"]), including_default_value_fields=False, use_integers_for_enums=False, )) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.ForwardingRule.from_json(response.content, ignore_unknown_fields=True)
def __call__( self, request: compute.GetRegionTargetHttpsProxyRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.TargetHttpsProxy: r"""Call the get method over HTTP. Args: request (~.compute.GetRegionTargetHttpsProxyRequest): The request object. A request message for RegionTargetHttpsProxies.Get. See the method description for details. 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: ~.compute.TargetHttpsProxy: Represents a Target HTTPS Proxy resource. Google Compute Engine has two Target HTTPS Proxy resources: \* `Global </compute/docs/reference/rest/v1/targetHttpsProxies>`__ \* `Regional </compute/docs/reference/rest/v1/regionTargetHttpsProxies>`__ A target HTTPS proxy is a component of GCP HTTPS load balancers. \* targetHttpsProxies are used by external HTTPS load balancers. \* regionTargetHttpsProxies are used by internal HTTPS load balancers. Forwarding rules reference a target HTTPS proxy, and the target proxy then references a URL map. For more information, read Using Target Proxies and Forwarding rule concepts. """ http_options = [ { "method": "get", "uri": "/compute/v1/projects/{project}/regions/{region}/targetHttpsProxies/{target_https_proxy}", }, ] request_kwargs = compute.GetRegionTargetHttpsProxyRequest.to_dict( request) transcoded_request = path_template.transcode( http_options, **request_kwargs) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.GetRegionTargetHttpsProxyRequest.to_json( compute.GetRegionTargetHttpsProxyRequest( transcoded_request["query_params"]), including_default_value_fields=False, use_integers_for_enums=False, )) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.TargetHttpsProxy.from_json( response.content, ignore_unknown_fields=True)
def __call__( self, request: compute.GetRegionBackendServiceRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.BackendService: r"""Call the get method over HTTP. Args: request (~.compute.GetRegionBackendServiceRequest): The request object. A request message for RegionBackendServices.Get. See the method description for details. 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: ~.compute.BackendService: Represents a Backend Service resource. A backend service defines how Google Cloud load balancers distribute traffic. The backend service configuration contains a set of values, such as the protocol used to connect to backends, various distribution and session settings, health checks, and timeouts. These settings provide fine-grained control over how your load balancer behaves. Most of the settings have default values that allow for easy configuration if you need to get started quickly. Backend services in Google Compute Engine can be either regionally or globally scoped. \* `Global <https://cloud.google.com/compute/docs/reference/rest/v1/backendServices>`__ \* `Regional <https://cloud.google.com/compute/docs/reference/rest/v1/regionBackendServices>`__ For more information, see Backend Services. """ http_options = [ { "method": "get", "uri": "/compute/v1/projects/{project}/regions/{region}/backendServices/{backend_service}", }, ] request_kwargs = compute.GetRegionBackendServiceRequest.to_dict( request) transcoded_request = path_template.transcode( http_options, **request_kwargs) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.GetRegionBackendServiceRequest.to_json( compute.GetRegionBackendServiceRequest( transcoded_request["query_params"]), including_default_value_fields=False, use_integers_for_enums=False, )) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.BackendService.from_json(response.content, ignore_unknown_fields=True)
def __call__( self, request: compute.GetRegionSslCertificateRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.SslCertificate: r"""Call the get method over HTTP. Args: request (~.compute.GetRegionSslCertificateRequest): The request object. A request message for RegionSslCertificates.Get. See the method description for details. 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: ~.compute.SslCertificate: Represents an SSL Certificate resource. Google Compute Engine has two SSL Certificate resources: \* `Global </compute/docs/reference/rest/v1/sslCertificates>`__ \* `Regional </compute/docs/reference/rest/v1/regionSslCertificates>`__ The sslCertificates are used by: - external HTTPS load balancers - SSL proxy load balancers The regionSslCertificates are used by internal HTTPS load balancers. Optionally, certificate file contents that you upload can contain a set of up to five PEM-encoded certificates. The API call creates an object (sslCertificate) that holds this data. You can use SSL keys and certificates to secure connections to a load balancer. For more information, read Creating and using SSL certificates, SSL certificates quotas and limits, and Troubleshooting SSL certificates. """ http_options = [ { "method": "get", "uri": "/compute/v1/projects/{project}/regions/{region}/sslCertificates/{ssl_certificate}", }, ] request_kwargs = compute.GetRegionSslCertificateRequest.to_dict( request) transcoded_request = path_template.transcode( http_options, **request_kwargs) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.GetRegionSslCertificateRequest.to_json( compute.GetRegionSslCertificateRequest( transcoded_request["query_params"]), including_default_value_fields=False, use_integers_for_enums=False, )) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.SslCertificate.from_json(response.content, ignore_unknown_fields=True)
def __call__( self, request: compute.GetGlobalPublicDelegatedPrefixeRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.PublicDelegatedPrefix: r"""Call the get method over HTTP. Args: request (~.compute.GetGlobalPublicDelegatedPrefixeRequest): The request object. A request message for GlobalPublicDelegatedPrefixes.Get. See the method description for details. 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: ~.compute.PublicDelegatedPrefix: A PublicDelegatedPrefix resource represents an IP block within a PublicAdvertisedPrefix that is configured within a single cloud scope (global or region). IPs in the block can be allocated to resources within that scope. Public delegated prefixes may be further broken up into smaller IP blocks in the same scope as the parent block. """ http_options = [ { "method": "get", "uri": "/compute/v1/projects/{project}/global/publicDelegatedPrefixes/{public_delegated_prefix}", }, ] request_kwargs = compute.GetGlobalPublicDelegatedPrefixeRequest.to_dict( request ) transcoded_request = path_template.transcode(http_options, **request_kwargs) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.GetGlobalPublicDelegatedPrefixeRequest.to_json( compute.GetGlobalPublicDelegatedPrefixeRequest( transcoded_request["query_params"] ), including_default_value_fields=False, use_integers_for_enums=False, ) ) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.PublicDelegatedPrefix.from_json( response.content, ignore_unknown_fields=True )
def test_flatten_empty_dict(): assert rest_helpers.flatten_query_params({}) == []
def test_flatten_none(): assert rest_helpers.flatten_query_params(None) == []
def test_flatten_list(): with pytest.raises(TypeError): rest_helpers.flatten_query_params(["abc", "def"])
def test_flatten_simple_value(): with pytest.raises(TypeError): rest_helpers.flatten_query_params("abc")
def __call__( self, request: compute.GetVpnGatewayRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.VpnGateway: r"""Call the get method over HTTP. Args: request (~.compute.GetVpnGatewayRequest): The request object. A request message for VpnGateways.Get. See the method description for details. 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: ~.compute.VpnGateway: Represents a HA VPN gateway. HA VPN is a high-availability (HA) Cloud VPN solution that lets you securely connect your on-premises network to your Google Cloud Virtual Private Cloud network through an IPsec VPN connection in a single region. For more information about Cloud HA VPN solutions, see Cloud VPN topologies . """ http_options = [ { "method": "get", "uri": "/compute/v1/projects/{project}/regions/{region}/vpnGateways/{vpn_gateway}", }, ] request_kwargs = compute.GetVpnGatewayRequest.to_dict(request) transcoded_request = path_template.transcode( http_options, **request_kwargs) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.GetVpnGatewayRequest.to_json( compute.GetVpnGatewayRequest( transcoded_request["query_params"]), including_default_value_fields=False, use_integers_for_enums=False, )) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.VpnGateway.from_json(response.content, ignore_unknown_fields=True)
def __call__( self, request: compute.GetPacketMirroringRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.PacketMirroring: r"""Call the get method over HTTP. Args: request (~.compute.GetPacketMirroringRequest): The request object. A request message for PacketMirrorings.Get. See the method description for details. 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: ~.compute.PacketMirroring: Represents a Packet Mirroring resource. Packet Mirroring clones the traffic of specified instances in your Virtual Private Cloud (VPC) network and forwards it to a collector destination, such as an instance group of an internal TCP/UDP load balancer, for analysis or examination. For more information about setting up Packet Mirroring, see Using Packet Mirroring. """ http_options = [ { "method": "get", "uri": "/compute/v1/projects/{project}/regions/{region}/packetMirrorings/{packet_mirroring}", }, ] request_kwargs = compute.GetPacketMirroringRequest.to_dict(request) transcoded_request = path_template.transcode( http_options, **request_kwargs) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.GetPacketMirroringRequest.to_json( compute.GetPacketMirroringRequest( transcoded_request["query_params"]), including_default_value_fields=False, use_integers_for_enums=False, )) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.PacketMirroring.from_json( response.content, ignore_unknown_fields=True)
def __call__( self, request: logging_metrics.UpdateLogMetricRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> logging_metrics.LogMetric: r"""Call the update log metric method over HTTP. Args: request (~.logging_metrics.UpdateLogMetricRequest): The request object. The parameters to UpdateLogMetric. 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: ~.logging_metrics.LogMetric: Describes a logs-based metric. The value of the metric is the number of log entries that match a logs filter in a given time interval. Logs-based metrics can also be used to extract values from logs and create a distribution of the values. The distribution records the statistics of the extracted values along with an optional histogram of the values as specified by the bucket options. """ http_options: List[Dict[str, str]] = [ { 'method': 'put', 'uri': '/v2/{metric_name=projects/*/metrics/*}', 'body': 'metric', }, ] request, metadata = self._interceptor.pre_update_log_metric( request, metadata) request_kwargs = logging_metrics.UpdateLogMetricRequest.to_dict( request) transcoded_request = path_template.transcode( http_options, **request_kwargs) # Jsonify the request body body = logging_metrics.LogMetric.to_json( logging_metrics.LogMetric(transcoded_request['body']), including_default_value_fields=False, use_integers_for_enums=False) uri = transcoded_request['uri'] method = transcoded_request['method'] # Jsonify the query params query_params = json.loads( logging_metrics.UpdateLogMetricRequest.to_json( logging_metrics.UpdateLogMetricRequest( transcoded_request['query_params']), including_default_value_fields=False, use_integers_for_enums=False)) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers['Content-Type'] = 'application/json' response = getattr(self._session, method)( "{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), data=body, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response resp = logging_metrics.LogMetric.from_json( response.content, ignore_unknown_fields=True) resp = self._interceptor.post_update_log_metric(resp) return resp
def __call__( self, request: logging.ListMonitoredResourceDescriptorsRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> logging.ListMonitoredResourceDescriptorsResponse: r"""Call the list monitored resource descriptors method over HTTP. Args: request (~.logging.ListMonitoredResourceDescriptorsRequest): The request object. The parameters to ListMonitoredResourceDescriptors 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: ~.logging.ListMonitoredResourceDescriptorsResponse: Result returned from ListMonitoredResourceDescriptors. """ http_options: List[Dict[str, str]] = [ { 'method': 'get', 'uri': '/v2/monitoredResourceDescriptors', }, ] request, metadata = self._interceptor.pre_list_monitored_resource_descriptors( request, metadata) request_kwargs = logging.ListMonitoredResourceDescriptorsRequest.to_dict( request) transcoded_request = path_template.transcode( http_options, **request_kwargs) uri = transcoded_request['uri'] method = transcoded_request['method'] # Jsonify the query params query_params = json.loads( logging.ListMonitoredResourceDescriptorsRequest.to_json( logging.ListMonitoredResourceDescriptorsRequest( transcoded_request['query_params']), including_default_value_fields=False, use_integers_for_enums=False)) # Send the request headers = dict(metadata) headers['Content-Type'] = 'application/json' response = getattr(self._session, method)( "{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response resp = logging.ListMonitoredResourceDescriptorsResponse.from_json( response.content, ignore_unknown_fields=True) resp = self._interceptor.post_list_monitored_resource_descriptors( resp) return resp
def __call__( self, request: compute.GetRegionInstanceGroupRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.InstanceGroup: r"""Call the get method over HTTP. Args: request (~.compute.GetRegionInstanceGroupRequest): The request object. A request message for RegionInstanceGroups.Get. See the method description for details. 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: ~.compute.InstanceGroup: Represents an Instance Group resource. Instance Groups can be used to configure a target for load balancing. Instance groups can either be managed or unmanaged. To create managed instance groups, use the instanceGroupManager or regionInstanceGroupManager resource instead. Use zonal unmanaged instance groups if you need to apply load balancing to groups of heterogeneous instances or if you need to manage the instances yourself. You cannot create regional unmanaged instance groups. For more information, read Instance groups. """ http_options = [ { "method": "get", "uri": "/compute/v1/projects/{project}/regions/{region}/instanceGroups/{instance_group}", }, ] request_kwargs = compute.GetRegionInstanceGroupRequest.to_dict(request) transcoded_request = path_template.transcode(http_options, **request_kwargs) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.GetRegionInstanceGroupRequest.to_json( compute.GetRegionInstanceGroupRequest( transcoded_request["query_params"] ), including_default_value_fields=False, use_integers_for_enums=False, ) ) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.InstanceGroup.from_json( response.content, ignore_unknown_fields=True )
def test_flatten_repeated_field(): assert rest_helpers.flatten_query_params({"a": ["x", "y", "z", None]}) == [ ("a", "x"), ("a", "y"), ("a", "z"), ]
def __call__( self, request: compute.GetNodeTypeRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.NodeType: r"""Call the get method over HTTP. Args: request (~.compute.GetNodeTypeRequest): The request object. A request message for NodeTypes.Get. See the method description for details. 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: ~.compute.NodeType: Represent a sole-tenant Node Type resource. Each node within a node group must have a node type. A node type specifies the total amount of cores and memory for that node. Currently, the only available node type is n1-node-96-624 node type that has 96 vCPUs and 624 GB of memory, available in multiple zones. For more information read Node types. """ http_options = [ { "method": "get", "uri": "/compute/v1/projects/{project}/zones/{zone}/nodeTypes/{node_type}", }, ] request_kwargs = compute.GetNodeTypeRequest.to_dict(request) transcoded_request = path_template.transcode(http_options, **request_kwargs) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.GetNodeTypeRequest.to_json( compute.GetNodeTypeRequest(transcoded_request["query_params"]), including_default_value_fields=False, use_integers_for_enums=False, ) ) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.NodeType.from_json( response.content, ignore_unknown_fields=True )
def test_flatten_nested_dict(): obj = {"a": {"b": {"c": ["x", "y", "z"]}}, "d": {"e": "uvw"}} expected_result = [("a.b.c", "x"), ("a.b.c", "y"), ("a.b.c", "z"), ("d.e", "uvw")] assert rest_helpers.flatten_query_params(obj) == expected_result
def __call__( self, request: compute.SetIamPolicyReservationRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.Policy: r"""Call the set iam policy method over HTTP. Args: request (~.compute.SetIamPolicyReservationRequest): The request object. A request message for Reservations.SetIamPolicy. See the method description for details. 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: ~.compute.Policy: An Identity and Access Management (IAM) policy, which specifies access controls for Google Cloud resources. A ``Policy`` is a collection of ``bindings``. A ``binding`` binds one or more ``members`` to a single ``role``. Members can be user accounts, service accounts, Google groups, and domains (such as G Suite). A ``role`` is a named list of permissions; each ``role`` can be an IAM predefined role or a user-created custom role. For some types of Google Cloud resources, a ``binding`` can also specify a ``condition``, which is a logical expression that allows access to a resource only if the expression evaluates to ``true``. A condition can add constraints based on attributes of the request, the resource, or both. To learn which resources support conditions in their IAM policies, see the `IAM documentation <https://cloud.google.com/iam/help/conditions/resource-policies>`__. **JSON example:** { "bindings": [ { "role": "roles/resourcemanager.organizationAdmin", "members": [ "user:[email protected]", "group:[email protected]", "domain:google.com", "serviceAccount:[email protected]" ] }, { "role": "roles/resourcemanager.organizationViewer", "members": [ "user:[email protected]" ], "condition": { "title": "expirable access", "description": "Does not grant access after Sep 2020", "expression": "request.time < timestamp('2020-10-01T00:00:00.000Z')", } } ], "etag": "BwWWja0YfJA=", "version": 3 } **YAML example:** bindings: - members: - user:[email protected] - group:[email protected] - domain:google.com - serviceAccount:[email protected] role: roles/resourcemanager.organizationAdmin - members: - user:[email protected] role: roles/resourcemanager.organizationViewer condition: title: expirable access description: Does not grant access after Sep 2020 expression: request.time < timestamp('2020-10-01T00:00:00.000Z') etag: BwWWja0YfJA= version: 3 For a description of IAM and its features, see the `IAM documentation <https://cloud.google.com/iam/docs/>`__. """ http_options = [ { "method": "post", "uri": "/compute/v1/projects/{project}/zones/{zone}/reservations/{resource}/setIamPolicy", "body": "zone_set_policy_request_resource", }, ] request_kwargs = compute.SetIamPolicyReservationRequest.to_dict(request) transcoded_request = path_template.transcode(http_options, **request_kwargs) # Jsonify the request body body = compute.ZoneSetPolicyRequest.to_json( compute.ZoneSetPolicyRequest(transcoded_request["body"]), including_default_value_fields=False, use_integers_for_enums=False, ) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.SetIamPolicyReservationRequest.to_json( compute.SetIamPolicyReservationRequest( transcoded_request["query_params"] ), including_default_value_fields=False, use_integers_for_enums=False, ) ) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), data=body, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.Policy.from_json( response.content, ignore_unknown_fields=True )
def __call__( self, request: compute.SetLabelsExternalVpnGatewayRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.Operation: r"""Call the set labels method over HTTP. Args: request (~.compute.SetLabelsExternalVpnGatewayRequest): The request object. A request message for ExternalVpnGateways.SetLabels. See the method description for details. 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: ~.compute.Operation: Represents an Operation resource. Google Compute Engine has three Operation resources: \* `Global </compute/docs/reference/rest/v1/globalOperations>`__ \* `Regional </compute/docs/reference/rest/v1/regionOperations>`__ \* `Zonal </compute/docs/reference/rest/v1/zoneOperations>`__ You can use an operation resource to manage asynchronous API requests. For more information, read Handling API responses. Operations can be global, regional or zonal. - For global operations, use the ``globalOperations`` resource. - For regional operations, use the ``regionOperations`` resource. - For zonal operations, use the ``zonalOperations`` resource. For more information, read Global, Regional, and Zonal Resources. """ http_options = [ { "method": "post", "uri": "/compute/v1/projects/{project}/global/externalVpnGateways/{resource}/setLabels", "body": "global_set_labels_request_resource", }, ] request_kwargs = compute.SetLabelsExternalVpnGatewayRequest.to_dict(request) transcoded_request = path_template.transcode(http_options, **request_kwargs) # Jsonify the request body body = compute.GlobalSetLabelsRequest.to_json( compute.GlobalSetLabelsRequest(transcoded_request["body"]), including_default_value_fields=False, use_integers_for_enums=False, ) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.SetLabelsExternalVpnGatewayRequest.to_json( compute.SetLabelsExternalVpnGatewayRequest( transcoded_request["query_params"] ), including_default_value_fields=False, use_integers_for_enums=False, ) ) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), data=body, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.Operation.from_json( response.content, ignore_unknown_fields=True )
def __call__( self, request: compute.GetZoneRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.Zone: r"""Call the get method over HTTP. Args: request (~.compute.GetZoneRequest): The request object. A request message for Zones.Get. See the method description for details. 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: ~.compute.Zone: Represents a Zone resource. A zone is a deployment area. These deployment areas are subsets of a region. For example the zone us-east1-a is located in the us-east1 region. For more information, read Regions and Zones. """ http_options = [ { "method": "get", "uri": "/compute/v1/projects/{project}/zones/{zone}", }, ] request_kwargs = compute.GetZoneRequest.to_dict(request) transcoded_request = path_template.transcode( http_options, **request_kwargs) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.GetZoneRequest.to_json( compute.GetZoneRequest(transcoded_request["query_params"]), including_default_value_fields=False, use_integers_for_enums=False, )) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.Zone.from_json(response.content, ignore_unknown_fields=True)
def __call__( self, request: compute.GetServiceAttachmentRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.ServiceAttachment: r"""Call the get method over HTTP. Args: request (~.compute.GetServiceAttachmentRequest): The request object. A request message for ServiceAttachments.Get. See the method description for details. 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: ~.compute.ServiceAttachment: Represents a ServiceAttachment resource. A service attachment represents a service that a producer has exposed. It encapsulates the load balancer which fronts the service runs and a list of NAT IP ranges that the producers uses to represent the consumers connecting to the service. next tag = 20 """ http_options = [ { "method": "get", "uri": "/compute/v1/projects/{project}/regions/{region}/serviceAttachments/{service_attachment}", }, ] request_kwargs = compute.GetServiceAttachmentRequest.to_dict(request) transcoded_request = path_template.transcode(http_options, **request_kwargs) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.GetServiceAttachmentRequest.to_json( compute.GetServiceAttachmentRequest( transcoded_request["query_params"] ), including_default_value_fields=False, use_integers_for_enums=False, ) ) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.ServiceAttachment.from_json( response.content, ignore_unknown_fields=True )
def __call__( self, request: compute.GetExternalVpnGatewayRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.ExternalVpnGateway: r"""Call the get method over HTTP. Args: request (~.compute.GetExternalVpnGatewayRequest): The request object. A request message for ExternalVpnGateways.Get. See the method description for details. 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: ~.compute.ExternalVpnGateway: Represents an external VPN gateway. External VPN gateway is the on-premises VPN gateway(s) or another cloud provider's VPN gateway that connects to your Google Cloud VPN gateway. To create a highly available VPN from Google Cloud Platform to your VPN gateway or another cloud provider's VPN gateway, you must create a external VPN gateway resource with information about the other gateway. For more information about using external VPN gateways, see Creating an HA VPN gateway and tunnel pair to a peer VPN. """ http_options = [ { "method": "get", "uri": "/compute/v1/projects/{project}/global/externalVpnGateways/{external_vpn_gateway}", }, ] request_kwargs = compute.GetExternalVpnGatewayRequest.to_dict(request) transcoded_request = path_template.transcode(http_options, **request_kwargs) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.GetExternalVpnGatewayRequest.to_json( compute.GetExternalVpnGatewayRequest( transcoded_request["query_params"] ), including_default_value_fields=False, use_integers_for_enums=False, ) ) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.ExternalVpnGateway.from_json( response.content, ignore_unknown_fields=True )
def __call__( self, request: compute.GetAutoscalerRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.Autoscaler: r"""Call the get method over HTTP. Args: request (~.compute.GetAutoscalerRequest): The request object. A request message for Autoscalers.Get. See the method description for details. 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: ~.compute.Autoscaler: Represents an Autoscaler resource. Google Compute Engine has two Autoscaler resources: \* `Zonal </compute/docs/reference/rest/v1/autoscalers>`__ \* `Regional </compute/docs/reference/rest/v1/regionAutoscalers>`__ Use autoscalers to automatically add or delete instances from a managed instance group according to your defined autoscaling policy. For more information, read Autoscaling Groups of Instances. For zonal managed instance groups resource, use the autoscaler resource. For regional managed instance groups, use the regionAutoscalers resource. """ http_options = [ { "method": "get", "uri": "/compute/v1/projects/{project}/zones/{zone}/autoscalers/{autoscaler}", }, ] request_kwargs = compute.GetAutoscalerRequest.to_dict(request) transcoded_request = path_template.transcode( http_options, **request_kwargs) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.GetAutoscalerRequest.to_json( compute.GetAutoscalerRequest( transcoded_request["query_params"]), including_default_value_fields=False, use_integers_for_enums=False, )) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.Autoscaler.from_json(response.content, ignore_unknown_fields=True)
def __call__( self, request: compute.TestIamPermissionsExternalVpnGatewayRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> compute.TestPermissionsResponse: r"""Call the test iam permissions method over HTTP. Args: request (~.compute.TestIamPermissionsExternalVpnGatewayRequest): The request object. A request message for ExternalVpnGateways.TestIamPermissions. See the method description for details. 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: ~.compute.TestPermissionsResponse: """ http_options = [ { "method": "post", "uri": "/compute/v1/projects/{project}/global/externalVpnGateways/{resource}/testIamPermissions", "body": "test_permissions_request_resource", }, ] request_kwargs = compute.TestIamPermissionsExternalVpnGatewayRequest.to_dict( request ) transcoded_request = path_template.transcode(http_options, **request_kwargs) # Jsonify the request body body = compute.TestPermissionsRequest.to_json( compute.TestPermissionsRequest(transcoded_request["body"]), including_default_value_fields=False, use_integers_for_enums=False, ) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params = json.loads( compute.TestIamPermissionsExternalVpnGatewayRequest.to_json( compute.TestIamPermissionsExternalVpnGatewayRequest( transcoded_request["query_params"] ), including_default_value_fields=False, use_integers_for_enums=False, ) ) query_params.update(self._get_unset_required_fields(query_params)) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( # Replace with proper schema configuration (http/https) logic "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), data=body, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response return compute.TestPermissionsResponse.from_json( response.content, ignore_unknown_fields=True )
def _cancel_operation( self, request: operations_pb2.CancelOperationRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = (), ) -> empty_pb2.Empty: r"""Call the cancel operation method over HTTP. Args: request (~.operations_pb2.CancelOperationRequest): The request object. The request message for [Operations.CancelOperation][google.api_core.operations_v1.Operations.CancelOperation]. 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. """ http_options = [ { "method": "post", "uri": "/v1/{name=operations/**}:cancel", "body": "*" }, ] if "google.longrunning.Operations.CancelOperation" in self._http_options: http_options = self._http_options[ "google.longrunning.Operations.CancelOperation"] request_kwargs = json_format.MessageToDict( request, preserving_proto_field_name=True, including_default_value_fields=True, ) transcoded_request = path_template.transcode(http_options, **request_kwargs) # Jsonify the request body body_request = operations_pb2.CancelOperationRequest() json_format.ParseDict(transcoded_request["body"], body_request) body = json_format.MessageToDict( body_request, including_default_value_fields=False, preserving_proto_field_name=False, use_integers_for_enums=False, ) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params_request = operations_pb2.CancelOperationRequest() json_format.ParseDict(transcoded_request["query_params"], query_params_request) query_params = json_format.MessageToDict( query_params_request, including_default_value_fields=False, preserving_proto_field_name=False, use_integers_for_enums=False, ) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), data=body, ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) return empty_pb2.Empty()