mirror of https://github.com/jumpserver/jumpserver
perf(applications): 修改应用序列类字段长度限制
parent
a98816462f
commit
9aed51ffe9
|
@ -10,9 +10,11 @@ from .. import models
|
||||||
|
|
||||||
|
|
||||||
class DatabaseCategorySerializer(serializers.Serializer):
|
class DatabaseCategorySerializer(serializers.Serializer):
|
||||||
host = serializers.CharField(label=_('Host'))
|
host = serializers.CharField(max_length=128, label=_('Host'))
|
||||||
port = serializers.IntegerField(label=_('Port'))
|
port = serializers.IntegerField(label=_('Port'))
|
||||||
database = serializers.CharField(allow_blank=True, allow_null=True, label=_('Database'))
|
database = serializers.CharField(
|
||||||
|
max_length=128, allow_blank=True, allow_null=True, label=_('Database')
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class DatabaseAttrsSerializer(DatabaseCategorySerializer):
|
class DatabaseAttrsSerializer(DatabaseCategorySerializer):
|
||||||
|
|
|
@ -6,7 +6,7 @@ from .. import models
|
||||||
|
|
||||||
|
|
||||||
class CloudCategorySerializer(serializers.Serializer):
|
class CloudCategorySerializer(serializers.Serializer):
|
||||||
cluster = serializers.CharField(label=_('Cluster'))
|
cluster = serializers.CharField(max_length=1024, label=_('Cluster'))
|
||||||
|
|
||||||
|
|
||||||
class K8sAttrsSerializer(CloudCategorySerializer):
|
class K8sAttrsSerializer(CloudCategorySerializer):
|
||||||
|
|
|
@ -19,89 +19,40 @@ class RemmoteAppCategorySerializer(serializers.Serializer):
|
||||||
|
|
||||||
|
|
||||||
class RemoteAppAttrsSerializer(RemmoteAppCategorySerializer):
|
class RemoteAppAttrsSerializer(RemmoteAppCategorySerializer):
|
||||||
path = serializers.CharField(label=_('Remote App path'))
|
path = serializers.CharField(max_length=128, label=_('Remote App path'))
|
||||||
|
|
||||||
|
|
||||||
class ChromeAttrsSerializer(RemoteAppAttrsSerializer):
|
class ChromeAttrsSerializer(RemoteAppAttrsSerializer):
|
||||||
REMOTE_APP_PATH = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
|
REMOTE_APP_PATH = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
|
||||||
path = serializers.CharField(label=_('Remote App path'), default=REMOTE_APP_PATH)
|
path = serializers.CharField(max_length=128, label=_('Remote App path'), default=REMOTE_APP_PATH)
|
||||||
chrome_target = serializers.CharField(label=_('Target URL'))
|
chrome_target = serializers.CharField(max_length=128, label=_('Target URL'))
|
||||||
chrome_username = serializers.CharField(label=_('Username'))
|
chrome_username = serializers.CharField(max_length=128, label=_('Username'))
|
||||||
chrome_password = serializers.CharField(write_only=True, label=_('Password'))
|
chrome_password = serializers.CharField(max_length=128, write_only=True, label=_('Password'))
|
||||||
|
|
||||||
|
|
||||||
class MySQLWorkbenchAttrsSerializer(RemoteAppAttrsSerializer):
|
class MySQLWorkbenchAttrsSerializer(RemoteAppAttrsSerializer):
|
||||||
REMOTE_APP_PATH = 'C:\Program Files\MySQL\MySQL Workbench 8.0 CE\MySQLWorkbench.exe'
|
REMOTE_APP_PATH = 'C:\Program Files\MySQL\MySQL Workbench 8.0 CE\MySQLWorkbench.exe'
|
||||||
path = serializers.CharField(label=_('Remote App path'), default=REMOTE_APP_PATH)
|
path = serializers.CharField(max_length=128, label=_('Remote App path'), default=REMOTE_APP_PATH)
|
||||||
mysql_workbench_ip = serializers.CharField(label=_('IP'))
|
mysql_workbench_ip = serializers.CharField(max_length=128, label=_('IP'))
|
||||||
mysql_workbench_port = serializers.IntegerField(label=_('Port'))
|
mysql_workbench_port = serializers.IntegerField(label=_('Port'))
|
||||||
mysql_workbench_name = serializers.CharField(label=_('Database'))
|
mysql_workbench_name = serializers.CharField(max_length=128, label=_('Database'))
|
||||||
mysql_workbench_username = serializers.CharField(label=_('Username'))
|
mysql_workbench_username = serializers.CharField(max_length=128, label=_('Username'))
|
||||||
mysql_workbench_password = serializers.CharField(write_only=True, label=_('Password'))
|
mysql_workbench_password = serializers.CharField(max_length=128, write_only=True, label=_('Password'))
|
||||||
|
|
||||||
|
|
||||||
class VMwareClientAttrsSerializer(RemoteAppAttrsSerializer):
|
class VMwareClientAttrsSerializer(RemoteAppAttrsSerializer):
|
||||||
REMOTE_APP_PATH = 'C:\Program Files (x86)\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe'
|
REMOTE_APP_PATH = 'C:\Program Files (x86)\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe'
|
||||||
path = serializers.CharField(label=_('Remote App path'), default=REMOTE_APP_PATH)
|
path = serializers.CharField(max_length=128, label=_('Remote App path'), default=REMOTE_APP_PATH)
|
||||||
vmware_target = serializers.CharField(label=_('Target URL'))
|
vmware_target = serializers.CharField(max_length=128, label=_('Target URL'))
|
||||||
vmware_username = serializers.CharField(label=_('Username'))
|
vmware_username = serializers.CharField(max_length=128, label=_('Username'))
|
||||||
vmware_password = serializers.CharField(write_only=True, label=_('Password'))
|
vmware_password = serializers.CharField(max_length=128, write_only=True, label=_('Password'))
|
||||||
|
|
||||||
|
|
||||||
class CustomRemoteAppAttrsSeralizers(RemoteAppAttrsSerializer):
|
class CustomRemoteAppAttrsSeralizers(RemoteAppAttrsSerializer):
|
||||||
custom_cmdline = serializers.CharField(label=_('Operating parameter'))
|
custom_cmdline = serializers.CharField(max_length=128, label=_('Operating parameter'))
|
||||||
custom_target = serializers.CharField(label=_('Target url'))
|
custom_target = serializers.CharField(max_length=128, label=_('Target url'))
|
||||||
custom_username = serializers.CharField(label=_('Username'))
|
custom_username = serializers.CharField(max_length=128, label=_('Username'))
|
||||||
custom_password = serializers.CharField(write_only=True, label=_('Password'))
|
custom_password = serializers.CharField(max_length=128, write_only=True, label=_('Password'))
|
||||||
|
|
||||||
|
|
||||||
class RemoteAppParamsDictField(CustomMetaDictField):
|
|
||||||
type_fields_map = const.REMOTE_APP_TYPE_FIELDS_MAP
|
|
||||||
default_type = const.REMOTE_APP_TYPE_CHROME
|
|
||||||
convert_key_remove_type_prefix = False
|
|
||||||
convert_key_to_upper = False
|
|
||||||
|
|
||||||
|
|
||||||
class RemoteAppSerializer(BulkOrgResourceModelSerializer):
|
|
||||||
params = RemoteAppParamsDictField()
|
|
||||||
type_fields_map = const.REMOTE_APP_TYPE_FIELDS_MAP
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = RemoteApp
|
|
||||||
list_serializer_class = AdaptedBulkListSerializer
|
|
||||||
fields = [
|
|
||||||
'id', 'name', 'asset', 'asset_info', 'type', 'get_type_display',
|
|
||||||
'path', 'params', 'date_created', 'created_by', 'comment',
|
|
||||||
]
|
|
||||||
read_only_fields = [
|
|
||||||
'created_by', 'date_created', 'asset_info',
|
|
||||||
'get_type_display'
|
|
||||||
]
|
|
||||||
|
|
||||||
def process_params(self, instance, validated_data):
|
|
||||||
new_params = copy.deepcopy(validated_data.get('params', {}))
|
|
||||||
tp = validated_data.get('type', '')
|
|
||||||
|
|
||||||
if tp != instance.type:
|
|
||||||
return new_params
|
|
||||||
|
|
||||||
old_params = instance.params
|
|
||||||
fields = self.type_fields_map.get(instance.type, [])
|
|
||||||
for field in fields:
|
|
||||||
if not field.get('write_only', False):
|
|
||||||
continue
|
|
||||||
field_name = field['name']
|
|
||||||
new_value = new_params.get(field_name, '')
|
|
||||||
old_value = old_params.get(field_name, '')
|
|
||||||
field_value = new_value if new_value else old_value
|
|
||||||
new_params[field_name] = field_value
|
|
||||||
|
|
||||||
return new_params
|
|
||||||
|
|
||||||
def update(self, instance, validated_data):
|
|
||||||
params = self.process_params(instance, validated_data)
|
|
||||||
validated_data['params'] = params
|
|
||||||
return super().update(instance, validated_data)
|
|
||||||
|
|
||||||
|
|
||||||
class RemoteAppConnectionInfoSerializer(serializers.ModelSerializer):
|
class RemoteAppConnectionInfoSerializer(serializers.ModelSerializer):
|
||||||
|
@ -149,3 +100,56 @@ class RemoteAppConnectionInfoSerializer(serializers.ModelSerializer):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_asset(obj):
|
def get_asset(obj):
|
||||||
return obj.attrs.get('asset')
|
return obj.attrs.get('asset')
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: DELETE
|
||||||
|
class RemoteAppParamsDictField(CustomMetaDictField):
|
||||||
|
type_fields_map = const.REMOTE_APP_TYPE_FIELDS_MAP
|
||||||
|
default_type = const.REMOTE_APP_TYPE_CHROME
|
||||||
|
convert_key_remove_type_prefix = False
|
||||||
|
convert_key_to_upper = False
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: DELETE
|
||||||
|
class RemoteAppSerializer(BulkOrgResourceModelSerializer):
|
||||||
|
params = RemoteAppParamsDictField()
|
||||||
|
type_fields_map = const.REMOTE_APP_TYPE_FIELDS_MAP
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = RemoteApp
|
||||||
|
list_serializer_class = AdaptedBulkListSerializer
|
||||||
|
fields = [
|
||||||
|
'id', 'name', 'asset', 'asset_info', 'type', 'get_type_display',
|
||||||
|
'path', 'params', 'date_created', 'created_by', 'comment',
|
||||||
|
]
|
||||||
|
read_only_fields = [
|
||||||
|
'created_by', 'date_created', 'asset_info',
|
||||||
|
'get_type_display'
|
||||||
|
]
|
||||||
|
|
||||||
|
def process_params(self, instance, validated_data):
|
||||||
|
new_params = copy.deepcopy(validated_data.get('params', {}))
|
||||||
|
tp = validated_data.get('type', '')
|
||||||
|
|
||||||
|
if tp != instance.type:
|
||||||
|
return new_params
|
||||||
|
|
||||||
|
old_params = instance.params
|
||||||
|
fields = self.type_fields_map.get(instance.type, [])
|
||||||
|
for field in fields:
|
||||||
|
if not field.get('write_only', False):
|
||||||
|
continue
|
||||||
|
field_name = field['name']
|
||||||
|
new_value = new_params.get(field_name, '')
|
||||||
|
old_value = old_params.get(field_name, '')
|
||||||
|
field_value = new_value if new_value else old_value
|
||||||
|
new_params[field_name] = field_value
|
||||||
|
|
||||||
|
return new_params
|
||||||
|
|
||||||
|
def update(self, instance, validated_data):
|
||||||
|
params = self.process_params(instance, validated_data)
|
||||||
|
validated_data['params'] = params
|
||||||
|
return super().update(instance, validated_data)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue