def create_table(context, table): """Create a table suitable for storing monitoring events.""" if not validate_table_name(table): logger.critical("Invalid PostgreSQL table name: %s", table) sys.exit(1) db = DatabaseHandler(context.obj["db"]["config"]) db.create_table(table) logger.info("Created table %s", table)
def process(context, **kwargs): """Stream results from Kafka into a database.""" for table_name in kwargs["tables"]: if not validate_table_name(table_name): logger.critical("Invalid PostgreSQL table name: %s", table_name) sys.exit(1) context.obj.update(kwargs) event_processor = EventProcessor(**context.obj) logger.info("Starting event processing service") event_processor.run()
def test_too_long(self): self.assertFalse(validate_table_name("table_" + 64 * "a"))
def test_starting_underscore(self): self.assertTrue(validate_table_name("_table1"))
def test_starting_numeral(self): self.assertFalse(validate_table_name("1table"))
def test_starting_dollar_sign(self): # Completely disallowed with PostgreSQL. self.assertFalse(validate_table_name("$table1"))
def test_cjk(self): self.assertFalse(validate_table_name("table_有り"))
def test_alphanumerical_with_underscore(self): self.assertTrue(validate_table_name("table_2"))
def test_alphanumerical_with_nonlatin(self): # Actually possible with PostgreSQL, but disallowed for the time being. self.assertFalse(validate_table_name("täble"))
def test_alphanumerical(self): self.assertTrue(validate_table_name("table1"))