From 262d070f3cbea29c5f4b3987f712c4844b055d0f Mon Sep 17 00:00:00 2001 From: jiangweidong Date: Tue, 18 Oct 2022 10:11:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E7=BA=B3=E7=AE=A1=20?= =?UTF-8?q?clickhouse[Web=20Terminal]?= 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 | 1 + .../serializers/attrs/application_type/clickhouse.py | 10 ++++++++++ apps/applications/serializers/attrs/attrs.py | 1 + apps/assets/models/user.py | 3 ++- apps/terminal/models/session.py | 3 ++- 6 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 apps/applications/serializers/attrs/application_type/clickhouse.py diff --git a/apps/applications/const.py b/apps/applications/const.py index 313477c25..0bf130f6f 100644 --- a/apps/applications/const.py +++ b/apps/applications/const.py @@ -27,6 +27,7 @@ class AppType(models.TextChoices): sqlserver = 'sqlserver', 'SQLServer' redis = 'redis', 'Redis' mongodb = 'mongodb', 'MongoDB' + clickhouse = 'clickhouse', 'ClickHouse' # remote-app category chrome = 'chrome', 'Chrome' @@ -42,7 +43,7 @@ class AppType(models.TextChoices): return { AppCategory.db: [ cls.mysql, cls.mariadb, cls.oracle, cls.pgsql, - cls.sqlserver, cls.redis, cls.mongodb + cls.sqlserver, cls.redis, cls.mongodb, cls.clickhouse ], AppCategory.remote_app: [ cls.chrome, cls.mysql_workbench, @@ -82,4 +83,4 @@ class AppType(models.TextChoices): if AppCategory.is_xpack(category): return True - return tp in ['oracle', 'postgresql', 'sqlserver'] + return tp in ['oracle', 'postgresql', 'sqlserver', 'clickhouse'] diff --git a/apps/applications/serializers/attrs/application_type/__init__.py b/apps/applications/serializers/attrs/application_type/__init__.py index 603dd89a4..cebf0027c 100644 --- a/apps/applications/serializers/attrs/application_type/__init__.py +++ b/apps/applications/serializers/attrs/application_type/__init__.py @@ -6,6 +6,7 @@ from .pgsql import * from .sqlserver import * from .redis import * from .mongodb import * +from .clickhouse import * from .chrome import * from .mysql_workbench import * diff --git a/apps/applications/serializers/attrs/application_type/clickhouse.py b/apps/applications/serializers/attrs/application_type/clickhouse.py new file mode 100644 index 000000000..5593f0fb1 --- /dev/null +++ b/apps/applications/serializers/attrs/application_type/clickhouse.py @@ -0,0 +1,10 @@ +from rest_framework import serializers +from django.utils.translation import ugettext_lazy as _ + +from ..application_category import DBSerializer + +__all__ = ['ClickHouseSerializer'] + + +class ClickHouseSerializer(DBSerializer): + port = serializers.IntegerField(default=9000, label=_('Port'), allow_null=True) diff --git a/apps/applications/serializers/attrs/attrs.py b/apps/applications/serializers/attrs/attrs.py index 1f3fb7944..ab49cd7f2 100644 --- a/apps/applications/serializers/attrs/attrs.py +++ b/apps/applications/serializers/attrs/attrs.py @@ -31,6 +31,7 @@ type_serializer_classes_mapping = { const.AppType.sqlserver.value: application_type.SQLServerSerializer, const.AppType.redis.value: application_type.RedisSerializer, const.AppType.mongodb.value: application_type.MongoDBSerializer, + const.AppType.clickhouse.value: application_type.ClickHouseSerializer, # cloud const.AppType.k8s.value: application_type.K8SSerializer } diff --git a/apps/assets/models/user.py b/apps/assets/models/user.py index e20664071..4c7454594 100644 --- a/apps/assets/models/user.py +++ b/apps/assets/models/user.py @@ -34,6 +34,7 @@ class ProtocolMixin: sqlserver = 'sqlserver', 'SQLServer' redis = 'redis', 'Redis' mongodb = 'mongodb', 'MongoDB' + clickhouse = 'clickhouse', 'ClickHouse' k8s = 'k8s', 'K8S' SUPPORT_PUSH_PROTOCOLS = [Protocol.ssh, Protocol.rdp] @@ -46,7 +47,7 @@ class ProtocolMixin: ] APPLICATION_CATEGORY_DB_PROTOCOLS = [ Protocol.mysql, Protocol.mariadb, Protocol.oracle, - Protocol.postgresql, Protocol.sqlserver, + Protocol.postgresql, Protocol.sqlserver, Protocol.clickhouse, Protocol.redis, Protocol.mongodb ] APPLICATION_CATEGORY_CLOUD_PROTOCOLS = [ diff --git a/apps/terminal/models/session.py b/apps/terminal/models/session.py index 8eff9368b..3f6a8c338 100644 --- a/apps/terminal/models/session.py +++ b/apps/terminal/models/session.py @@ -38,6 +38,7 @@ class Session(OrgModelMixin): POSTGRESQL = 'postgresql', 'postgresql' REDIS = 'redis', 'redis' MONGODB = 'mongodb', 'MongoDB' + CLICKHOUSE = 'clickhouse', 'ClickHouse' K8S = 'k8s', 'kubernetes' id = models.UUIDField(default=uuid.uuid4, primary_key=True) @@ -150,7 +151,7 @@ class Session(OrgModelMixin): def db_protocols(self): _PROTOCOL = self.PROTOCOL return [_PROTOCOL.MYSQL, _PROTOCOL.MARIADB, _PROTOCOL.ORACLE, - _PROTOCOL.POSTGRESQL, _PROTOCOL.SQLSERVER, + _PROTOCOL.POSTGRESQL, _PROTOCOL.SQLSERVER, _PROTOCOL.CLICKHOUSE, _PROTOCOL.REDIS, _PROTOCOL.MONGODB] @property