def test_load(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) server = HttpServer("Manage", "Default") self.assertEqual(server.server_name(), "Manage") self.assertIsNotNone(server.read(connection)) self.assertEqual("http", server.server_type())
def create(self, args, config, connection): stype = args['type'] if stype == 'http': server = HttpServer(args['name'], args['group'], args['port'], args['root'], args['database'], args['modules'], connection) elif stype == 'odbc': server = OdbcServer(args['name'], args['group'], args['port'], args['root'], args['database'], args['modules'], connection) elif stype == 'xdbc': server = XdbcServer(args['name'], args['group'], args['port'], args['root'], args['database'], args['modules'], connection) elif stype == 'webdav': server = WebDAVServer(args['name'], args['group'], args['port'], args['root'], args['database'], connection) else: print("Unexpected server type: {0}".format(stype)) sys.exit(1) if server.exists(connection): print("Error: Server already exists: {0} in group {1}".format( args['name'], args['group'])) sys.exit(1) if args['json'] is not None: server = self._read(args['name'], args['group'], stype, args['json']) self._properties(server, args) server.create()
def http_server(self, name, group='Default', port=0, root='/', content_db_name=None, modules_db_name=None, connection=None): """ Get the named HTTP server. """ if connection is None: server = HttpServer(name, group, port, root, content_db_name, modules_db_name, connection=self.connection, save_connection=self.save_connection) else: server = HttpServer(name, group, port, root, content_db_name, modules_db_name, connection=connection, save_connection=False) if connection is None: server = server.read(self.connection) else: server = server.read(connection) if server.server_type() != 'http': raise InvalidAPIRequest("Attempt to load {0} server as http" \ .format(server.server_type())) return server
def create(self, args, config, connection): name = args['name'] group = args['group'] stype = args['type'] if args['json'] is not None: server = self._read(name, group, stype, args['json'], connection=connection) name = server.server_name() group = server.group_name() stype = server.server_type() else: if stype == 'http': server = HttpServer(name, group, args['port'], args['root'], args['database'], args['modules'], connection=connection) elif stype == 'odbc': server = OdbcServer(name, group, args['port'], args['root'], args['database'], args['modules'], connection=connection) elif stype == 'xdbc': server = XdbcServer(name, group, args['port'], args['root'], args['database'], args['modules'], connection=connection) elif stype == 'webdav': server = WebDAVServer(name, group, args['port'], args['root'], args['database'], connection=connection) else: print("Unexpected server type: {0}".format(stype)) sys.exit(1) if server.exists(connection): print("Error: Server already exists: {0} in group {1}".format( name, group)) sys.exit(1) self._properties(server, args) print("Create {0} server {1}...".format(stype, name)) server.create()
def test_create_http_server(self): server = HttpServer("foo-http", "Default", 10101, '/', 'Documents') assert "foo-http" == server.server_name() server.create(self.connection) assert server is not None assert "http" == server.server_type() server.delete(self.connection) server = Server.lookup(self.connection, "foo-http") assert server is None
def http_servers(self, connection=None): """ Get a list of the HTTP servers in the local cluster. """ if connection is None: connection = self.connection return HttpServer.list(connection)
def create(self, args, config, connection): stype = args['type'] if stype == 'http': server = HttpServer(args['name'], args['group'], args['port'], args['root'], args['database'], args['modules'], connection) elif stype == 'odbc': server = OdbcServer(args['name'], args['group'], args['port'], args['root'], args['database'], args['modules'], connection) elif stype == 'xdbc': server = XdbcServer(args['name'], args['group'], args['port'], args['root'], args['database'], args['modules'], connection) elif stype == 'webdav': server = WebDAVServer(args['name'], args['group'], args['port'], args['root'], args['database'], connection) else: print("Unexpected server type: {0}".format(stype)) sys.exit(1) if server.exists(connection): print("Error: Server already exists: {0} in group {1}" .format(args['name'], args['group'])) sys.exit(1) if args['json'] is not None: server = self._read(args['name'], args['group'], stype, args['json']) self._properties(server, args) server.create()
def test_create_http_server(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) server = HttpServer("foo-http", "Default", 10101, '/', 'Documents') self.assertEqual(server.server_name(), "foo-http") server.create(connection) self.assertIsNotNone(server) self.assertEqual("http", server.server_type()) server.delete(connection) server = Server.lookup(connection, "foo-http") self.assertIsNone(server)
def _read(self, name, group, stype, jsonfile): jf = open(jsonfile).read() data = json.loads(jf) data['server-name'] = name data['group-name'] = group data['server-type'] = stype if stype == 'http': server = HttpServer(name, group) elif stype == 'odbc': server = OdbcServer(name, group) elif stype == 'xdbc': server = XdbcServer(name, group) elif stype == 'webdav': server = WebDAVServer(name, group) else: print("Unexpected server type: {0}".format(stype)) sys.exit(1) server = server.unmarshal(data) return server
def create(self, conn, hostname='localhost.localdomain'): """ Connects to the server and creates the relevant artifacts, including the database, the modules database, and the HTTP server. :param conn: The server connection :return:A map containing the content db, the modules db and the HTTP server. """ self.logger.info("Create simple application") data_database = Database(self._db_name, hostname) data_database.set_forest_names(self._forests) modules_database = Database(self._modules_db_name, hostname) server = HttpServer(self._http_server, "Default", self._app_port, self._db_name, self._modules_db_name) server.set_modules_database_name(self._modules_db_name) data_database.create(conn) modules_database.create(conn) server.create(conn) return { u'content': data_database, u'modules': modules_database, u'server': server }
def _read(self, name, group, stype, jsonfile, connection=None, save_connection=True): jf = open(jsonfile).read() data = json.loads(jf) if name is not None: data['server-name'] = name if group is not None: data['group-name'] = group if stype is not None: data['server-type'] = stype stype = data['server-type'] if stype == 'http': server = HttpServer(name, group) elif stype == 'odbc': server = OdbcServer(name, group) elif stype == 'xdbc': server = XdbcServer(name, group) elif stype == 'webdav': server = WebDAVServer(name, group) elif stype is None: print("Server type must be specified.") sys.ext(1) else: print("Unexpected server type: {0}".format(stype)) sys.exit(1) server = server.unmarshal(data, connection=connection, save_connection=save_connection) return server
def create(self, args, config, connection): name = args['name'] group = args['group'] stype = args['type'] if args['json'] is not None: server = self._read(name, group, stype, args['json'], connection=connection) name = server.server_name() group = server.group_name() stype = server.server_type() else: if stype == 'http': server = HttpServer(name, group, args['port'], args['root'], args['database'], args['modules'], connection=connection) elif stype == 'odbc': server = OdbcServer(name, group, args['port'], args['root'], args['database'], args['modules'], connection=connection) elif stype == 'xdbc': server = XdbcServer(name, group, args['port'], args['root'], args['database'], args['modules'], connection=connection) elif stype == 'webdav': server = WebDAVServer(name, group, args['port'], args['root'], args['database'], connection=connection) else: print("Unexpected server type: {0}".format(stype)) sys.exit(1) if server.exists(connection): print("Error: Server already exists: {0} in group {1}" .format(name, group)) sys.exit(1) self._properties(server, args) print("Create {0} server {1}...".format(stype,name)) server.create()
def list(self, args, config, connection): stype = args['type'] if stype == None: slist = Server.list(connection) elif stype == 'http': slist = HttpServer.list(connection) elif stype == 'odbc': slist = OdbcServer.list(connection) elif stype == 'xdbc': slist = XdbcServer.list(connection) elif stype == 'webdav': slist = WebDAVServer.list(connection) else: print("Unexpected server type: {0}".format(stype)) sys.exit(1) names = [] for key in slist: (group,name) = key.split('|') if group == args['group']: names.append(name) print(json.dumps(names,sort_keys=True, indent=2))
def list(self, args, config, connection): stype = args['type'] if stype == None: slist = Server.list(connection) elif stype == 'http': slist = HttpServer.list(connection) elif stype == 'odbc': slist = OdbcServer.list(connection) elif stype == 'xdbc': slist = XdbcServer.list(connection) elif stype == 'webdav': slist = WebDAVServer.list(connection) else: print("Unexpected server type: {0}".format(stype)) sys.exit(1) names = [] for key in slist: (group, name) = key.split('|') if group == args['group']: names.append(name) print(json.dumps(names, sort_keys=True, indent=2))
def http_servers(self, connection=None): if connection is None: connection = self.connection return HttpServer.list(connection)
def test_load(self): server = HttpServer("Manage", "Default") assert "Manage" == server.server_name() assert server.read(self.connection) is not None assert "http" == server.server_type()
def _test_ssl_certificate_pems(self): connection = Connection.make_connection(tc.hostname, tc.admin, tc.password) server = HttpServer("foo-http", "Default", 10101, '/', 'Documents') self.assertEqual(server.server_name(), "foo-http") server.create(connection) self.assertIsNotNone(server) self.assertEqual("http", server.server_type()) pem1 = "-----BEGIN CERTIFICATE-----\n\ MIICgjCCAeugAwIBAgIBBDANBgkqhkiG9w0BAQQFADBTMQswCQYDVQQGEwJVUzEc\n\ MBoGA1UEChMTRXF1aWZheCBTZWN1cmUgSW5jLjEmMCQGA1UEAxMdRXF1aWZheCBT\n\ ZWN1cmUgZUJ1c2luZXNzIENBLTEwHhcNOTkwNjIxMDQwMDAwWhcNMjAwNjIxMDQw\n\ MDAwWjBTMQswCQYDVQQGEwJVUzEcMBoGA1UEChMTRXF1aWZheCBTZWN1cmUgSW5j\n\ LjEmMCQGA1UEAxMdRXF1aWZheCBTZWN1cmUgZUJ1c2luZXNzIENBLTEwgZ8wDQYJ\n\ KoZIhvcNAQEBBQADgY0AMIGJAoGBAM4vGbwXt3fek6lfWg0XTzQaDJj0ItlZ1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qY6KxRwIP1ORROhI8bIpaVIRw28HFkM9yRcuoWcDNM50/\n\ o5brhTMhHD4ePmBudpxnhcXIw2ECAwEAAaNmMGQwEQYJYIZIAYb4QgEBBAQDAgAH\n\ MA8GA1UdEwEB/wQFMAMBAf8wHwYDVR0jBBgwFoAUvqigdHJQa0S3ySPY+6j/s1dr\n\ aGwwHQYDVR0OBBYEFL6ooHRyUGtEt8kj2Puo/7NXa2hsMA0GCSqGSIb3DQEBBAUA\n\ A4GBADDiAVGqx+pf2rnQZQ8w1j7aDRRJbpGTJxQx78T3LUX47Me/okENI7SS+RkA\n\ Z70Br83gcfxaz2TE4JaY0KNA4gGK7ycH8WUBikQtBmV1UsCGECAhX2xrD2yuCRyv\n\ 8qIYNMR1pHMc8Y3c7635s3a0kr/clRAevsvIO1qEYBlWlKlV\n\ -----END CERTIFICATE-----" server.add_ssl_client_certificate_pem(pem1) server.update(connection) server.read(connection) self.assertEqual(1, len(server.ssl_client_certificate_pems())) server.set_ssl_client_certificate_pems([pem1,pem2]) server.update(connection) server.read(connection) self.assertEqual(2, len(server.ssl_client_certificate_pems())) server.delete(connection) server = Server.lookup(connection, "foo-http") self.assertIsNone(server)
def _test_ssl_certificate_pems(self): server = HttpServer("foo-http", "Default", 10101, '/', 'Documents') assert "foo-http" == server.server_name() server.create(self.connection) assert server is not None assert "http" == server.server_type() pem1 = "-----BEGIN CERTIFICATE-----\n\ MIICgjCCAeugAwIBAgIBBDANBgkqhkiG9w0BAQQFADBTMQswCQYDVQQGEwJVUzEc\n\ MBoGA1UEChMTRXF1aWZheCBTZWN1cmUgSW5jLjEmMCQGA1UEAxMdRXF1aWZheCBT\n\ ZWN1cmUgZUJ1c2luZXNzIENBLTEwHhcNOTkwNjIxMDQwMDAwWhcNMjAwNjIxMDQw\n\ MDAwWjBTMQswCQYDVQQGEwJVUzEcMBoGA1UEChMTRXF1aWZheCBTZWN1cmUgSW5j\n\ LjEmMCQGA1UEAxMdRXF1aWZheCBTZWN1cmUgZUJ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EnC\n\ UdXfp9E3j9HngXNBUmCbnaEXJnitx7HoJpQytd4zjTov2/KaelpzmKNc6fuKcxtc\n\ 58O/gGzNqfTWK8D3+ZmqY6KxRwIP1ORROhI8bIpaVIRw28HFkM9yRcuoWcDNM50/\n\ o5brhTMhHD4ePmBudpxnhcXIw2ECAwEAAaNmMGQwEQYJYIZIAYb4QgEBBAQDAgAH\n\ MA8GA1UdEwEB/wQFMAMBAf8wHwYDVR0jBBgwFoAUvqigdHJQa0S3ySPY+6j/s1dr\n\ aGwwHQYDVR0OBBYEFL6ooHRyUGtEt8kj2Puo/7NXa2hsMA0GCSqGSIb3DQEBBAUA\n\ A4GBADDiAVGqx+pf2rnQZQ8w1j7aDRRJbpGTJxQx78T3LUX47Me/okENI7SS+RkA\n\ Z70Br83gcfxaz2TE4JaY0KNA4gGK7ycH8WUBikQtBmV1UsCGECAhX2xrD2yuCRyv\n\ 8qIYNMR1pHMc8Y3c7635s3a0kr/clRAevsvIO1qEYBlWlKlV\n\ -----END CERTIFICATE-----" server.add_ssl_client_certificate_pem(pem1) server.update(self.connection) server.read(self.connection) assert 1 == len(server.ssl_client_certificate_pems()) server.set_ssl_client_certificate_pems([pem1, pem2]) server.update(self.connection) server.read(self.connection) assert 2 == len(server.ssl_client_certificate_pems()) server.delete(self.connection) server = Server.lookup(self.connection, "foo-http") assert server is None