def test_validate_time_period(self): result = utilities.validate_time_period(["days=1"]) self.assertEqual(("days",1), result, "expected a tuple of days, 1") result = utilities.validate_time_period(["hours=10"]) self.assertEqual(("hours", 10), result, "expected a tuple of hours, 10") result = utilities.validate_time_period(["minutes=10"]) self.assertEqual(("minutes", 10), result, "expected a tuple of minutes, 10") result = utilities.validate_time_period(["weeks=10"]) self.assertEqual(("weeks", 10), result, "expected a tuple of weeks, 10") result = utilities.validate_time_period(["days=1", "years=1"]) self.assertEqual(("days", 1), result, "expected a tuple of days, 1") result = utilities.validate_time_period(["days=1", "weeks=10"]) self.assertEqual(("days", 1), result, "expected a tuple of days, 1") result = utilities.validate_time_period(["weeks=10", "minutes=10"]) self.assertEqual(("weeks", 10), result, "expected a tuple of weeks, 10") #the equal sign is missing...we should return None, None and give up. result = utilities.validate_time_period(["days1000"]) self.assertEqual((None, None), result, "expected a tuple of None,None")
def process(self, rqst, path_tokens, query_tokens): uom = None units = None self.log.info("processing ipaddress request:" + str(path_tokens) + str(query_tokens)) try: time_period = utilities.validate_time_period(query_tokens) uom = time_period[0] units = time_period[1] except ValueError: rqst.badRequest(units) return if len(path_tokens) == 5: ipaddress = path_tokens[4].strip() self.log.debug("requested: " + str(ipaddress)) if ipaddress is not None or ipaddress is not "": try: ipaddress = utilities.validate_ipaddress(ipaddress) self.get_ips_data_by_time(rqst, ipaddress, uom, units) except ValueError: rqst.badRequest(badIpAddress) return elif ipaddress == None or ipaddress == "": self.get_ips_data_by_time(rqst, "", uom, units) else: rqst.badRequest() return elif len(path_tokens) == 4: self.get_ips_list_json(rqst, uom, units) else: rqst.badRequest() return
def process(self, rqst, path_tokens, query_tokens): uom = None units = None self.log.info("processing ports request:" + str(path_tokens) + str(query_tokens)) if len(query_tokens) > 0: try: time_period = utilities.validate_time_period(query_tokens) uom = time_period[0] units = time_period[1] except ValueError: rqst.badRequest(units) return # default if we aren't given valid uom and units if uom is None or units is None: uom = "days" units = 1 if len(path_tokens) == 5: portNbr = utilities.validate_port_number(path_tokens[4]) self.log.debug("requested: " + str(portNbr)) if portNbr is not None and 0 < portNbr < 9000: self.get_port_data_by_time(rqst, portNbr, uom, units) elif portNbr == None or "": self.get_port_list_json(rqst, uom, units) else: rqst.badRequest() return elif len(path_tokens) == 4: self.get_port_list_json(rqst, uom, units) else: rqst.badRequest() return
def process(self, rqst, path_tokens, query_tokens): global have_basemap if not have_basemap: err_msg = \ ('<html><head><title>WorldMap</title></head><body>' 'To enable WorldMap generation, please visit ' '<a href="https://recce7.github.io/">the documentation</a> and ' 'follow the directions for installing the Basemap library.' '</body></html>') rqst.send_response(200) #todo make this configurable for allow-origin rqst.send_header("Access-Control-Allow-Origin","http://localhost:8000") rqst.send_header('Content-Type', 'text/html') rqst.send_header('Content-Length', len(err_msg)) rqst.end_headers() rqst.flush_headers() rqst.wfile.write(bytes(err_msg, "utf-8")) rqst.wfile.flush() return uom = None units = None self.log.info("processing ipaddress request:" + str(path_tokens) + str(query_tokens)) try: time_period = utilities.validate_time_period(query_tokens) uom = time_period[0] units = time_period[1] except ValueError: rqst.badRequest(units) return if len(path_tokens) >= 5: rqst.badRequest() return else: self.construct_worldmap(rqst, uom, units)