mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-07-05 19:16:37 +00:00
perf: Endpoint add is_active field
This commit is contained in:
parent
ad6d2e1cd7
commit
addd2e7d1c
18
apps/terminal/migrations/0004_endpoint_is_active.py
Normal file
18
apps/terminal/migrations/0004_endpoint_is_active.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.1.13 on 2024-09-25 07:38
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('terminal', '0003_auto_20171230_0308'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='endpoint',
|
||||||
|
name='is_active',
|
||||||
|
field=models.BooleanField(default=True, verbose_name='Active'),
|
||||||
|
),
|
||||||
|
]
|
@ -1,5 +1,6 @@
|
|||||||
from django.core.validators import MinValueValidator, MaxValueValidator
|
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.db.models import Prefetch
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from assets.models import Asset
|
from assets.models import Asset
|
||||||
@ -23,6 +24,7 @@ class Endpoint(JMSBaseModel):
|
|||||||
sqlserver_port = PortField(default=14330, verbose_name=_('SQLServer port'))
|
sqlserver_port = PortField(default=14330, verbose_name=_('SQLServer port'))
|
||||||
|
|
||||||
comment = models.TextField(default='', blank=True, verbose_name=_('Comment'))
|
comment = models.TextField(default='', blank=True, verbose_name=_('Comment'))
|
||||||
|
is_active = models.BooleanField(default=True, verbose_name=_('Active'))
|
||||||
|
|
||||||
default_id = '00000000-0000-0000-0000-000000000001'
|
default_id = '00000000-0000-0000-0000-000000000001'
|
||||||
|
|
||||||
@ -98,7 +100,7 @@ class Endpoint(JMSBaseModel):
|
|||||||
values = instance.labels.filter(label__name='endpoint').values_list('label__value', flat=True)
|
values = instance.labels.filter(label__name='endpoint').values_list('label__value', flat=True)
|
||||||
if not values:
|
if not values:
|
||||||
return None
|
return None
|
||||||
endpoints = cls.objects.filter(name__in=list(values)).order_by('-date_updated')
|
endpoints = cls.objects.filter(is_active=True, name__in=list(values)).order_by('-date_updated')
|
||||||
for endpoint in endpoints:
|
for endpoint in endpoints:
|
||||||
if endpoint.is_valid_for(instance, protocol):
|
if endpoint.is_valid_for(instance, protocol):
|
||||||
endpoint = cls.handle_endpoint_host(endpoint, request)
|
endpoint = cls.handle_endpoint_host(endpoint, request)
|
||||||
@ -128,7 +130,8 @@ class EndpointRule(JMSBaseModel):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def match(cls, target_instance, target_ip, protocol):
|
def match(cls, target_instance, target_ip, protocol):
|
||||||
for endpoint_rule in cls.objects.prefetch_related('endpoint').filter(is_active=True):
|
active_endpoints = Prefetch('endpoint', queryset=Endpoint.objects.filter(is_active=True))
|
||||||
|
for endpoint_rule in cls.objects.prefetch_related(active_endpoints).filter(is_active=True):
|
||||||
if not contains_ip(target_ip, endpoint_rule.ip_group):
|
if not contains_ip(target_ip, endpoint_rule.ip_group):
|
||||||
continue
|
continue
|
||||||
if not endpoint_rule.endpoint:
|
if not endpoint_rule.endpoint:
|
||||||
|
@ -28,7 +28,7 @@ class EndpointSerializer(BulkModelSerializer):
|
|||||||
fields_small = [
|
fields_small = [
|
||||||
'host', 'https_port', 'http_port', 'ssh_port', 'rdp_port',
|
'host', 'https_port', 'http_port', 'ssh_port', 'rdp_port',
|
||||||
'mysql_port', 'mariadb_port', 'postgresql_port', 'redis_port',
|
'mysql_port', 'mariadb_port', 'postgresql_port', 'redis_port',
|
||||||
'oracle_port_range', 'oracle_port', 'sqlserver_port',
|
'oracle_port_range', 'oracle_port', 'sqlserver_port', 'is_active'
|
||||||
]
|
]
|
||||||
fields = fields_mini + fields_small + [
|
fields = fields_mini + fields_small + [
|
||||||
'comment', 'date_created', 'date_updated', 'created_by'
|
'comment', 'date_created', 'date_updated', 'created_by'
|
||||||
|
Loading…
Reference in New Issue
Block a user