2023-02-02 07:03:48 +00:00
|
|
|
|
from django.conf import settings
|
2022-11-01 12:37:04 +00:00
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
2022-11-14 10:48:21 +00:00
|
|
|
|
from rest_framework import serializers
|
2022-11-01 12:37:04 +00:00
|
|
|
|
|
2023-01-16 11:02:09 +00:00
|
|
|
|
from accounts.models import Account
|
|
|
|
|
from assets.models import Platform
|
2022-11-01 12:37:04 +00:00
|
|
|
|
from assets.serializers import HostSerializer
|
2023-01-16 11:02:09 +00:00
|
|
|
|
from common.const.choices import Status
|
|
|
|
|
from common.serializers.fields import LabeledChoiceField
|
2022-11-14 10:48:21 +00:00
|
|
|
|
from common.validators import ProjectUniqueValidator
|
2022-11-01 12:37:04 +00:00
|
|
|
|
from .applet import AppletSerializer
|
2022-11-07 12:41:18 +00:00
|
|
|
|
from .. import const
|
2022-11-14 10:48:21 +00:00
|
|
|
|
from ..models import AppletHost, AppletHostDeployment
|
2022-11-01 12:37:04 +00:00
|
|
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
|
'AppletHostSerializer', 'AppletHostDeploymentSerializer',
|
2022-11-07 12:41:18 +00:00
|
|
|
|
'AppletHostAccountSerializer', 'AppletHostAppletReportSerializer',
|
2023-08-01 09:42:16 +00:00
|
|
|
|
'AppletHostStartupSerializer'
|
2022-11-01 12:37:04 +00:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DeployOptionsSerializer(serializers.Serializer):
|
|
|
|
|
LICENSE_MODE_CHOICES = (
|
|
|
|
|
(4, _('Per Session')),
|
|
|
|
|
(2, _('Per Device')),
|
|
|
|
|
)
|
2023-06-14 08:37:30 +00:00
|
|
|
|
|
|
|
|
|
# 单用户单会话,
|
|
|
|
|
# 默认值为1,表示启用状态(组策略默认值),此时单用户只能有一个会话连接
|
|
|
|
|
# 如果改为 0 ,表示禁用状态,此时可以单用户多会话连接
|
2022-11-01 12:37:04 +00:00
|
|
|
|
SESSION_PER_USER = (
|
2023-06-13 07:50:21 +00:00
|
|
|
|
(0, _("Disabled")),
|
|
|
|
|
(1, _("Enabled")),
|
2022-11-01 12:37:04 +00:00
|
|
|
|
)
|
2023-02-02 07:03:48 +00:00
|
|
|
|
|
2023-03-01 07:16:11 +00:00
|
|
|
|
CORE_HOST = serializers.CharField(
|
|
|
|
|
default=settings.SITE_URL, label=_('Core API'), max_length=1024,
|
2023-03-08 05:40:55 +00:00
|
|
|
|
help_text=_("""
|
|
|
|
|
Tips: The application release machine communicates with the Core service.
|
|
|
|
|
If the release machine and the Core service are on the same network segment,
|
|
|
|
|
it is recommended to fill in the intranet address, otherwise fill in the current site URL
|
|
|
|
|
<br>
|
2023-03-08 05:42:37 +00:00
|
|
|
|
eg: https://172.16.10.110 or https://dev.jumpserver.com
|
|
|
|
|
""")
|
2023-03-01 07:16:11 +00:00
|
|
|
|
)
|
2023-03-08 05:27:03 +00:00
|
|
|
|
IGNORE_VERIFY_CERTS = serializers.BooleanField(default=True, label=_("Ignore Certificate Verification"))
|
2023-03-01 06:37:13 +00:00
|
|
|
|
RDS_Licensing = serializers.BooleanField(default=False, label=_("Existing RDS license"))
|
2022-11-01 12:37:04 +00:00
|
|
|
|
RDS_LicenseServer = serializers.CharField(default='127.0.0.1', label=_('RDS License Server'), max_length=1024)
|
2023-02-21 06:20:03 +00:00
|
|
|
|
RDS_LicensingMode = serializers.ChoiceField(choices=LICENSE_MODE_CHOICES, default=2, label=_('RDS Licensing Mode'))
|
2022-11-14 10:48:21 +00:00
|
|
|
|
RDS_fSingleSessionPerUser = serializers.ChoiceField(choices=SESSION_PER_USER, default=1,
|
2023-02-04 12:42:53 +00:00
|
|
|
|
label=_("RDS Single Session Per User"))
|
2022-11-01 12:37:04 +00:00
|
|
|
|
RDS_MaxDisconnectionTime = serializers.IntegerField(default=60000, label=_("RDS Max Disconnection Time"))
|
|
|
|
|
RDS_RemoteAppLogoffTimeLimit = serializers.IntegerField(default=0, label=_("RDS Remote App Logoff Time Limit"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AppletHostSerializer(HostSerializer):
|
|
|
|
|
deploy_options = DeployOptionsSerializer(required=False, label=_("Deploy options"))
|
2022-11-07 12:41:18 +00:00
|
|
|
|
load = LabeledChoiceField(
|
|
|
|
|
read_only=True, label=_('Load status'), choices=const.ComponentLoad.choices,
|
|
|
|
|
)
|
2022-11-01 12:37:04 +00:00
|
|
|
|
|
|
|
|
|
class Meta(HostSerializer.Meta):
|
|
|
|
|
model = AppletHost
|
|
|
|
|
fields = HostSerializer.Meta.fields + [
|
2023-07-28 02:41:37 +00:00
|
|
|
|
'auto_create_accounts', 'accounts_create_amount',
|
2022-11-07 12:41:18 +00:00
|
|
|
|
'load', 'date_synced', 'deploy_options'
|
2022-11-01 12:37:04 +00:00
|
|
|
|
]
|
|
|
|
|
extra_kwargs = {
|
2023-01-16 11:02:09 +00:00
|
|
|
|
**HostSerializer.Meta.extra_kwargs,
|
2023-07-28 03:02:21 +00:00
|
|
|
|
'date_synced': {'read_only': True},
|
|
|
|
|
'auto_create_accounts': {'help_text': _(
|
|
|
|
|
'These accounts are used to connect to the published application, '
|
|
|
|
|
'the account is now divided into two types, one is dedicated to each account, '
|
|
|
|
|
'each user has a private account, the other is public, '
|
|
|
|
|
'when the application does not support multiple open and the special has been used, '
|
|
|
|
|
'the public account will be used to connect')},
|
|
|
|
|
'accounts_create_amount': {'help_text': _('The number of public accounts created automatically')},
|
2022-11-01 12:37:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args, data=None, **kwargs):
|
|
|
|
|
if data:
|
|
|
|
|
self.set_initial_data(data)
|
|
|
|
|
kwargs['data'] = data
|
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def set_initial_data(data):
|
|
|
|
|
platform = Platform.objects.get(name='RemoteAppHost')
|
|
|
|
|
data.update({
|
|
|
|
|
'platform': platform.id,
|
|
|
|
|
'nodes_display': [
|
|
|
|
|
'RemoteAppHosts'
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
def get_validators(self):
|
|
|
|
|
validators = super().get_validators()
|
|
|
|
|
# 不知道为啥没有继承过来
|
|
|
|
|
uniq_validator = ProjectUniqueValidator(
|
|
|
|
|
queryset=AppletHost.objects.all(),
|
|
|
|
|
fields=('org_id', 'name')
|
|
|
|
|
)
|
|
|
|
|
validators.append(uniq_validator)
|
|
|
|
|
return validators
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HostAppletSerializer(AppletSerializer):
|
|
|
|
|
publication = serializers.SerializerMethodField()
|
|
|
|
|
|
|
|
|
|
class Meta(AppletSerializer.Meta):
|
|
|
|
|
fields = AppletSerializer.Meta.fields + ['publication']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AppletHostDeploymentSerializer(serializers.ModelSerializer):
|
2023-01-16 11:02:09 +00:00
|
|
|
|
status = LabeledChoiceField(choices=Status.choices, label=_('Status'), default=Status.pending)
|
|
|
|
|
|
2022-11-01 12:37:04 +00:00
|
|
|
|
class Meta:
|
|
|
|
|
model = AppletHostDeployment
|
2022-11-15 08:01:01 +00:00
|
|
|
|
fields_mini = ['id', 'host', 'status', 'task']
|
2022-11-01 12:37:04 +00:00
|
|
|
|
read_only_fields = [
|
|
|
|
|
'status', 'date_created', 'date_updated',
|
|
|
|
|
'date_start', 'date_finished'
|
|
|
|
|
]
|
|
|
|
|
fields = fields_mini + ['comment'] + read_only_fields
|
2022-11-03 08:55:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AppletHostAccountSerializer(serializers.ModelSerializer):
|
|
|
|
|
class Meta:
|
|
|
|
|
model = Account
|
2022-11-08 05:55:06 +00:00
|
|
|
|
fields = ['id', 'username', 'secret', 'is_active', 'date_updated']
|
2022-11-03 08:55:38 +00:00
|
|
|
|
|
|
|
|
|
|
2022-11-07 12:41:18 +00:00
|
|
|
|
class AppletHostAppletReportSerializer(serializers.Serializer):
|
|
|
|
|
id = serializers.UUIDField(read_only=True)
|
|
|
|
|
name = serializers.CharField()
|
|
|
|
|
version = serializers.CharField()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AppletHostStartupSerializer(serializers.Serializer):
|
|
|
|
|
pass
|