1616
1717from google .auth .transport .requests import AuthorizedSession # type: ignore
1818import json # type: ignore
19- import grpc # type: ignore
20- from google .auth .transport .grpc import SslCredentials # type: ignore
2119from google .auth import credentials as ga_credentials # type: ignore
2220from google .api_core import exceptions as core_exceptions
2321from google .api_core import retry as retries
2422from google .api_core import rest_helpers
2523from google .api_core import rest_streaming
26- from google .api_core import path_template
2724from google .api_core import gapic_v1
2825
2926from google .protobuf import json_format
27+
3028from requests import __version__ as requests_version
3129import dataclasses
32- import re
3330from typing import Any , Callable , Dict , List , Optional , Sequence , Tuple , Union
3431import warnings
3532
36- try :
37- OptionalRetry = Union [retries .Retry , gapic_v1 .method ._MethodDefault , None ]
38- except AttributeError : # pragma: NO COVER
39- OptionalRetry = Union [retries .Retry , object , None ] # type: ignore
40-
4133
4234from google .cloud .errorreporting_v1beta1 .types import common
4335from google .cloud .errorreporting_v1beta1 .types import error_group_service
4436
45- from .base import (
46- ErrorGroupServiceTransport ,
47- DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO ,
48- )
37+
38+ from .rest_base import _BaseErrorGroupServiceRestTransport
39+ from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO
40+
41+ try :
42+ OptionalRetry = Union [retries .Retry , gapic_v1 .method ._MethodDefault , None ]
43+ except AttributeError : # pragma: NO COVER
44+ OptionalRetry = Union [retries .Retry , object , None ] # type: ignore
4945
5046
5147DEFAULT_CLIENT_INFO = gapic_v1 .client_info .ClientInfo (
@@ -142,8 +138,8 @@ class ErrorGroupServiceRestStub:
142138 _interceptor : ErrorGroupServiceRestInterceptor
143139
144140
145- class ErrorGroupServiceRestTransport (ErrorGroupServiceTransport ):
146- """REST backend transport for ErrorGroupService.
141+ class ErrorGroupServiceRestTransport (_BaseErrorGroupServiceRestTransport ):
142+ """REST backend synchronous transport for ErrorGroupService.
147143
148144 Service for retrieving and updating individual error groups.
149145
@@ -152,7 +148,6 @@ class ErrorGroupServiceRestTransport(ErrorGroupServiceTransport):
152148 and call it.
153149
154150 It sends JSON representations of protocol buffers over HTTP/1.1
155-
156151 """
157152
158153 def __init__ (
@@ -206,21 +201,12 @@ def __init__(
206201 # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc.
207202 # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the
208203 # credentials object
209- maybe_url_match = re .match ("^(?P<scheme>http(?:s)?://)?(?P<host>.*)$" , host )
210- if maybe_url_match is None :
211- raise ValueError (
212- f"Unexpected hostname structure: { host } "
213- ) # pragma: NO COVER
214-
215- url_match_items = maybe_url_match .groupdict ()
216-
217- host = f"{ url_scheme } ://{ host } " if not url_match_items ["scheme" ] else host
218-
219204 super ().__init__ (
220205 host = host ,
221206 credentials = credentials ,
222207 client_info = client_info ,
223208 always_use_jwt_access = always_use_jwt_access ,
209+ url_scheme = url_scheme ,
224210 api_audience = api_audience ,
225211 )
226212 self ._session = AuthorizedSession (
@@ -231,19 +217,33 @@ def __init__(
231217 self ._interceptor = interceptor or ErrorGroupServiceRestInterceptor ()
232218 self ._prep_wrapped_messages (client_info )
233219
234- class _GetGroup (ErrorGroupServiceRestStub ):
220+ class _GetGroup (
221+ _BaseErrorGroupServiceRestTransport ._BaseGetGroup , ErrorGroupServiceRestStub
222+ ):
235223 def __hash__ (self ):
236- return hash ("GetGroup" )
237-
238- __REQUIRED_FIELDS_DEFAULT_VALUES : Dict [str , Any ] = {}
239-
240- @classmethod
241- def _get_unset_required_fields (cls , message_dict ):
242- return {
243- k : v
244- for k , v in cls .__REQUIRED_FIELDS_DEFAULT_VALUES .items ()
245- if k not in message_dict
246- }
224+ return hash ("ErrorGroupServiceRestTransport.GetGroup" )
225+
226+ @staticmethod
227+ def _get_response (
228+ host ,
229+ metadata ,
230+ query_params ,
231+ session ,
232+ timeout ,
233+ transcoded_request ,
234+ body = None ,
235+ ):
236+ uri = transcoded_request ["uri" ]
237+ method = transcoded_request ["method" ]
238+ headers = dict (metadata )
239+ headers ["Content-Type" ] = "application/json"
240+ response = getattr (session , method )(
241+ "{host}{uri}" .format (host = host , uri = uri ),
242+ timeout = timeout ,
243+ headers = headers ,
244+ params = rest_helpers .flatten_query_params (query_params , strict = True ),
245+ )
246+ return response
247247
248248 def __call__ (
249249 self ,
@@ -272,42 +272,27 @@ def __call__(
272272
273273 """
274274
275- http_options : List [Dict [str , str ]] = [
276- {
277- "method" : "get" ,
278- "uri" : "/v1beta1/{group_name=projects/*/groups/*}" ,
279- },
280- {
281- "method" : "get" ,
282- "uri" : "/v1beta1/{group_name=projects/*/locations/*/groups/*}" ,
283- },
284- ]
275+ http_options = (
276+ _BaseErrorGroupServiceRestTransport ._BaseGetGroup ._get_http_options ()
277+ )
285278 request , metadata = self ._interceptor .pre_get_group (request , metadata )
286- pb_request = error_group_service .GetGroupRequest .pb (request )
287- transcoded_request = path_template .transcode (http_options , pb_request )
288-
289- uri = transcoded_request ["uri" ]
290- method = transcoded_request ["method" ]
279+ transcoded_request = _BaseErrorGroupServiceRestTransport ._BaseGetGroup ._get_transcoded_request (
280+ http_options , request
281+ )
291282
292283 # Jsonify the query params
293- query_params = json .loads (
294- json_format .MessageToJson (
295- transcoded_request ["query_params" ],
296- use_integers_for_enums = True ,
297- )
284+ query_params = _BaseErrorGroupServiceRestTransport ._BaseGetGroup ._get_query_params_json (
285+ transcoded_request
298286 )
299- query_params .update (self ._get_unset_required_fields (query_params ))
300-
301- query_params ["$alt" ] = "json;enum-encoding=int"
302287
303288 # Send the request
304- headers = dict ( metadata )
305- headers [ "Content-Type" ] = "application/json"
306- response = getattr ( self . _session , method )(
307- "{host}{uri}" . format ( host = self . _host , uri = uri ) ,
308- timeout = timeout ,
309- headers = headers ,
310- params = rest_helpers . flatten_query_params ( query_params , strict = True ) ,
289+ response = ErrorGroupServiceRestTransport . _GetGroup . _get_response (
290+ self . _host ,
291+ metadata ,
292+ query_params ,
293+ self . _session ,
294+ timeout ,
295+ transcoded_request ,
311296 )
312297
313298 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
@@ -323,19 +308,34 @@ def __call__(
323308 resp = self ._interceptor .post_get_group (resp )
324309 return resp
325310
326- class _UpdateGroup (ErrorGroupServiceRestStub ):
311+ class _UpdateGroup (
312+ _BaseErrorGroupServiceRestTransport ._BaseUpdateGroup , ErrorGroupServiceRestStub
313+ ):
327314 def __hash__ (self ):
328- return hash ("UpdateGroup" )
329-
330- __REQUIRED_FIELDS_DEFAULT_VALUES : Dict [str , Any ] = {}
331-
332- @classmethod
333- def _get_unset_required_fields (cls , message_dict ):
334- return {
335- k : v
336- for k , v in cls .__REQUIRED_FIELDS_DEFAULT_VALUES .items ()
337- if k not in message_dict
338- }
315+ return hash ("ErrorGroupServiceRestTransport.UpdateGroup" )
316+
317+ @staticmethod
318+ def _get_response (
319+ host ,
320+ metadata ,
321+ query_params ,
322+ session ,
323+ timeout ,
324+ transcoded_request ,
325+ body = None ,
326+ ):
327+ uri = transcoded_request ["uri" ]
328+ method = transcoded_request ["method" ]
329+ headers = dict (metadata )
330+ headers ["Content-Type" ] = "application/json"
331+ response = getattr (session , method )(
332+ "{host}{uri}" .format (host = host , uri = uri ),
333+ timeout = timeout ,
334+ headers = headers ,
335+ params = rest_helpers .flatten_query_params (query_params , strict = True ),
336+ data = body ,
337+ )
338+ return response
339339
340340 def __call__ (
341341 self ,
@@ -364,50 +364,32 @@ def __call__(
364364
365365 """
366366
367- http_options : List [Dict [str , str ]] = [
368- {
369- "method" : "put" ,
370- "uri" : "/v1beta1/{group.name=projects/*/groups/*}" ,
371- "body" : "group" ,
372- },
373- {
374- "method" : "put" ,
375- "uri" : "/v1beta1/{group.name=projects/*/locations/*/groups/*}" ,
376- "body" : "group" ,
377- },
378- ]
367+ http_options = (
368+ _BaseErrorGroupServiceRestTransport ._BaseUpdateGroup ._get_http_options ()
369+ )
379370 request , metadata = self ._interceptor .pre_update_group (request , metadata )
380- pb_request = error_group_service .UpdateGroupRequest .pb (request )
381- transcoded_request = path_template .transcode (http_options , pb_request )
382-
383- # Jsonify the request body
371+ transcoded_request = _BaseErrorGroupServiceRestTransport ._BaseUpdateGroup ._get_transcoded_request (
372+ http_options , request
373+ )
384374
385- body = json_format . MessageToJson (
386- transcoded_request [ "body" ], use_integers_for_enums = True
375+ body = _BaseErrorGroupServiceRestTransport . _BaseUpdateGroup . _get_request_body_json (
376+ transcoded_request
387377 )
388- uri = transcoded_request ["uri" ]
389- method = transcoded_request ["method" ]
390378
391379 # Jsonify the query params
392- query_params = json .loads (
393- json_format .MessageToJson (
394- transcoded_request ["query_params" ],
395- use_integers_for_enums = True ,
396- )
380+ query_params = _BaseErrorGroupServiceRestTransport ._BaseUpdateGroup ._get_query_params_json (
381+ transcoded_request
397382 )
398- query_params .update (self ._get_unset_required_fields (query_params ))
399-
400- query_params ["$alt" ] = "json;enum-encoding=int"
401383
402384 # Send the request
403- headers = dict ( metadata )
404- headers [ "Content-Type" ] = "application/json"
405- response = getattr ( self . _session , method )(
406- "{host}{uri}" . format ( host = self . _host , uri = uri ) ,
407- timeout = timeout ,
408- headers = headers ,
409- params = rest_helpers . flatten_query_params ( query_params , strict = True ) ,
410- data = body ,
385+ response = ErrorGroupServiceRestTransport . _UpdateGroup . _get_response (
386+ self . _host ,
387+ metadata ,
388+ query_params ,
389+ self . _session ,
390+ timeout ,
391+ transcoded_request ,
392+ body ,
411393 )
412394
413395 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
0 commit comments