def test_extract_from_origin(self): scheme, host, port = parser.extract_from_origin('www.example.com') self.assertIsInstance(scheme, str) self.assertEqual(scheme, 'https') self.assertIsInstance(host, str) self.assertEqual(host, 'www.example.com') self.assertIsInstance(port, str) self.assertEqual(port, '443') scheme, host, port = parser.extract_from_origin('http://example.com') self.assertIsInstance(scheme, str) self.assertEqual(scheme, 'http') self.assertIsInstance(host, str) self.assertEqual(host, 'example.com') self.assertIsInstance(port, str) self.assertEqual(port, '80') scheme, host, port = parser.extract_from_origin('imba://' 'www.example.com:1337') self.assertIsInstance(scheme, str) self.assertEqual(scheme, 'imba') self.assertIsInstance(host, str) self.assertEqual(host, 'www.example.com') self.assertIsInstance(port, str) self.assertEqual(port, '1337')
def make_backend_action(self, backend_config, rule_id): origins = [] if 'origin' in backend_config: origins.append(backend_config['origin']) elif 'servers' in backend_config: origins += backend_config['servers'] else: raise ORMInternalRenderException( 'ERROR: unhandled backend type: ' + str(backend_config.keys())) if origins: self.backend_acls.append(' use_backend ' + rule_id + ' ' 'if { hdr(X-ORM-ID) -m str ' + rule_id + ' }') self.backends.append('') self.backends.append('backend ' + rule_id) for origin in origins: origin_instance = origin if isinstance(origin, str): origin_instance = {'server': origin} scheme, hostname, port = parser.extract_from_origin( origin_instance['server']) server = (' server ' + parser.normalize(origin_instance['server']) + ' ' + hostname + ':' + port + ' resolvers dns resolve-prefer ipv4' + ' check') if scheme == 'https': # TODO: add 'verify required sni ca-file verifyhost' server += ' ssl verify none' elif scheme != 'http': raise ORMInternalRenderException('ERROR: unhandled origin ' 'scheme: ' + scheme) if origin_instance.get('max_connections', False): server += ' maxconn {}'.format( origin_instance['max_connections']) if origin_instance.get('max_queued_connections', False): server += ' maxqueue {}'.format( origin_instance['max_queued_connections']) self.backends.append(server)
def make_backend_action(self, backend_config, rule_id): origins = [] if "origin" in backend_config: origins.append(backend_config["origin"]) elif "servers" in backend_config: origins += backend_config["servers"] else: raise ORMInternalRenderException( "ERROR: unhandled backend type: " + str(backend_config.keys())) if origins: self.backend_acls.append(" use_backend " + rule_id + " " "if { hdr(X-ORM-ID) -m str " + rule_id + " }") self.backends.append("") self.backends.append("backend " + rule_id) for origin in origins: origin_instance = origin if isinstance(origin, str): origin_instance = {"server": origin} scheme, hostname, port = parser.extract_from_origin( origin_instance["server"]) server = (" server " + parser.normalize(origin_instance["server"]) + " " + hostname + ":" + port + " resolvers dns resolve-prefer ipv4" + " check") if scheme == "https": # TODO: add 'verify required sni ca-file verifyhost' server += " ssl verify none" elif scheme != "http": raise ORMInternalRenderException("ERROR: unhandled origin " "scheme: " + scheme) if origin_instance.get("max_connections", False): server += " maxconn {}".format( origin_instance["max_connections"]) if origin_instance.get("max_queued_connections", False): server += " maxqueue {}".format( origin_instance["max_queued_connections"]) self.backends.append(server)