diff --git a/apps/assets/api/node.py b/apps/assets/api/node.py index 45b2b27bf..6519c1020 100644 --- a/apps/assets/api/node.py +++ b/apps/assets/api/node.py @@ -202,7 +202,7 @@ class NodeChildrenAsTreeApi(SerializeToTreeNodeMixin, NodeChildrenApi): return [] assets = self.instance.get_assets().only( "id", "name", "ip", "platform_id", - "org_id", "protocols", "is_active", + "org_id", "is_active", ).prefetch_related('platform') return self.serialize_assets(assets, self.instance.key) diff --git a/apps/assets/const/base.py b/apps/assets/const/base.py index cad913e6b..e9d90958a 100644 --- a/apps/assets/const/base.py +++ b/apps/assets/const/base.py @@ -30,11 +30,11 @@ class BaseType(TextChoices): @classmethod def _parse_protocols(cls, protocol, tp): - default_ports = Protocol.default_ports() + settings = Protocol.settings() choices = protocol.get('choices', []) if choices == '__self__': choices = [tp] - protocols = [{'name': name, 'port': default_ports.get(name, 0)} for name in choices] + protocols = [{'name': name, **settings.get(name, {})} for name in choices] return protocols @classmethod diff --git a/apps/assets/const/protocol.py b/apps/assets/const/protocol.py index 7b283428b..5a556a17e 100644 --- a/apps/assets/const/protocol.py +++ b/apps/assets/const/protocol.py @@ -6,7 +6,6 @@ __all__ = ['Protocol'] class Protocol(ChoicesMixin, models.TextChoices): ssh = 'ssh', 'SSH' - sftp = 'sftp', 'SFTP' rdp = 'rdp', 'RDP' telnet = 'telnet', 'Telnet' vnc = 'vnc', 'VNC' @@ -24,15 +23,95 @@ class Protocol(ChoicesMixin, models.TextChoices): https = 'https', 'HTTPS' @classmethod - def host_protocols(cls): - return [cls.ssh, cls.rdp, cls.telnet, cls.vnc] + def device_settings(cls): + return { + cls.ssh: { + 'port': 22, + 'secret_type': ['password', 'ssh_key'], + 'setting': { + 'sftp_enabled': True, + 'sftp_home': '/tmp', + } + }, + cls.rdp: { + 'port': 3389, + 'secret_type': ['password'], + 'setting': { + 'console': True, + 'security': 'any', + } + }, + cls.vnc: { + 'port': 5900, + 'secret_type': ['password'], + }, + cls.telnet: { + 'port': 23, + 'secret_type': ['password'], + }, + } @classmethod - def db_protocols(cls): - return [ - cls.mysql, cls.mariadb, cls.postgresql, cls.oracle, - cls.sqlserver, cls.redis, cls.mongodb, - ] + def db_settings(cls): + return { + cls.mysql: { + 'port': 3306, + 'secret_type': ['password'], + 'setting': { + } + }, + cls.mariadb: { + 'port': 3306, + 'secret_type': ['password'], + }, + cls.postgresql: { + 'port': 5432, + 'secret_type': ['password'], + }, + cls.oracle: { + 'port': 1521, + 'secret_type': ['password'], + }, + cls.sqlserver: { + 'port': 1433, + 'secret_type': ['password'], + }, + cls.mongodb: { + 'port': 27017, + 'secret_type': ['password'], + }, + cls.redis: { + 'port': 6379, + 'secret_type': ['password'], + }, + } + + @classmethod + def cloud_settings(cls): + return { + cls.k8s: { + 'port': 443, + 'secret_type': ['token'], + 'setting': { + 'via_http': True + } + }, + cls.http: { + 'port': 80, + 'secret_type': ['password'], + 'setting': { + 'ssl': True + } + }, + } + + @classmethod + def settings(cls): + return { + **cls.device_settings(), + **cls.db_settings(), + **cls.cloud_settings() + } @classmethod def default_ports(cls): @@ -54,6 +133,5 @@ class Protocol(ChoicesMixin, models.TextChoices): cls.k8s: 0, cls.http: 80, - cls.https: 443 } diff --git a/apps/assets/const/types.py b/apps/assets/const/types.py index 24c145a8b..67d4b9ff0 100644 --- a/apps/assets/const/types.py +++ b/apps/assets/const/types.py @@ -13,7 +13,7 @@ class AllTypes(ChoicesMixin, metaclass=IncludesTextChoicesMeta): choices: list includes = [ HostTypes, DeviceTypes, DatabaseTypes, - WebTypes, CloudTypes + CloudTypes, WebTypes, ] _category_constrains = {} diff --git a/apps/assets/migrations/0096_auto_20220426_1550.py b/apps/assets/migrations/0096_auto_20220426_1550.py index a0b1035d0..e03272504 100644 --- a/apps/assets/migrations/0096_auto_20220426_1550.py +++ b/apps/assets/migrations/0096_auto_20220426_1550.py @@ -36,7 +36,7 @@ class Migration(migrations.Migration): name='Cloud', fields=[ ('asset_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='assets.asset')), - ('cluster', models.CharField(max_length=4096, verbose_name='Cluster')), + ('url', models.CharField(max_length=4096, verbose_name='Cluster')), ], options={ 'abstract': False, diff --git a/apps/assets/migrations/0097_auto_20220426_1558.py b/apps/assets/migrations/0097_auto_20220426_1558.py index ff82e0cf7..02cbda4ce 100644 --- a/apps/assets/migrations/0097_auto_20220426_1558.py +++ b/apps/assets/migrations/0097_auto_20220426_1558.py @@ -86,7 +86,7 @@ def migrate_cloud_to_asset(apps, *args): protocols='', platform=platform, org_id=app.org_id, - cluster=attrs.get('cluster', '') + url=attrs.get('cluster', '') ) try: diff --git a/apps/assets/models/asset/cloud.py b/apps/assets/models/asset/cloud.py index 8810f199c..f4874b9c1 100644 --- a/apps/assets/models/asset/cloud.py +++ b/apps/assets/models/asset/cloud.py @@ -5,7 +5,7 @@ from .common import Asset class Cloud(Asset): - cluster = models.CharField(max_length=4096, verbose_name=_("Cluster")) + url = models.CharField(max_length=4096, verbose_name=_("Url")) def __str__(self): return self.name diff --git a/apps/assets/models/base.py b/apps/assets/models/base.py index ba919a6a0..429a4a0a5 100644 --- a/apps/assets/models/base.py +++ b/apps/assets/models/base.py @@ -72,12 +72,6 @@ class BaseAccount(OrgModelMixin): date_updated = models.DateTimeField(auto_now=True, verbose_name=_("Date updated")) created_by = models.CharField(max_length=128, null=True, verbose_name=_('Created by')) - ASSETS_AMOUNT_CACHE_KEY = "ASSET_USER_{}_ASSETS_AMOUNT" - ASSET_USER_CACHE_TIME = 600 - - APPS_AMOUNT_CACHE_KEY = "APP_USER_{}_APPS_AMOUNT" - APP_USER_CACHE_TIME = 600 - @property def public_key(self): return ''