Ejemplo n.º 1
0
 async def __safely_get_source_responses(self) -> SourceResponses:
     """Connect to the source and get the data, without failing. This method should not be overridden
     because it makes sure the collection of source data never causes the collector to fail."""
     api_url = safe_api_url = self.__class__.__name__
     try:
         api_url = await self._api_url()
         safe_api_url = tokenless(api_url) or self.__class__.__name__
         responses = await self._get_source_responses(api_url)
         logging.info("Retrieved %s", safe_api_url)
         return responses
     except aiohttp.ClientError as reason:
         error = tokenless(str(reason)) if str(reason) else reason.__class__.__name__
         logging.warning("Failed to retrieve %s: %s", safe_api_url, error)
     except Exception as reason:  # pylint: disable=broad-except
         error = stable_traceback(traceback.format_exc())
         logging.error("Failed to retrieve %s: %s", safe_api_url, reason)
     return SourceResponses(api_url=URL(api_url), connection_error=error)
Ejemplo n.º 2
0
 def __logsafe_exception(exception: Exception) -> str:
     """Return a log-safe version of the exception."""
     return tokenless(
         str(exception)) if str(exception) else exception.__class__.__name__
Ejemplo n.º 3
0
 def test_private_token(self):
     """Test that the URL is returned without the private token."""
     self.assertEqual(
         URL("https://url/path?private_token=<redacted>"),
         tokenless(URL("https://url/path?private_token=abcdef45321a")),
     )
Ejemplo n.º 4
0
 def test_no_token(self):
     """Test that the URL is returned unchanged if it does not contain a token."""
     url = URL("https://url/path/1")
     self.assertEqual(url, tokenless(url))