| 22 | |
| 23 | |
| 24 | class ZoneManager(object): |
| 25 | # A status of confirmed typically means it was entered by a human |
| 26 | CONFIRMED = "confirmed" |
| 27 | |
| 28 | # A status of unconfirmed means that it was added via automation |
| 29 | # It has not been reviewed by a human |
| 30 | UNCONFIRMED = "unconfirmed" |
| 31 | |
| 32 | # A status of false positive means that a human identified that automation made a mistake |
| 33 | FALSE_POSITIVE = "false_positive" |
| 34 | |
| 35 | # A status of expired means that the automation believes that the domain is no longer registered |
| 36 | EXPIRED = "expired" |
| 37 | |
| 38 | # The MongoConnector |
| 39 | mongo_connector = None |
| 40 | |
| 41 | # The zone collection |
| 42 | zone_collection = None |
| 43 | |
| 44 | # The logger |
| 45 | _logger = None |
| 46 | |
| 47 | def _log(self): |
| 48 | """ |
| 49 | Get the log |
| 50 | """ |
| 51 | return logging.getLogger(__name__) |
| 52 | |
| 53 | def __init__(self, mongo_connector): |
| 54 | """ |
| 55 | Initialize the MongoDB Connector |
| 56 | """ |
| 57 | self._logger = self._log() |
| 58 | self.mongo_connector = mongo_connector |
| 59 | self.zone_collection = mongo_connector.get_zone_connection() |
| 60 | |
| 61 | def _check_valid_status(self, status): |
| 62 | if ( |
| 63 | status != ZoneManager.EXPIRED |
| 64 | and status != ZoneManager.FALSE_POSITIVE |
| 65 | and status != ZoneManager.CONFIRMED |
| 66 | and status != ZoneManager.UNCONFIRMED |
| 67 | ): |
| 68 | self._logger.error("ERROR: Bad status value") |
| 69 | return False |
| 70 | |
| 71 | return True |
| 72 | |
| 73 | @staticmethod |
| 74 | def get_distinct_zones(mongo_connector, includeAll=False): |
| 75 | """ |
| 76 | This is the most common usage of get zones where the caller wants just the list of |
| 77 | active zones. |
| 78 | |
| 79 | This returns the list of zones as an array of strings rather than the complete JSON objects |
| 80 | """ |
| 81 | zones_collection = mongo_connector.get_zone_connection() |