2023-08-15 05:45:44 +00:00
|
|
|
import uuid
|
|
|
|
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from rest_framework import serializers
|
|
|
|
|
|
|
|
from common.serializers.fields import EncryptedField
|
|
|
|
|
|
|
|
__all__ = [
|
2023-08-15 08:58:41 +00:00
|
|
|
'AnnouncementSettingSerializer', 'OpsSettingSerializer',
|
2023-08-15 05:45:44 +00:00
|
|
|
'VaultSettingSerializer', 'TicketSettingSerializer'
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class AnnouncementSerializer(serializers.Serializer):
|
|
|
|
ID = serializers.CharField(required=False, allow_blank=True, allow_null=True)
|
|
|
|
SUBJECT = serializers.CharField(required=True, max_length=1024, label=_("Subject"))
|
|
|
|
CONTENT = serializers.CharField(label=_("Content"))
|
|
|
|
LINK = serializers.URLField(
|
|
|
|
required=False, allow_null=True, allow_blank=True,
|
|
|
|
label=_("More url"), default='',
|
|
|
|
)
|
|
|
|
|
|
|
|
def to_representation(self, instance):
|
|
|
|
defaults = {'ID': '', 'SUBJECT': '', 'CONTENT': '', 'LINK': '', 'ENABLED': False}
|
|
|
|
data = {**defaults, **instance}
|
|
|
|
return super().to_representation(data)
|
|
|
|
|
|
|
|
def to_internal_value(self, data):
|
|
|
|
data['ID'] = str(uuid.uuid4())
|
|
|
|
return super().to_internal_value(data)
|
|
|
|
|
|
|
|
|
|
|
|
class AnnouncementSettingSerializer(serializers.Serializer):
|
2023-08-15 08:58:41 +00:00
|
|
|
PREFIX_TITLE = _('Announcement')
|
|
|
|
|
2023-08-15 05:45:44 +00:00
|
|
|
ANNOUNCEMENT_ENABLED = serializers.BooleanField(label=_('Enable announcement'), default=True)
|
|
|
|
ANNOUNCEMENT = AnnouncementSerializer(label=_("Announcement"))
|
|
|
|
|
|
|
|
|
|
|
|
class VaultSettingSerializer(serializers.Serializer):
|
2023-08-17 07:34:50 +00:00
|
|
|
PREFIX_TITLE = _('HCP Vault')
|
2023-08-15 08:58:41 +00:00
|
|
|
|
2023-08-17 04:12:58 +00:00
|
|
|
VAULT_ENABLED = serializers.BooleanField(
|
|
|
|
required=False, label=_('Enable Vault'), read_only=True
|
2023-08-15 05:45:44 +00:00
|
|
|
)
|
|
|
|
VAULT_HCP_HOST = serializers.CharField(
|
|
|
|
max_length=256, allow_blank=True, required=False, label=_('Host')
|
|
|
|
)
|
|
|
|
VAULT_HCP_TOKEN = EncryptedField(
|
|
|
|
max_length=256, allow_blank=True, required=False, label=_('Token'), default=''
|
|
|
|
)
|
|
|
|
VAULT_HCP_MOUNT_POINT = serializers.CharField(
|
|
|
|
max_length=256, allow_blank=True, required=False, label=_('Mount Point')
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class TicketSettingSerializer(serializers.Serializer):
|
2023-08-15 08:58:41 +00:00
|
|
|
PREFIX_TITLE = _('Ticket')
|
|
|
|
|
2023-08-15 05:45:44 +00:00
|
|
|
TICKETS_ENABLED = serializers.BooleanField(required=False, default=True, label=_("Enable tickets"))
|
|
|
|
TICKET_AUTHORIZE_DEFAULT_TIME = serializers.IntegerField(
|
|
|
|
min_value=1, max_value=999999, required=False,
|
|
|
|
label=_("Ticket authorize default time")
|
|
|
|
)
|
|
|
|
TICKET_AUTHORIZE_DEFAULT_TIME_UNIT = serializers.ChoiceField(
|
|
|
|
choices=[('day', _("day")), ('hour', _("hour"))],
|
|
|
|
label=_("Ticket authorize default time unit"), required=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class OpsSettingSerializer(serializers.Serializer):
|
2023-08-15 08:58:41 +00:00
|
|
|
PREFIX_TITLE = _('Feature')
|
|
|
|
|
2023-08-15 05:45:44 +00:00
|
|
|
SECURITY_COMMAND_EXECUTION = serializers.BooleanField(
|
|
|
|
required=False, label=_('Operation center'),
|
|
|
|
help_text=_('Allow user run batch command or not using ansible')
|
|
|
|
)
|
|
|
|
SECURITY_COMMAND_BLACKLIST = serializers.ListField(
|
|
|
|
child=serializers.CharField(max_length=1024, ),
|
|
|
|
label=_('Operation center command blacklist'),
|
|
|
|
help_text=_("Commands that are not allowed execute.")
|
|
|
|
)
|