mirror of https://github.com/jumpserver/jumpserver
feat: 增加数据库redis的纳管功能
parent
24cad76232
commit
aaaa87dd60
|
@ -17,6 +17,7 @@ class AppCategory(TextChoices):
|
||||||
class AppType(TextChoices):
|
class AppType(TextChoices):
|
||||||
# db category
|
# db category
|
||||||
mysql = 'mysql', 'MySQL'
|
mysql = 'mysql', 'MySQL'
|
||||||
|
redis = 'redis', 'Redis'
|
||||||
oracle = 'oracle', 'Oracle'
|
oracle = 'oracle', 'Oracle'
|
||||||
pgsql = 'postgresql', 'PostgreSQL'
|
pgsql = 'postgresql', 'PostgreSQL'
|
||||||
mariadb = 'mariadb', 'MariaDB'
|
mariadb = 'mariadb', 'MariaDB'
|
||||||
|
@ -34,7 +35,9 @@ class AppType(TextChoices):
|
||||||
@classmethod
|
@classmethod
|
||||||
def category_types_mapper(cls):
|
def category_types_mapper(cls):
|
||||||
return {
|
return {
|
||||||
AppCategory.db: [cls.mysql, cls.oracle, cls.pgsql, cls.mariadb, cls.sqlserver],
|
AppCategory.db: [
|
||||||
|
cls.mysql, cls.oracle, cls.redis, cls.pgsql, cls.mariadb, cls.sqlserver
|
||||||
|
],
|
||||||
AppCategory.remote_app: [cls.chrome, cls.mysql_workbench, cls.vmware_client, cls.custom],
|
AppCategory.remote_app: [cls.chrome, cls.mysql_workbench, cls.vmware_client, cls.custom],
|
||||||
AppCategory.cloud: [cls.k8s]
|
AppCategory.cloud: [cls.k8s]
|
||||||
}
|
}
|
||||||
|
@ -62,7 +65,3 @@ class AppType(TextChoices):
|
||||||
@classmethod
|
@classmethod
|
||||||
def cloud_types(cls):
|
def cloud_types(cls):
|
||||||
return [tp.value for tp in cls.category_types_mapper()[AppCategory.cloud]]
|
return [tp.value for tp in cls.category_types_mapper()[AppCategory.cloud]]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
from .mysql import *
|
from .mysql import *
|
||||||
|
from .redis import *
|
||||||
from .mariadb import *
|
from .mariadb import *
|
||||||
from .oracle import *
|
from .oracle import *
|
||||||
from .pgsql import *
|
from .pgsql import *
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
from rest_framework import serializers
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from ..application_category import DBSerializer
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ['RedisSerializer']
|
||||||
|
|
||||||
|
|
||||||
|
class RedisSerializer(DBSerializer):
|
||||||
|
port = serializers.IntegerField(default=6379, label=_('Port'), allow_null=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ category_serializer_classes_mapping = {
|
||||||
type_serializer_classes_mapping = {
|
type_serializer_classes_mapping = {
|
||||||
# db
|
# db
|
||||||
const.AppType.mysql.value: application_type.MySQLSerializer,
|
const.AppType.mysql.value: application_type.MySQLSerializer,
|
||||||
|
const.AppType.redis.value: application_type.RedisSerializer,
|
||||||
const.AppType.mariadb.value: application_type.MariaDBSerializer,
|
const.AppType.mariadb.value: application_type.MariaDBSerializer,
|
||||||
const.AppType.oracle.value: application_type.OracleSerializer,
|
const.AppType.oracle.value: application_type.OracleSerializer,
|
||||||
const.AppType.pgsql.value: application_type.PostgreSerializer,
|
const.AppType.pgsql.value: application_type.PostgreSerializer,
|
||||||
|
|
|
@ -19,6 +19,7 @@ from ..tasks import (
|
||||||
push_system_user_to_assets_manual, test_system_user_connectivity_manual,
|
push_system_user_to_assets_manual, test_system_user_connectivity_manual,
|
||||||
push_system_user_to_assets
|
push_system_user_to_assets
|
||||||
)
|
)
|
||||||
|
from ..filters import ProtocolInFilterBackend
|
||||||
|
|
||||||
logger = get_logger(__file__)
|
logger = get_logger(__file__)
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
@ -40,6 +41,7 @@ class SystemUserViewSet(SuggestionMixin, OrgBulkModelViewSet):
|
||||||
'type': ['exact', 'in'],
|
'type': ['exact', 'in'],
|
||||||
}
|
}
|
||||||
search_fields = filterset_fields
|
search_fields = filterset_fields
|
||||||
|
extra_filter_backends = [ProtocolInFilterBackend]
|
||||||
serializer_class = serializers.SystemUserSerializer
|
serializer_class = serializers.SystemUserSerializer
|
||||||
serializer_classes = {
|
serializer_classes = {
|
||||||
'default': serializers.SystemUserSerializer,
|
'default': serializers.SystemUserSerializer,
|
||||||
|
|
|
@ -149,3 +149,13 @@ class IpInFilterBackend(filters.BaseFilterBackend):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class ProtocolInFilterBackend(filters.BaseFilterBackend):
|
||||||
|
def filter_queryset(self, request, queryset, view):
|
||||||
|
protocols = request.query_params.get('protocols')
|
||||||
|
if not protocols:
|
||||||
|
return queryset
|
||||||
|
protocol_list = [i.strip() for i in protocols.split(',')]
|
||||||
|
queryset = queryset.filter(protocol__in=protocol_list)
|
||||||
|
return queryset
|
||||||
|
|
|
@ -29,6 +29,8 @@ class ProtocolMixin:
|
||||||
telnet = 'telnet', 'Telnet'
|
telnet = 'telnet', 'Telnet'
|
||||||
vnc = 'vnc', 'VNC'
|
vnc = 'vnc', 'VNC'
|
||||||
mysql = 'mysql', 'MySQL'
|
mysql = 'mysql', 'MySQL'
|
||||||
|
redis = 'redis', 'Redis'
|
||||||
|
redis_acl = 'redis_acl', 'Redis ACL'
|
||||||
oracle = 'oracle', 'Oracle'
|
oracle = 'oracle', 'Oracle'
|
||||||
mariadb = 'mariadb', 'MariaDB'
|
mariadb = 'mariadb', 'MariaDB'
|
||||||
postgresql = 'postgresql', 'PostgreSQL'
|
postgresql = 'postgresql', 'PostgreSQL'
|
||||||
|
@ -44,7 +46,8 @@ class ProtocolMixin:
|
||||||
Protocol.rdp
|
Protocol.rdp
|
||||||
]
|
]
|
||||||
APPLICATION_CATEGORY_DB_PROTOCOLS = [
|
APPLICATION_CATEGORY_DB_PROTOCOLS = [
|
||||||
Protocol.mysql, Protocol.oracle, Protocol.mariadb, Protocol.postgresql, Protocol.sqlserver
|
Protocol.mysql, Protocol.redis, Protocol.redis_acl, Protocol.oracle,
|
||||||
|
Protocol.mariadb, Protocol.postgresql, Protocol.sqlserver
|
||||||
]
|
]
|
||||||
APPLICATION_CATEGORY_CLOUD_PROTOCOLS = [
|
APPLICATION_CATEGORY_CLOUD_PROTOCOLS = [
|
||||||
Protocol.k8s
|
Protocol.k8s
|
||||||
|
|
|
@ -119,7 +119,8 @@ class SystemUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
login_mode = self.get_initial_value("login_mode")
|
login_mode = self.get_initial_value("login_mode")
|
||||||
if login_mode == SystemUser.LOGIN_AUTO and protocol != SystemUser.Protocol.vnc:
|
if login_mode == SystemUser.LOGIN_AUTO and protocol != SystemUser.Protocol.vnc \
|
||||||
|
and protocol != SystemUser.Protocol.redis:
|
||||||
msg = _('* Automatic login mode must fill in the username.')
|
msg = _('* Automatic login mode must fill in the username.')
|
||||||
raise serializers.ValidationError(msg)
|
raise serializers.ValidationError(msg)
|
||||||
return username
|
return username
|
||||||
|
|
|
@ -29,6 +29,8 @@ class Session(OrgModelMixin):
|
||||||
VNC = 'vnc', 'vnc'
|
VNC = 'vnc', 'vnc'
|
||||||
TELNET = 'telnet', 'telnet'
|
TELNET = 'telnet', 'telnet'
|
||||||
MYSQL = 'mysql', 'mysql'
|
MYSQL = 'mysql', 'mysql'
|
||||||
|
REDIS = 'redis', 'redis'
|
||||||
|
REDIS_ACL = 'redis_acl', 'redis acl'
|
||||||
ORACLE = 'oracle', 'oracle'
|
ORACLE = 'oracle', 'oracle'
|
||||||
MARIADB = 'mariadb', 'mariadb'
|
MARIADB = 'mariadb', 'mariadb'
|
||||||
SQLSERVER = 'sqlserver', 'sqlserver'
|
SQLSERVER = 'sqlserver', 'sqlserver'
|
||||||
|
@ -162,7 +164,8 @@ class Session(OrgModelMixin):
|
||||||
@property
|
@property
|
||||||
def db_protocols(self):
|
def db_protocols(self):
|
||||||
_PROTOCOL = self.PROTOCOL
|
_PROTOCOL = self.PROTOCOL
|
||||||
return [_PROTOCOL.MYSQL, _PROTOCOL.MARIADB, _PROTOCOL.ORACLE, _PROTOCOL.POSTGRESQL, _PROTOCOL.SQLSERVER]
|
return [_PROTOCOL.MYSQL, _PROTOCOL.MARIADB, _PROTOCOL.REDIS, _PROTOCOL.REDIS_ACL,
|
||||||
|
_PROTOCOL.ORACLE, _PROTOCOL.POSTGRESQL, _PROTOCOL.SQLSERVER]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def can_terminate(self):
|
def can_terminate(self):
|
||||||
|
|
Loading…
Reference in New Issue