jumpserver/apps/assets/serializers/account/common.py

30 lines
976 B
Python
Raw Normal View History

2022-08-24 08:36:42 +00:00
# -*- coding: utf-8 -*-
#
from rest_framework import serializers
2022-09-06 11:57:03 +00:00
__all__ = ['AccountFieldsSerializerMixin']
2022-08-24 08:36:42 +00:00
2022-09-06 11:57:03 +00:00
class AccountFieldsSerializerMixin(serializers.ModelSerializer):
2022-08-24 08:36:42 +00:00
class Meta:
fields_mini = [
2022-09-06 11:57:03 +00:00
'id', 'name', 'username', 'privileged', 'ip',
'asset_name', 'platform', 'version'
2022-08-24 08:36:42 +00:00
]
fields_write_only = ['password', 'private_key', 'public_key', 'passphrase']
2022-09-06 11:57:03 +00:00
fields_other = ['date_created', 'date_updated', 'comment']
2022-08-24 08:36:42 +00:00
fields_small = fields_mini + fields_write_only + fields_other
fields_fk = ['asset']
fields = fields_small + fields_fk
extra_kwargs = {
'private_key': {'write_only': True},
'public_key': {'write_only': True},
2022-09-07 12:24:48 +00:00
'token': {'write_only': True},
'password': {'write_only': True},
2022-08-24 08:36:42 +00:00
}
2022-09-06 11:57:03 +00:00
def validate_name(self, value):
if not value:
return self.initial_data.get('username')
return ''