2021-01-05 15:39:38 +00:00
|
|
|
from rest_framework import serializers
|
2021-01-03 21:27:03 +00:00
|
|
|
from applications import const
|
2021-01-05 15:39:38 +00:00
|
|
|
from . import application_category, application_type
|
2021-01-03 21:27:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
__all__ = [
|
2021-01-05 15:39:38 +00:00
|
|
|
'attrs_field_dynamic_mapping_serializers',
|
|
|
|
'get_serializer_class_by_application_type',
|
2021-01-03 21:27:03 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
|
2021-01-05 15:39:38 +00:00
|
|
|
# define `attrs` field `dynamic mapping serializers`
|
|
|
|
# --------------------------------------------------
|
2021-01-03 21:27:03 +00:00
|
|
|
|
|
|
|
|
2021-01-05 15:39:38 +00:00
|
|
|
attrs_field_dynamic_mapping_serializers = {
|
2021-01-03 21:27:03 +00:00
|
|
|
'category': {
|
2021-01-05 15:39:38 +00:00
|
|
|
category_db: application_category.DBSerializer,
|
|
|
|
category_remote_app: application_category.RemoteAppSerializer,
|
|
|
|
category_cloud: application_category.CloudSerializer,
|
2021-01-03 21:27:03 +00:00
|
|
|
},
|
|
|
|
'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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-05 15:39:38 +00:00
|
|
|
def get_serializer_class_by_application_type(_application_type):
|
|
|
|
return attrs_field_dynamic_mapping_serializers['type'].get(_application_type)
|