2019-05-20 11:39:53 +00:00
|
|
|
# coding: utf-8
|
|
|
|
#
|
2022-02-21 08:24:03 +00:00
|
|
|
from django.db import models
|
2019-05-20 11:39:53 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
|
|
|
|
2022-02-21 08:24:03 +00:00
|
|
|
class AppCategory(models.TextChoices):
|
2021-01-03 21:27:03 +00:00
|
|
|
db = 'db', _('Database')
|
|
|
|
remote_app = 'remote_app', _('Remote app')
|
|
|
|
cloud = 'cloud', 'Cloud'
|
2019-12-19 07:28:17 +00:00
|
|
|
|
2021-01-03 21:27:03 +00:00
|
|
|
@classmethod
|
|
|
|
def get_label(cls, category):
|
|
|
|
return dict(cls.choices).get(category, '')
|
2019-05-20 11:39:53 +00:00
|
|
|
|
2022-03-15 12:02:08 +00:00
|
|
|
@classmethod
|
|
|
|
def is_xpack(cls, category):
|
|
|
|
return category in ['remote_app']
|
|
|
|
|
2019-05-20 11:39:53 +00:00
|
|
|
|
2022-02-21 08:24:03 +00:00
|
|
|
class AppType(models.TextChoices):
|
2021-01-03 21:27:03 +00:00
|
|
|
# db category
|
|
|
|
mysql = 'mysql', 'MySQL'
|
2022-03-15 12:02:08 +00:00
|
|
|
mariadb = 'mariadb', 'MariaDB'
|
2021-01-03 21:27:03 +00:00
|
|
|
oracle = 'oracle', 'Oracle'
|
|
|
|
pgsql = 'postgresql', 'PostgreSQL'
|
2021-11-18 08:44:33 +00:00
|
|
|
sqlserver = 'sqlserver', 'SQLServer'
|
2022-02-22 02:09:48 +00:00
|
|
|
redis = 'redis', 'Redis'
|
|
|
|
mongodb = 'mongodb', 'MongoDB'
|
2019-05-20 11:39:53 +00:00
|
|
|
|
2021-01-03 21:27:03 +00:00
|
|
|
# remote-app category
|
|
|
|
chrome = 'chrome', 'Chrome'
|
|
|
|
mysql_workbench = 'mysql_workbench', 'MySQL Workbench'
|
|
|
|
vmware_client = 'vmware_client', 'vSphere Client'
|
|
|
|
custom = 'custom', _('Custom')
|
2019-05-20 11:39:53 +00:00
|
|
|
|
2021-01-03 21:27:03 +00:00
|
|
|
# cloud category
|
|
|
|
k8s = 'k8s', 'Kubernetes'
|
2019-12-10 07:16:16 +00:00
|
|
|
|
2021-07-27 08:06:00 +00:00
|
|
|
@classmethod
|
|
|
|
def category_types_mapper(cls):
|
|
|
|
return {
|
2021-12-23 03:13:32 +00:00
|
|
|
AppCategory.db: [
|
2022-03-25 06:45:08 +00:00
|
|
|
cls.mysql, cls.mariadb, cls.oracle, cls.pgsql,
|
2022-03-15 12:02:08 +00:00
|
|
|
cls.sqlserver, cls.redis, cls.mongodb
|
|
|
|
],
|
|
|
|
AppCategory.remote_app: [
|
|
|
|
cls.chrome, cls.mysql_workbench,
|
|
|
|
cls.vmware_client, cls.custom
|
2021-12-23 03:13:32 +00:00
|
|
|
],
|
2021-07-27 08:06:00 +00:00
|
|
|
AppCategory.cloud: [cls.k8s]
|
|
|
|
}
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def type_category_mapper(cls):
|
|
|
|
mapper = {}
|
|
|
|
for category, tps in cls.category_types_mapper().items():
|
|
|
|
for tp in tps:
|
|
|
|
mapper[tp] = category
|
|
|
|
return mapper
|
|
|
|
|
2021-01-03 21:27:03 +00:00
|
|
|
@classmethod
|
|
|
|
def get_label(cls, tp):
|
|
|
|
return dict(cls.choices).get(tp, '')
|
2019-12-19 07:28:17 +00:00
|
|
|
|
2021-01-03 21:27:03 +00:00
|
|
|
@classmethod
|
|
|
|
def db_types(cls):
|
2021-07-27 08:06:00 +00:00
|
|
|
return [tp.value for tp in cls.category_types_mapper()[AppCategory.db]]
|
2019-12-19 07:28:17 +00:00
|
|
|
|
2021-01-03 21:27:03 +00:00
|
|
|
@classmethod
|
|
|
|
def remote_app_types(cls):
|
2021-07-27 08:06:00 +00:00
|
|
|
return [tp.value for tp in cls.category_types_mapper()[AppCategory.remote_app]]
|
2019-12-19 07:28:17 +00:00
|
|
|
|
2021-01-03 21:27:03 +00:00
|
|
|
@classmethod
|
|
|
|
def cloud_types(cls):
|
2021-07-27 08:06:00 +00:00
|
|
|
return [tp.value for tp in cls.category_types_mapper()[AppCategory.cloud]]
|
2022-03-15 12:02:08 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def is_xpack(cls, tp):
|
|
|
|
tp_category_mapper = cls.type_category_mapper()
|
|
|
|
category = tp_category_mapper[tp]
|
|
|
|
|
|
|
|
if AppCategory.is_xpack(category):
|
|
|
|
return True
|
|
|
|
return tp in ['oracle', 'postgresql', 'sqlserver']
|
2022-07-13 08:29:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OracleVersion(models.TextChoices):
|
|
|
|
version_11g = '11g', '11g'
|
|
|
|
version_12c = '12c', '12c'
|
|
|
|
version_other = 'other', _('Other')
|