Source code for censys.exceptions

"""
Exceptions for Censys.
"""

from typing import Optional, Dict, Type


[docs]class CensysException(Exception): """ Base Exception for Censys. """
[docs]class CensysCLIException(CensysException): """ Exception raised when the CLI is passed invalid arguments. """
[docs]class CensysMissingApiKeyException(CensysException): """ Exception raised when there is no provided ASM API key. """
[docs]class CensysAPIException(CensysException): """ Base Exception for Censys API's. """ # pylint: disable=too-many-arguments def __init__( self, status_code: int, message: str, body: Optional[str] = None, const: Optional[str] = None, error_code: Optional[int] = None, details: Optional[str] = None, ): self.status_code = status_code self.message = message self.body = body self.const = const self.error_code = error_code self.details = details super().__init__(self.message)
[docs]class CensysSearchException(CensysAPIException): """ Base Exception for the Censys search API. """ def __repr__(self): return "%i (%s): %s" % (self.status_code, self.const, self.message or self.body) __str__ = __repr__
[docs]class CensysAsmException(CensysAPIException): """ Base Exception for the Censys ASM API. """ def __repr__(self): return "%i (Error Code: %i), %s. %s" % ( self.status_code, self.error_code, self.message, self.details, ) __str__ = __repr__
[docs]class CensysRateLimitExceededException(CensysSearchException): """ Exception raised when your Censys rate limit has been exceeded. """
[docs]class CensysNotFoundException(CensysSearchException): """ Exception raised when the resource requested is not found. """
[docs]class CensysUnauthorizedException(CensysSearchException): """ Exception raised when your Censys account doesn't have access to the requested resource. """
[docs]class CensysJSONDecodeException(CensysSearchException): """ Exception raised when the resource requested is not valid JSON. """
[docs]class CensysInvalidRequestException(CensysAsmException): """ Exception raised when the HTTP request is invalid. """
[docs]class CensysInvalidAuthTokenException(CensysAsmException): """ Exception raised when the auth token is invalid. """
[docs]class CensysInvalidAPIKeyException(CensysAsmException): """ Exception raised when the ASM API key is invalid. """
[docs]class CensysTooManyRequestsException(CensysAsmException): """ Exception raised when the allowed requests bandwidth is exceeded. """
[docs]class CensysAppDownForMaintenanceException(CensysAsmException): """ Exception raised when the ASM API is down for maintenance. """
[docs]class CensysInvalidSeedDataException(CensysAsmException): """ Exception raised when the seed data is invalid. """
[docs]class CensysAssociatedAssetsThresholdWarningException(CensysAsmException): """ Exception raised when the associated asset count is within the warning threshold. """
[docs]class CensysTooManyInputNodesException(CensysAsmException): """ Exception raised when there are too many input nodes. """
[docs]class CensysSeedNotFoundException(CensysAsmException): """ Exception raised when the requested seed can not be found. """
[docs]class CensysNotASeedException(CensysAsmException): """ Exception raised when the requested resource is not a seed. """
[docs]class CensysNeedConfirmationToRemoveParentSeedsException(CensysAsmException): """ Exception raised when confirmation is needed to remove seeds with children. """
[docs]class CensysCannotRemoveNonExistentSeedsException(CensysAsmException): """ Exception raised when trying to remove non existent seed nodes. """
[docs]class CensysCannotRemoveNonSeedsException(CensysAsmException): """ Exception raised when trying to remove non seed nodes. """
[docs]class CensysInvalidSeedTypeException(CensysAsmException): """ Exception raised when the seed type is invalid. """
[docs]class CensysInvalidLogbookCursorException(CensysAsmException): """ Exception raised when the logbook cursor is invalid. """
[docs]class CensysPageNumberOutOfRangeException(CensysAsmException): """ Exception raised when the requested page number is out of range [1 - totalPages]. """
[docs]class CensysInvalidPageSizeException(CensysAsmException): """ Exception raised when the page size is invalid. """
[docs]class CensysHostNotFoundException(CensysAsmException): """ Exception raised when the requested host is not found. """
[docs]class CensysInvalidIPv4AddressException(CensysAsmException): """ Exception raised when the IPv4 address is invalid. """
[docs]class CensysInvalidCommentException(CensysAsmException): """ Exception raised when the comment is invalid. """
[docs]class CensysCommentNotFoundException(CensysAsmException): """ Exception raised when the requested comment is not found. """
[docs]class CensysInvalidColorException(CensysAsmException): """ Exception raised when the specified color is invalid. """
[docs]class CensysTagHasTrailingOrLeadingWhitespaceException(CensysAsmException): """ Exception raised when the specified tag has trailing or leading whitespace. """
[docs]class CensysTagIsEmptyStringException(CensysAsmException): """ Exception raised when the specified tag is an empty string. """
[docs]class CensysTagLabelsDifferOnlyInCasingException(CensysAsmException): """ Exception raised when the specified tag differs from an existing tag in only casing. """
[docs]class CensysTagLabelTooLongException(CensysAsmException): """ Exception raised when the specified tag label is too long. """
[docs]class CensysTagColorTooLongException(CensysAsmException): """ Exception raised when the specified tag color is too long. """
[docs]class CensysCannotCreateTagWithNewColorException(CensysAsmException): """ Exception raised when the specified tag cannot be created with a new color. """
[docs]class CensysTagColorHasTrailingOrLeadingWhitespaceException(CensysAsmException): """ Exception raised when the specified tag color has trailing or leading whitespace. """
[docs]class CensysCertificateNotFoundException(CensysAsmException): """ Exception raised when the certificate is not found. """
[docs]class CensysDomainNotFoundException(CensysAsmException): """ Exception raised when the domain is not found. """
[docs]class CensysExceptionMapper: """ Map status code to Exception for the ASM and Search API. """ ASM_EXCEPTIONS: Dict[int, Type[CensysAsmException]] = { 10008: CensysInvalidRequestException, 10002: CensysInvalidAuthTokenException, 10001: CensysInvalidAPIKeyException, 10039: CensysTooManyRequestsException, 10029: CensysAppDownForMaintenanceException, 10007: CensysInvalidSeedDataException, 10017: CensysAssociatedAssetsThresholdWarningException, 10016: CensysTooManyInputNodesException, 10014: CensysSeedNotFoundException, 10015: CensysNotASeedException, 10013: CensysNeedConfirmationToRemoveParentSeedsException, 10012: CensysCannotRemoveNonExistentSeedsException, 10011: CensysCannotRemoveNonSeedsException, 10038: CensysInvalidSeedTypeException, 10040: CensysInvalidLogbookCursorException, 10051: CensysPageNumberOutOfRangeException, 10050: CensysInvalidPageSizeException, 10018: CensysHostNotFoundException, 10021: CensysInvalidIPv4AddressException, 10054: CensysInvalidCommentException, 10055: CensysCommentNotFoundException, 10037: CensysInvalidColorException, 10025: CensysTagHasTrailingOrLeadingWhitespaceException, 10026: CensysTagIsEmptyStringException, 10027: CensysTagLabelsDifferOnlyInCasingException, 10028: CensysTagLabelTooLongException, 10034: CensysTagColorTooLongException, 10035: CensysCannotCreateTagWithNewColorException, 10036: CensysTagColorHasTrailingOrLeadingWhitespaceException, 10020: CensysCertificateNotFoundException, 10019: CensysDomainNotFoundException, } """Map of status code to ASM Exception.""" SEARCH_EXCEPTIONS: Dict[int, Type[CensysSearchException]] = { 401: CensysUnauthorizedException, 403: CensysUnauthorizedException, 404: CensysNotFoundException, 429: CensysRateLimitExceededException, } """Map of status code to Search Exception."""