@@ -284,10 +284,9 @@ def get_service_account_email(
284284 """
285285 if project is None :
286286 project = self .project
287+
287288 path = "/projects/%s/serviceAccount" % (project ,)
288- api_response = self ._base_connection .api_request (
289- method = "GET" , path = path , timeout = timeout , retry = retry ,
290- )
289+ api_response = self ._get_resource (path , timeout = timeout , retry = retry )
291290 return api_response ["email_address" ]
292291
293292 def bucket (self , bucket_name , user_project = None ):
@@ -321,6 +320,72 @@ def batch(self):
321320 """
322321 return Batch (client = self )
323322
323+ def _get_resource (
324+ self ,
325+ path ,
326+ query_params = None ,
327+ headers = None ,
328+ timeout = _DEFAULT_TIMEOUT ,
329+ retry = DEFAULT_RETRY ,
330+ _target_object = None ,
331+ ):
332+ """Helper for bucket / blob methods making API 'GET' calls.
333+
334+ Args:
335+ path str:
336+ The path of the resource to fetch.
337+
338+ query_params Optional[dict]:
339+ HTTP query parameters to be passed
340+
341+ headers Optional[dict]:
342+ HTTP headers to be passed
343+
344+ timeout (Optional[Union[float, Tuple[float, float]]]):
345+ The amount of time, in seconds, to wait for the server response.
346+
347+ Can also be passed as a tuple (connect_timeout, read_timeout).
348+ See :meth:`requests.Session.request` documentation for details.
349+
350+ retry (Optional[Union[google.api_core.retry.Retry, google.cloud.storage.retry.ConditionalRetryPolicy]]):
351+ How to retry the RPC. A None value will disable retries.
352+ A google.api_core.retry.Retry value will enable retries, and the object will
353+ define retriable response codes and errors and configure backoff and timeout options.
354+
355+ A google.cloud.storage.retry.ConditionalRetryPolicy value wraps a Retry object and
356+ activates it only if certain conditions are met. This class exists to provide safe defaults
357+ for RPC calls that are not technically safe to retry normally (due to potential data
358+ duplication or other side-effects) but become safe to retry if a condition such as
359+ if_metageneration_match is set.
360+
361+ See the retry.py source code and docstrings in this package (google.cloud.storage.retry) for
362+ information on retry types and how to configure them.
363+
364+ _target_object (Union[ \
365+ :class:`~google.cloud.storage.bucket.Bucket`, \
366+ :class:`~google.cloud.storage.bucket.blob`, \
367+ ]):
368+ Object to which future data is to be applied -- only relevant
369+ in the context of a batch.
370+
371+ Returns:
372+ dict
373+ The JSON resource fetched
374+
375+ Raises:
376+ google.cloud.exceptions.NotFound
377+ If the bucket is not found.
378+ """
379+ return self ._connection .api_request (
380+ method = "GET" ,
381+ path = path ,
382+ query_params = query_params ,
383+ headers = headers ,
384+ timeout = timeout ,
385+ retry = retry ,
386+ _target_object = _target_object ,
387+ )
388+
324389 def get_bucket (
325390 self ,
326391 bucket_or_name ,
0 commit comments