def CreateService(
    service_name: str,
    api_version: str) -> 'googleapiclient.discovery.Resource':
  """Creates an GCP API service.

  Args:
    service_name (str): Name of the GCP service to use.
    api_version (str): Version of the GCP service API to use.

  Returns:
    googleapiclient.discovery.Resource: API service resource.

  Raises:
    CredentialsConfigurationError: If Application Default Credentials could
        not be obtained
    RuntimeError: If service build times out.
  """

  try:
    credentials, _ = default()  # type: ignore [no-untyped-call]
  except DefaultCredentialsError as exception:
    raise errors.CredentialsConfigurationError(
        'Could not get application default credentials. Have you run $ gcloud '
        'auth application-default login?: {0!s}'.format(exception),
        __name__) from exception

  service_built = False
  for retry in range(RETRY_MAX):
    try:
      service = build(
          service_name,
          api_version,
          credentials=credentials,
          cache_discovery=False)
      service_built = True
    except socket.timeout:
      logger.warning(
          'Timeout trying to build service {0:s} (try {1:d} of {2:d})'.format(
              service_name, retry, RETRY_MAX))

    if service_built:
      break

  if not service_built:
    error_msg = (
        'Failures building service {0:s} caused by multiple '
        'timeouts').format(service_name)
    raise RuntimeError(error_msg)

  return service
Creates an GCP API service.

Args:
service_name (str): Name of the GCP service to use.
api_version (str): Version of the GCP service API to use.

Returns:
googleapiclient.discovery.Resource: API service resource.

Raises:
CredentialsConfigurationError: If Application Default Credentials could
not be obtained
RuntimeError: If service build times out.
libcloudforensics/providers/gcp/internal/common.py