예제 #1
0
    def _load_plugins(self, options):
        for plugin_name, plugin_config in get_enabled_plugins():
            try:
                plugin_class = ('plugins.%s.%s' %
                                (plugin_name,
                                 plugin_config['wok']['plugin_class']))
                extra_auth = plugin_config['wok'].get('extra_auth_api_class',
                                                      None)
                script_name = plugin_config['wok']['uri']
                del plugin_config['wok']

                plugin_config.update(PluginConfig(plugin_name))
            except KeyError:
                continue

            try:
                plugin_app = import_class(plugin_class)(options)
            except ImportError, e:
                cherrypy.log.error_log.error(
                    "Failed to import plugin %s, "
                    "error: %s" % (plugin_class, e.message)
                )
                continue

            # dynamically extend plugin config with custom data, if provided
            get_custom_conf = getattr(plugin_app, "get_custom_conf", None)
            if get_custom_conf is not None:
                plugin_config.update(get_custom_conf())

            # dynamically add tools.wokauth.on = True to extra plugin APIs
            if extra_auth:
                try:
                    authed_apis = import_class(('plugins.%s.%s' %
                                                (plugin_name, extra_auth)))
                except ImportError, e:
                    cherrypy.log.error_log.error(
                        "Failed to import subnodes for plugin %s, "
                        "error: %s" % (plugin_class, e.message)
                    )
                    continue

                urlSubNodes = {}
                for ident, node in authed_apis.items():
                    if node.url_auth:
                        ident = "/%s" % ident
                        urlSubNodes[ident] = {'tools.wokauth.on': True}

                plugin_config.update(urlSubNodes)
예제 #2
0
파일: server.py 프로젝트: sdnnfv/kimchi
    def _load_plugins(self, options):
        for plugin_name, plugin_config in get_enabled_plugins():
            try:
                plugin_class = (
                    'plugins.%s.%s' %
                    (plugin_name, plugin_config['wok']['plugin_class']))
                extra_auth = plugin_config['wok'].get('extra_auth_api_class',
                                                      None)
                script_name = plugin_config['wok']['uri']
                del plugin_config['wok']

                plugin_config.update(PluginConfig(plugin_name))
            except KeyError:
                continue

            try:
                plugin_app = import_class(plugin_class)(options)
            except ImportError:
                cherrypy.log.error_log.error("Failed to import plugin %s" %
                                             plugin_class)
                continue

            # dynamically extend plugin config with custom data, if provided
            get_custom_conf = getattr(plugin_app, "get_custom_conf", None)
            if get_custom_conf is not None:
                plugin_config.update(get_custom_conf())

            # dynamically add tools.wokauth.on = True to extra plugin APIs
            if extra_auth:
                try:
                    authed_apis = import_class(
                        ('plugins.%s.%s' % (plugin_name, extra_auth)))
                except ImportError:
                    cherrypy.log.error_log.error("Failed to import subnodes "
                                                 "for plugin %s" %
                                                 plugin_class)
                    continue

                urlSubNodes = {}
                for ident, node in authed_apis.items():
                    if node.url_auth:
                        ident = "/%s" % ident
                        urlSubNodes[ident] = {'tools.wokauth.on': True}

                plugin_config.update(urlSubNodes)

            cherrypy.tree.mount(plugin_app, script_name, plugin_config)
예제 #3
0
파일: server.py 프로젝트: lcorreia/wok
    def _load_plugins(self, options):
        for plugin_name, plugin_config in get_enabled_plugins():
            try:
                plugin_class = ('plugins.%s.%s' %
                                (plugin_name,
                                 plugin_name[0].upper() + plugin_name[1:]))
                script_name = plugin_config['wok']['uri']
                del plugin_config['wok']

                plugin_config.update(PluginConfig(plugin_name))
            except KeyError:
                continue

            try:
                plugin_app = import_class(plugin_class)(options)
            except ImportError, e:
                cherrypy.log.error_log.error(
                    "Failed to import plugin %s, "
                    "error: %s" % (plugin_class, e.message)
                )
                continue

            # dynamically extend plugin config with custom data, if provided
            get_custom_conf = getattr(plugin_app, "get_custom_conf", None)
            if get_custom_conf is not None:
                plugin_config.update(get_custom_conf())

            # dynamically add tools.wokauth.on = True to extra plugin APIs
            try:
                sub_nodes = import_class('plugins.%s.control.sub_nodes' %
                                         plugin_name)

                urlSubNodes = {}
                for ident, node in sub_nodes.items():
                    if node.url_auth:
                        ident = "/%s" % ident
                        urlSubNodes[ident] = {'tools.wokauth.on': True}

                    plugin_config.update(urlSubNodes)

            except ImportError, e:
                cherrypy.log.error_log.error(
                    "Failed to import subnodes for plugin %s, "
                    "error: %s" % (plugin_class, e.message)
                )
예제 #4
0
    def _load_plugins(self, options):
        for plugin_name, plugin_config in get_enabled_plugins():
            try:
                plugin_class = ('plugins.%s.%s' %
                                (plugin_name,
                                 plugin_name[0].upper() + plugin_name[1:]))
                del plugin_config['wok']
                plugin_config.update(PluginConfig(plugin_name))
            except KeyError:
                continue

            try:
                plugin_app = import_class(plugin_class)(options)
            except (ImportError, Exception), e:
                cherrypy.log.error_log.error(
                    "Failed to import plugin %s, "
                    "error: %s" % (plugin_class, e.message)
                )
                continue

            # dynamically extend plugin config with custom data, if provided
            get_custom_conf = getattr(plugin_app, "get_custom_conf", None)
            if get_custom_conf is not None:
                plugin_config.update(get_custom_conf())

            # dynamically add tools.wokauth.on = True to extra plugin APIs
            try:
                sub_nodes = import_class('plugins.%s.control.sub_nodes' %
                                         plugin_name)

                urlSubNodes = {}
                for ident, node in sub_nodes.items():
                    if node.url_auth:
                        ident = "/%s" % ident
                        urlSubNodes[ident] = {'tools.wokauth.on': True}

                    plugin_config.update(urlSubNodes)

            except ImportError, e:
                cherrypy.log.error_log.error(
                    "Failed to import subnodes for plugin %s, "
                    "error: %s" % (plugin_class, e.message)
                )
예제 #5
0
 def _load_plugins(self):
     for plugin_name, plugin_config in get_enabled_plugins():
         load_plugin(plugin_name, plugin_config)
예제 #6
0
def setUpModule():
    global test_server, model, host, port, ssl_port

    utils.patch_auth()
    host = '127.0.0.1'
    port = utils.get_free_port('http')
    ssl_port = utils.get_free_port('https')
    test_server = utils.run_server(host, port, ssl_port, test_mode=True)


def tearDownModule():
    test_server.stop()


@unittest.skipUnless(
    'sample' in [plugin for plugin, _config in get_enabled_plugins()],
    'sample plugin is not enabled, skip this test!')
class PluginTests(unittest.TestCase):

    def setUp(self):
        self.request = partial(utils.request, host, ssl_port)

    def _create_rectangle(self, name, length, width):
        req = json.dumps({'name': name, 'length': length, 'width': width})
        resp = self.request('/plugins/sample/rectangles', req, 'POST')
        return resp

    def _get_rectangle(self, name):
        resp = self.request('/plugins/sample/rectangles/%s' % name)
        return json.loads(resp.read())
예제 #7
0
파일: plugins.py 프로젝트: lcorreia/wok
 def get_list(self):
     # Will only return plugins that were loaded correctly by WOK and are
     # properly configured in cherrypy
     return [plugin for (plugin, config) in get_enabled_plugins()
             if config.get('wok').get('uri') in cherrypy.tree.apps.keys()]
예제 #8
0
파일: plugins.py 프로젝트: lcorreia/kimchi
 def get_list(self):
     return [plugin for (plugin, config) in get_enabled_plugins()]
예제 #9
0
def setUpModule():
    global test_server, model, host, port, ssl_port

    utils.patch_auth()
    host = '127.0.0.1'
    port = utils.get_free_port('http')
    ssl_port = utils.get_free_port('https')
    test_server = utils.run_server(host, port, ssl_port, test_mode=True)


def tearDownModule():
    test_server.stop()


@unittest.skipUnless(
    'sample' in [plugin for plugin, _config in get_enabled_plugins()],
    'sample plugin is not enabled, skip this test!')
class PluginTests(unittest.TestCase):

    def setUp(self):
        self.request = partial(utils.request, host, ssl_port)

    def _create_rectangle(self, name, length, width):
        req = json.dumps({'name': name, 'length': length, 'width': width})
        resp = self.request('/plugins/sample/rectangles', req, 'POST')
        return resp

    def _get_rectangle(self, name):
        resp = self.request('/plugins/sample/rectangles/%s' % name)
        return json.loads(resp.read())
예제 #10
0
 def get_list(self):
     return [plugin for (plugin, config) in get_enabled_plugins()]
예제 #11
0
 def _load_plugins(self):
     for plugin_name, plugin_config in get_enabled_plugins():
         load_plugin(plugin_name, plugin_config)