def fetch()

in blueprints/cloud-operations/network-quota-monitoring/src/main.py [0:0]


def fetch(request):
  '''Minimal HTTP client interface for API calls.

  Executes the HTTP request passed as argument using the google.auth
  authenticated session.

  Args:
    request: an instance of plugins.HTTPRequest.
  Returns:
    JSON-decoded or raw response depending on the 'json' request attribute.
  '''
  # try
  LOGGER.debug(f'fetch {"POST" if request.data else "GET"} {request.url}')
  try:
    if not request.data:
      response = _http().get(request.url, headers=request.headers)
    else:
      response = _http().post(request.url, headers=request.headers,
                              data=request.data)
  except google.auth.exceptions.RefreshError as e:
    raise SystemExit(e.args[0])
  if response.status_code != 200:
    LOGGER.critical(
        f'response code {response.status_code} for URL {request.url}')
    LOGGER.critical(response.content)
    print(request.data)
    raise SystemExit(1)
  return response