From ad2cb233d7beb401a1e4946dd21ec8c2aa0ab37e Mon Sep 17 00:00:00 2001 From: jiangweidong <80373698+f2c-jiangweidong@users.noreply.github.com> Date: Tue, 22 Feb 2022 10:09:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20MongoDB=20?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E7=9A=84=E7=BA=B3=E7=AE=A1=20(#7631?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/applications/const.py | 5 +++-- .../serializers/attrs/application_type/__init__.py | 3 ++- .../serializers/attrs/application_type/mongodb.py | 11 +++++++++++ apps/applications/serializers/attrs/attrs.py | 3 ++- apps/assets/models/user.py | 8 +++++--- apps/terminal/models/session.py | 8 +++++--- 6 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 apps/applications/serializers/attrs/application_type/mongodb.py diff --git a/apps/applications/const.py b/apps/applications/const.py index 23cf409c9..76fc51e33 100644 --- a/apps/applications/const.py +++ b/apps/applications/const.py @@ -17,11 +17,12 @@ class AppCategory(models.TextChoices): class AppType(models.TextChoices): # db category mysql = 'mysql', 'MySQL' - redis = 'redis', 'Redis' oracle = 'oracle', 'Oracle' pgsql = 'postgresql', 'PostgreSQL' mariadb = 'mariadb', 'MariaDB' sqlserver = 'sqlserver', 'SQLServer' + redis = 'redis', 'Redis' + mongodb = 'mongodb', 'MongoDB' # remote-app category chrome = 'chrome', 'Chrome' @@ -36,7 +37,7 @@ class AppType(models.TextChoices): def category_types_mapper(cls): return { AppCategory.db: [ - cls.mysql, cls.oracle, cls.redis, cls.pgsql, cls.mariadb, cls.sqlserver + cls.mysql, cls.oracle, cls.pgsql, cls.mariadb, cls.sqlserver, cls.redis, cls.mongodb ], AppCategory.remote_app: [cls.chrome, cls.mysql_workbench, cls.vmware_client, cls.custom], AppCategory.cloud: [cls.k8s] diff --git a/apps/applications/serializers/attrs/application_type/__init__.py b/apps/applications/serializers/attrs/application_type/__init__.py index 94a6f921d..603dd89a4 100644 --- a/apps/applications/serializers/attrs/application_type/__init__.py +++ b/apps/applications/serializers/attrs/application_type/__init__.py @@ -1,10 +1,11 @@ from .mysql import * -from .redis import * from .mariadb import * from .oracle import * from .pgsql import * from .sqlserver import * +from .redis import * +from .mongodb import * from .chrome import * from .mysql_workbench import * diff --git a/apps/applications/serializers/attrs/application_type/mongodb.py b/apps/applications/serializers/attrs/application_type/mongodb.py new file mode 100644 index 000000000..3824e9c8a --- /dev/null +++ b/apps/applications/serializers/attrs/application_type/mongodb.py @@ -0,0 +1,11 @@ +from rest_framework import serializers +from django.utils.translation import ugettext_lazy as _ + +from ..application_category import DBSerializer + +__all__ = ['MongoDBSerializer'] + + +class MongoDBSerializer(DBSerializer): + port = serializers.IntegerField(default=27017, label=_('Port'), allow_null=True) + diff --git a/apps/applications/serializers/attrs/attrs.py b/apps/applications/serializers/attrs/attrs.py index a1ca0a3da..1f3fb7944 100644 --- a/apps/applications/serializers/attrs/attrs.py +++ b/apps/applications/serializers/attrs/attrs.py @@ -25,11 +25,12 @@ 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, const.AppType.sqlserver.value: application_type.SQLServerSerializer, + const.AppType.redis.value: application_type.RedisSerializer, + const.AppType.mongodb.value: application_type.MongoDBSerializer, # cloud const.AppType.k8s.value: application_type.K8SSerializer } diff --git a/apps/assets/models/user.py b/apps/assets/models/user.py index 428723a11..609a512e7 100644 --- a/apps/assets/models/user.py +++ b/apps/assets/models/user.py @@ -28,11 +28,12 @@ class ProtocolMixin: telnet = 'telnet', 'Telnet' vnc = 'vnc', 'VNC' mysql = 'mysql', 'MySQL' - redis = 'redis', 'Redis' oracle = 'oracle', 'Oracle' mariadb = 'mariadb', 'MariaDB' postgresql = 'postgresql', 'PostgreSQL' sqlserver = 'sqlserver', 'SQLServer' + redis = 'redis', 'Redis' + mongodb = 'mongodb', 'MongoDB' k8s = 'k8s', 'K8S' SUPPORT_PUSH_PROTOCOLS = [Protocol.ssh, Protocol.rdp] @@ -44,8 +45,9 @@ class ProtocolMixin: Protocol.rdp ] APPLICATION_CATEGORY_DB_PROTOCOLS = [ - Protocol.mysql, Protocol.redis, Protocol.oracle, - Protocol.mariadb, Protocol.postgresql, Protocol.sqlserver + Protocol.mysql, Protocol.mariadb, Protocol.oracle, + Protocol.postgresql, Protocol.sqlserver, + Protocol.redis, Protocol.mongodb ] APPLICATION_CATEGORY_CLOUD_PROTOCOLS = [ Protocol.k8s diff --git a/apps/terminal/models/session.py b/apps/terminal/models/session.py index c5064beea..5bd71d25a 100644 --- a/apps/terminal/models/session.py +++ b/apps/terminal/models/session.py @@ -29,11 +29,12 @@ class Session(OrgModelMixin): VNC = 'vnc', 'vnc' TELNET = 'telnet', 'telnet' MYSQL = 'mysql', 'mysql' - REDIS = 'redis', 'redis' ORACLE = 'oracle', 'oracle' MARIADB = 'mariadb', 'mariadb' SQLSERVER = 'sqlserver', 'sqlserver' POSTGRESQL = 'postgresql', 'postgresql' + REDIS = 'redis', 'redis' + MONGODB = 'mongodb', 'MongoDB' K8S = 'k8s', 'kubernetes' id = models.UUIDField(default=uuid.uuid4, primary_key=True) @@ -145,8 +146,9 @@ class Session(OrgModelMixin): @property def db_protocols(self): _PROTOCOL = self.PROTOCOL - return [_PROTOCOL.MYSQL, _PROTOCOL.MARIADB, _PROTOCOL.REDIS, - _PROTOCOL.ORACLE, _PROTOCOL.POSTGRESQL, _PROTOCOL.SQLSERVER] + return [_PROTOCOL.MYSQL, _PROTOCOL.MARIADB, _PROTOCOL.ORACLE, + _PROTOCOL.POSTGRESQL, _PROTOCOL.SQLSERVER, + _PROTOCOL.REDIS, _PROTOCOL.MONGODB] @property def can_terminate(self):