Browse Source

feat: 增加数据库redis的纳管功能

pull/7447/head
jiangweidong 3 years ago committed by 老广
parent
commit
aaaa87dd60
  1. 9
      apps/applications/const.py
  2. 1
      apps/applications/serializers/attrs/application_type/__init__.py
  3. 15
      apps/applications/serializers/attrs/application_type/redis.py
  4. 1
      apps/applications/serializers/attrs/attrs.py
  5. 2
      apps/assets/api/system_user.py
  6. 10
      apps/assets/filters.py
  7. 5
      apps/assets/models/user.py
  8. 3
      apps/assets/serializers/system_user.py
  9. 5
      apps/terminal/models/session.py

9
apps/applications/const.py

@ -17,6 +17,7 @@ class AppCategory(TextChoices):
class AppType(TextChoices):
# db category
mysql = 'mysql', 'MySQL'
redis = 'redis', 'Redis'
oracle = 'oracle', 'Oracle'
pgsql = 'postgresql', 'PostgreSQL'
mariadb = 'mariadb', 'MariaDB'
@ -34,7 +35,9 @@ class AppType(TextChoices):
@classmethod
def category_types_mapper(cls):
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.cloud: [cls.k8s]
}
@ -62,7 +65,3 @@ class AppType(TextChoices):
@classmethod
def cloud_types(cls):
return [tp.value for tp in cls.category_types_mapper()[AppCategory.cloud]]

1
apps/applications/serializers/attrs/application_type/__init__.py

@ -1,5 +1,6 @@
from .mysql import *
from .redis import *
from .mariadb import *
from .oracle import *
from .pgsql import *

15
apps/applications/serializers/attrs/application_type/redis.py

@ -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)

1
apps/applications/serializers/attrs/attrs.py

@ -25,6 +25,7 @@ category_serializer_classes_mapping = {
type_serializer_classes_mapping = {
# db
const.AppType.mysql.value: application_type.MySQLSerializer,
const.AppType.redis.value: application_type.RedisSerializer,
const.AppType.mariadb.value: application_type.MariaDBSerializer,
const.AppType.oracle.value: application_type.OracleSerializer,
const.AppType.pgsql.value: application_type.PostgreSerializer,

2
apps/assets/api/system_user.py

@ -19,6 +19,7 @@ from ..tasks import (
push_system_user_to_assets_manual, test_system_user_connectivity_manual,
push_system_user_to_assets
)
from ..filters import ProtocolInFilterBackend
logger = get_logger(__file__)
__all__ = [
@ -40,6 +41,7 @@ class SystemUserViewSet(SuggestionMixin, OrgBulkModelViewSet):
'type': ['exact', 'in'],
}
search_fields = filterset_fields
extra_filter_backends = [ProtocolInFilterBackend]
serializer_class = serializers.SystemUserSerializer
serializer_classes = {
'default': serializers.SystemUserSerializer,

10
apps/assets/filters.py

@ -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

5
apps/assets/models/user.py

@ -29,6 +29,8 @@ class ProtocolMixin:
telnet = 'telnet', 'Telnet'
vnc = 'vnc', 'VNC'
mysql = 'mysql', 'MySQL'
redis = 'redis', 'Redis'
redis_acl = 'redis_acl', 'Redis ACL'
oracle = 'oracle', 'Oracle'
mariadb = 'mariadb', 'MariaDB'
postgresql = 'postgresql', 'PostgreSQL'
@ -44,7 +46,8 @@ class ProtocolMixin:
Protocol.rdp
]
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 = [
Protocol.k8s

3
apps/assets/serializers/system_user.py

@ -119,7 +119,8 @@ class SystemUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer):
return ''
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.')
raise serializers.ValidationError(msg)
return username

5
apps/terminal/models/session.py

@ -29,6 +29,8 @@ class Session(OrgModelMixin):
VNC = 'vnc', 'vnc'
TELNET = 'telnet', 'telnet'
MYSQL = 'mysql', 'mysql'
REDIS = 'redis', 'redis'
REDIS_ACL = 'redis_acl', 'redis acl'
ORACLE = 'oracle', 'oracle'
MARIADB = 'mariadb', 'mariadb'
SQLSERVER = 'sqlserver', 'sqlserver'
@ -162,7 +164,8 @@ class Session(OrgModelMixin):
@property
def db_protocols(self):
_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
def can_terminate(self):

Loading…
Cancel
Save