jumpserver/apps/terminal/backends/__init__.py

43 lines
1.1 KiB
Python
Raw Normal View History

2017-11-29 11:27:04 +00:00
from importlib import import_module
from django.conf import settings
from .command.serializers import SessionCommandSerializer
from common import utils
2018-01-20 14:22:09 +00:00
TYPE_ENGINE_MAPPING = {
2018-01-21 09:27:27 +00:00
'elasticsearch': 'terminal.backends.command.es',
2018-01-20 14:22:09 +00:00
}
2017-11-29 11:27:04 +00:00
2018-05-22 10:22:06 +00:00
def get_command_storage():
config = settings.COMMAND_STORAGE
engine_class = import_module(config['ENGINE'])
storage = engine_class.CommandStore(config)
2018-01-20 14:22:09 +00:00
return storage
2018-05-22 10:22:06 +00:00
def get_terminal_command_storages():
2018-01-20 14:22:09 +00:00
storage_list = {}
2018-11-19 04:18:52 +00:00
command_storage = utils.get_command_storage_setting()
for name, params in command_storage.items():
2018-01-20 14:22:09 +00:00
tp = params['TYPE']
if tp == 'server':
2018-05-22 10:22:06 +00:00
storage = get_command_storage()
2018-01-20 14:22:09 +00:00
else:
if not TYPE_ENGINE_MAPPING.get(tp):
continue
2018-01-20 14:22:09 +00:00
engine_class = import_module(TYPE_ENGINE_MAPPING[tp])
storage = engine_class.CommandStore(params)
storage_list[name] = storage
return storage_list
2018-05-22 10:22:06 +00:00
def get_multi_command_storage():
2018-01-21 09:27:27 +00:00
from .command.multi import CommandStore
2018-05-22 10:22:06 +00:00
storage_list = get_terminal_command_storages().values()
2018-01-21 09:27:27 +00:00
storage = CommandStore(storage_list)
return storage
2017-11-29 11:27:04 +00:00