mirror of https://github.com/jumpserver/jumpserver
perf: 优化平台协议
parent
79ce1215f5
commit
cf5c50b343
|
@ -202,7 +202,7 @@ class NodeChildrenAsTreeApi(SerializeToTreeNodeMixin, NodeChildrenApi):
|
||||||
return []
|
return []
|
||||||
assets = self.instance.get_assets().only(
|
assets = self.instance.get_assets().only(
|
||||||
"id", "name", "ip", "platform_id",
|
"id", "name", "ip", "platform_id",
|
||||||
"org_id", "protocols", "is_active",
|
"org_id", "is_active",
|
||||||
).prefetch_related('platform')
|
).prefetch_related('platform')
|
||||||
return self.serialize_assets(assets, self.instance.key)
|
return self.serialize_assets(assets, self.instance.key)
|
||||||
|
|
||||||
|
|
|
@ -30,11 +30,11 @@ class BaseType(TextChoices):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _parse_protocols(cls, protocol, tp):
|
def _parse_protocols(cls, protocol, tp):
|
||||||
default_ports = Protocol.default_ports()
|
settings = Protocol.settings()
|
||||||
choices = protocol.get('choices', [])
|
choices = protocol.get('choices', [])
|
||||||
if choices == '__self__':
|
if choices == '__self__':
|
||||||
choices = [tp]
|
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
|
return protocols
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -6,7 +6,6 @@ __all__ = ['Protocol']
|
||||||
|
|
||||||
class Protocol(ChoicesMixin, models.TextChoices):
|
class Protocol(ChoicesMixin, models.TextChoices):
|
||||||
ssh = 'ssh', 'SSH'
|
ssh = 'ssh', 'SSH'
|
||||||
sftp = 'sftp', 'SFTP'
|
|
||||||
rdp = 'rdp', 'RDP'
|
rdp = 'rdp', 'RDP'
|
||||||
telnet = 'telnet', 'Telnet'
|
telnet = 'telnet', 'Telnet'
|
||||||
vnc = 'vnc', 'VNC'
|
vnc = 'vnc', 'VNC'
|
||||||
|
@ -24,15 +23,95 @@ class Protocol(ChoicesMixin, models.TextChoices):
|
||||||
https = 'https', 'HTTPS'
|
https = 'https', 'HTTPS'
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def host_protocols(cls):
|
def device_settings(cls):
|
||||||
return [cls.ssh, cls.rdp, cls.telnet, cls.vnc]
|
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
|
@classmethod
|
||||||
def db_protocols(cls):
|
def db_settings(cls):
|
||||||
return [
|
return {
|
||||||
cls.mysql, cls.mariadb, cls.postgresql, cls.oracle,
|
cls.mysql: {
|
||||||
cls.sqlserver, cls.redis, cls.mongodb,
|
'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
|
@classmethod
|
||||||
def default_ports(cls):
|
def default_ports(cls):
|
||||||
|
@ -54,6 +133,5 @@ class Protocol(ChoicesMixin, models.TextChoices):
|
||||||
cls.k8s: 0,
|
cls.k8s: 0,
|
||||||
|
|
||||||
cls.http: 80,
|
cls.http: 80,
|
||||||
cls.https: 443
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ class AllTypes(ChoicesMixin, metaclass=IncludesTextChoicesMeta):
|
||||||
choices: list
|
choices: list
|
||||||
includes = [
|
includes = [
|
||||||
HostTypes, DeviceTypes, DatabaseTypes,
|
HostTypes, DeviceTypes, DatabaseTypes,
|
||||||
WebTypes, CloudTypes
|
CloudTypes, WebTypes,
|
||||||
]
|
]
|
||||||
_category_constrains = {}
|
_category_constrains = {}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ class Migration(migrations.Migration):
|
||||||
name='Cloud',
|
name='Cloud',
|
||||||
fields=[
|
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')),
|
('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={
|
options={
|
||||||
'abstract': False,
|
'abstract': False,
|
||||||
|
|
|
@ -86,7 +86,7 @@ def migrate_cloud_to_asset(apps, *args):
|
||||||
protocols='',
|
protocols='',
|
||||||
platform=platform,
|
platform=platform,
|
||||||
org_id=app.org_id,
|
org_id=app.org_id,
|
||||||
cluster=attrs.get('cluster', '')
|
url=attrs.get('cluster', '')
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -5,7 +5,7 @@ from .common import Asset
|
||||||
|
|
||||||
|
|
||||||
class Cloud(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):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
|
@ -72,12 +72,6 @@ class BaseAccount(OrgModelMixin):
|
||||||
date_updated = models.DateTimeField(auto_now=True, verbose_name=_("Date updated"))
|
date_updated = models.DateTimeField(auto_now=True, verbose_name=_("Date updated"))
|
||||||
created_by = models.CharField(max_length=128, null=True, verbose_name=_('Created by'))
|
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
|
@property
|
||||||
def public_key(self):
|
def public_key(self):
|
||||||
return ''
|
return ''
|
||||||
|
|
Loading…
Reference in New Issue