forked from savon-noir/python-libnmap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackendpluginFactory.py
More file actions
32 lines (30 loc) · 1.3 KB
/
backendpluginFactory.py
File metadata and controls
32 lines (30 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
import sys
import inspect
class BackendPluginFactory(object):
"""
This is a backend plugin factory a backend instance MUST be
created via the static method create()
ie : mybackend = BackendPluginFactory.create()
"""
@classmethod
def create(cls, plugin_name="mongodb", **kwargs):
"""Import the needed lib and return an object NmapBackendPlugin
representing the backend of your desire.
NmapBackendPlugin is an abstract class, to know what argument
need to be given, review the code of the subclass you need
:param plugin_name: str : name of the py file without .py
:return: NmapBackend (abstract class on top of all plugin)
"""
backendplugin = None
plugin_path = "libnmap.plugins.%s" % (plugin_name)
__import__(plugin_path)
pluginobj = sys.modules[plugin_path]
pluginclasses = inspect.getmembers(pluginobj, inspect.isclass)
for classname, classobj in pluginclasses:
if inspect.getmodule(classobj).__name__.find(plugin_path) == 0:
try:
backendplugin = classobj(**kwargs)
except Exception as error:
print "Cannot create Backend: %s" % (error)
return backendplugin