2015-04-23 14:34:04 +00:00
|
|
|
from django.forms import widgets
|
|
|
|
from django.core.validators import RegexValidator
|
2023-10-24 16:59:02 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2015-04-23 14:34:04 +00:00
|
|
|
from rest_framework import serializers
|
|
|
|
|
|
|
|
from orchestra.api.serializers import SetPasswordHyperlinkedSerializer
|
|
|
|
from orchestra.contrib.accounts.serializers import AccountSerializerMixin
|
|
|
|
from orchestra.core import validators
|
|
|
|
|
|
|
|
from .models import SaaS
|
|
|
|
|
|
|
|
|
|
|
|
class SaaSSerializer(AccountSerializerMixin, SetPasswordHyperlinkedSerializer):
|
|
|
|
data = serializers.DictField(required=False)
|
|
|
|
password = serializers.CharField(write_only=True, required=False,
|
|
|
|
style={'widget': widgets.PasswordInput},
|
|
|
|
validators=[
|
|
|
|
validators.validate_password,
|
|
|
|
RegexValidator(r'^[^"\'\\]+$',
|
|
|
|
_('Enter a valid password. '
|
|
|
|
'This value may contain any ascii character except for '
|
|
|
|
' \'/"/\\/ characters.'), 'invalid'),
|
|
|
|
])
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = SaaS
|
2015-04-30 09:51:55 +00:00
|
|
|
fields = ('url', 'id', 'name', 'service', 'is_active', 'data', 'password')
|
2015-04-23 14:34:04 +00:00
|
|
|
postonly_fields = ('name', 'service', 'password')
|