mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-13 13:59:17 +00:00
reactor&remove: 重构applications模块 & 移除applications、perms中已不再使用的模块 (#5374)
* reactor: 重构applications模块 & 删除applications、perms中已不再使用的模块 * reactor: 1. 针对application.attrs字段的view-serializer映射逻辑,采用DynamicMapping的方案重写; * reactor: 2. 删除applications和perms模块中已不再使用的database-app/k8s-app/remote-app模块; * reactor: 添加迁移文件(删除perms/databaseperrmission/remoteapppermission/k8sapppermission) * reactor: 修改细节 Co-authored-by: Bai <bugatti_it@163.com>
This commit is contained in:
94
apps/applications/serializers/attrs/attrs.py
Normal file
94
apps/applications/serializers/attrs/attrs.py
Normal file
@@ -0,0 +1,94 @@
|
||||
import copy
|
||||
from applications import const
|
||||
from common.drf.fields import IgnoreSensitiveInfoReadOnlyJSONField
|
||||
from . import category, type as application_type
|
||||
|
||||
|
||||
__all__ = [
|
||||
'get_attrs_field_dynamic_mapping_rules', 'get_attrs_field_mapping_rule_by_view',
|
||||
'get_serializer_by_application_type',
|
||||
]
|
||||
|
||||
|
||||
# application category
|
||||
# --------------------
|
||||
|
||||
category_db = const.ApplicationCategoryChoices.db.value
|
||||
category_remote_app = const.ApplicationCategoryChoices.remote_app.value
|
||||
category_cloud = const.ApplicationCategoryChoices.cloud.value
|
||||
|
||||
|
||||
# application type
|
||||
# ----------------
|
||||
|
||||
# db
|
||||
type_mysql = const.ApplicationTypeChoices.mysql.value
|
||||
type_mariadb = const.ApplicationTypeChoices.mariadb.value
|
||||
type_oracle = const.ApplicationTypeChoices.oracle.value
|
||||
type_pgsql = const.ApplicationTypeChoices.pgsql.value
|
||||
# remote-app
|
||||
type_chrome = const.ApplicationTypeChoices.chrome.value
|
||||
type_mysql_workbench = const.ApplicationTypeChoices.mysql_workbench.value
|
||||
type_vmware_client = const.ApplicationTypeChoices.vmware_client.value
|
||||
type_custom = const.ApplicationTypeChoices.custom.value
|
||||
# cloud
|
||||
type_k8s = const.ApplicationTypeChoices.k8s.value
|
||||
|
||||
|
||||
# define `attrs` field `DynamicMappingField` mapping_rules
|
||||
# -----------------------------------------------------
|
||||
|
||||
|
||||
__ATTRS_FIELD_DYNAMIC_MAPPING_RULES = {
|
||||
'default': IgnoreSensitiveInfoReadOnlyJSONField,
|
||||
'category': {
|
||||
category_db: category.DBSerializer,
|
||||
category_remote_app: category.RemoteAppSerializer,
|
||||
category_cloud: category.CloudSerializer,
|
||||
},
|
||||
'type': {
|
||||
# db
|
||||
type_mysql: application_type.MySQLSerializer,
|
||||
type_mariadb: application_type.MariaDBSerializer,
|
||||
type_oracle: application_type.OracleSerializer,
|
||||
type_pgsql: application_type.PostgreSerializer,
|
||||
# remote-app
|
||||
type_chrome: application_type.ChromeSerializer,
|
||||
type_mysql_workbench: application_type.MySQLWorkbenchSerializer,
|
||||
type_vmware_client: application_type.VMwareClientSerializer,
|
||||
type_custom: application_type.CustomSerializer,
|
||||
# cloud
|
||||
type_k8s: application_type.K8SSerializer
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Note:
|
||||
# The dynamic mapping rules of `attrs` field is obtained
|
||||
# through call method `get_attrs_field_dynamic_mapping_rules`
|
||||
|
||||
def get_attrs_field_dynamic_mapping_rules():
|
||||
return copy.deepcopy(__ATTRS_FIELD_DYNAMIC_MAPPING_RULES)
|
||||
|
||||
|
||||
# get `attrs dynamic field` mapping rule by `view object`
|
||||
# ----------------------------------------------------
|
||||
|
||||
|
||||
def get_attrs_field_mapping_rule_by_view(view):
|
||||
query_type = view.request.query_params.get('type')
|
||||
query_category = view.request.query_params.get('category')
|
||||
if query_type:
|
||||
mapping_rule = ['type', query_type]
|
||||
elif query_category:
|
||||
mapping_rule = ['category', query_category]
|
||||
else:
|
||||
mapping_rule = ['default']
|
||||
return mapping_rule
|
||||
|
||||
|
||||
# get `category` mapping `serializer`
|
||||
# -----------------------------------
|
||||
|
||||
def get_serializer_by_application_type(app_tp):
|
||||
return __ATTRS_FIELD_DYNAMIC_MAPPING_RULES['type'].get(app_tp)
|
Reference in New Issue
Block a user