class ChangeJumperAccountInfoSerializer(serializers.Serializer): jumper_ip = serializers.IPAddressField( required=True, error_messages=serializers.CommonErrorMessages(_(u"堡垒机IP"))) host_id = serializers.IntegerField( required=True, error_messages=serializers.CommonErrorMessages(_(u"主机ID"))) account_id = serializers.IntegerField( required=True, error_messages=serializers.CommonErrorMessages(_(u"账户ID"))) protocol = serializers.ChoiceField( choices=["SSH", "RDP"], required=True, error_messages=serializers.CommonErrorMessages(_(u"协议"))) auth_mode = serializers.ChoiceField( choices=["autoLogin", "manualLogin"], required=True, error_messages=serializers.CommonErrorMessages(_(u"登录方式"))) account_name = serializers.CharField( required=True, error_messages=serializers.CommonErrorMessages(_(u"用户名"))) password = serializers.CharField( required=False, default="", error_messages=serializers.CommonErrorMessages(_(u"密码")))
class AddHostAccountSerializer(serializers.Serializer): # 堡垒机IP jumper_ip = serializers.IPAddressField( required=True, error_messages=serializers.CommonErrorMessages(_(u"堡垒机IP"))) # 主机ID host_id = serializers.IntegerField( required=True, error_messages=serializers.CommonErrorMessages(_(u"主机ID"))) # 账户名 account_name = serializers.CharField( required=True, error_messages=serializers.CommonErrorMessages(_(u"账户名"))) # 账户密码 account_password = serializers.CharField(required=False, default="") # 登录方式 auth_mode = serializers.ChoiceField( choices=["autoLogin", "manualLogin"], required=True, error_messages=serializers.CommonErrorMessages(_(u"登录方式"))) # 用户协议 protocol = serializers.ChoiceField( choices=["RDP", "SSH"], required=True, error_messages=serializers.CommonErrorMessages(_(u"用户协议")))
class ElasticGroupTriggerMonitorSwitchValidator(serializers.Serializer): threshold = serializers.IntegerField(min_value=1, max_value=99) stat = serializers.ChoiceField(choices=(('avg', 'AVG'), ('min', 'MIN'), ('max', 'MAX'))) compare = serializers.ChoiceField(choices=(('ge', 'greater or equal'), ('le', 'less or equal'))) step = serializers.IntegerField(min_value=1)
class CreatePortalorderValidator(serializers.Serializer): type = serializers.ChoiceField(choices=(PortalOrderType.TEST, PortalOrderType.FORMAL)) lessee_id = serializers.CharField( max_length=100, validators=[username_validator], error_messages=serializers.CommonErrorMessages(_(u'租户'))) seller_name = serializers.CharField(max_length=100) seller_id = serializers.CharField(max_length=100) duration_type = serializers.ChoiceField( choices=(PortalOrderDurationType.MONTH, PortalOrderDurationType.YEAR)) duration_value = serializers.IntegerField(min_value=1) expire_at = serializers.IntegerField(min_value=1486546424) cabinet_count = serializers.IntegerField(min_value=0) platform_type = serializers.CharField(max_length=100) platform_version = serializers.CharField(max_length=100) contract_money = serializers.FloatField(min_value=0.01) contract_id = serializers.CharField(max_length=100)
class DescribeMonitorVMInfoValidator(serializers.Serializer): num = serializers.IntegerField( required=False, min_value=0, error_messages=serializers.CommonErrorMessages('num')) sort = serializers.ChoiceField( required=False, choices=SORT_METHOD, error_messages=serializers.CommonErrorMessages('sort')) format = serializers.ChoiceField( required=False, choices=PERIOD_CHOICE, error_messages=serializers.CommonErrorMessages('format')) poolname = serializers.CharField( required=False, error_messages=serializers.CommonErrorMessages('poolname')) items = serializers.ListField( required=False, child=serializers.ChoiceField(required=False, choices=VM_ITEM), error_messages=serializers.CommonErrorMessages('items')) timestamp = serializers.IntegerField(required=False, validators=[]) point_num = serializers.IntegerField(required=False, validators=[]) VM_type = serializers.ChoiceField( required=False, choices=('KVM', 'VMWARE'), )
class DescribeMonitorPMInfoValidator(serializers.Serializer): num = serializers.IntegerField( required=False, min_value=0, error_messages=serializers.CommonErrorMessages('num')) itemname = serializers.ChoiceField( required=True, choices=PM_ITEM, error_messages=serializers.CommonErrorMessages('item_name')) format = serializers.ChoiceField( required=True, choices=PERIOD_CHOICE, error_messages=serializers.CommonErrorMessages('format')) poolname = serializers.CharField( required=False, error_messages=serializers.CommonErrorMessages('poolname')) sort = serializers.ChoiceField( required=False, choices=SORT_METHOD, error_messages=serializers.CommonErrorMessages('sort'))
class CreateWafSeniorSerializer(DescribeWafSeniorSerializer): """ 新建高级防护 """ url = serializers.CharField( required=True, error_messages=serializers.CommonErrorMessages(u"url")) time = serializers.CharField( required=True, error_messages=serializers.CommonErrorMessages(u"统计时间")) blocktime = serializers.CharField( required=True, error_messages=serializers.CommonErrorMessages(u"阻断时间")) threshold = serializers.CharField( required=True, error_messages=serializers.CommonErrorMessages(u"阈值")) process_action = serializers.ChoiceField( required=True, choices=["pass", "notify", "deny", "captcha", "all"], error_messages=serializers.CommonErrorMessages(u"防护动作")) matchtype = serializers.ChoiceField( required=True, choices=["equ", "cnt", "regex", "prefix"], error_messages=serializers.CommonErrorMessages(u"关系"))
class DescribeLoadbalancerMonitorSerializer(serializers.Serializer): resource_type = serializers.ChoiceField(required=True, allow_blank=False, choices=RESOURCE_TYPE_CHOICE) resource_id = serializers.CharField(required=True, allow_blank=False, max_length=20, validators=[]) data_fmt = serializers.ChoiceField(required=True, allow_blank=False, choices=FORMAT_CHOICE) def validate(self, attrs): resource_type = attrs.get("resource_type") resource_id = attrs.get("resource_id") func = None if resource_type == RESOURCE_TYPE.loadbalancer: func = lb_id_validator elif resource_type == RESOURCE_TYPE.listener: func = lbl_id_validator elif resource_type == RESOURCE_TYPE.member: func = lbm_id_validator func(resource_id) return attrs
class RdsMonitorValidator(serializers.Serializer): data_fmt = serializers.ChoiceField( required=True, choices=model.PERIOD_CHOICE, ) item = serializers.ChoiceField( required=True, choices=model.ITEM_CHOICE, )
class UpdateLoadbalancerListenerSerializer(serializers.Serializer): lb_id = serializers.CharField(required=True, allow_blank=False, max_length=20, validators=[lb_id_validator]) lbl_id = serializers.CharField(required=True, allow_blank=False, max_length=20, validators=[lbl_id_validator]) lbl_name = serializers.CharField(required=True, allow_blank=True, max_length=20, validators=[]) lb_algorithm = serializers.ChoiceField(required=True, allow_blank=False, choices=LB_ALGORITHM_CHOICES) health_check_type = serializers.ChoiceField( required=True, allow_blank=False, choices=HEALTH_CHECK_TYPE_CHOICES) health_check_delay = serializers.IntegerField(required=True, min_value=1, max_value=300) health_check_timeout = serializers.IntegerField(required=True, min_value=1, max_value=50) health_check_max_retries = serializers.IntegerField(required=True, min_value=2, max_value=10) health_check_url_path = serializers.CharField(required=False, allow_blank=False, max_length=255, default="/") health_check_expected_codes = serializers.CharField( required=False, allow_blank=False, max_length=9, validators=[health_check_expected_codes_validator], default="2") session_persistence_type = serializers.ChoiceField( required=True, choices=SESSION_PERSISTENCE_TYPE_CHOICES, ) cookie_name = serializers.CharField(required=False, allow_blank=False, max_length=1024, validators=[])
class LbMonitorValidator(serializers.Serializer): data_fmt = serializers.ChoiceField( required=True, choices=model.PERIOD_CHOICE, ) item = serializers.ChoiceField( required=True, choices=model.ITEM_CHOICE, ) resource_type = serializers.ChoiceField( required=True, choices=model.LB_TYPE_CHOICE, )
class MultiMonitorValidator(serializers.Serializer): data_fmt = serializers.ChoiceField( required=True, choices=model.PERIOD_CHOICE, ) item = serializers.ChoiceField( required=True, choices=model.ITEM_CHOICE, ) timestamp = serializers.IntegerField(required=False, validators=[]) point_num = serializers.IntegerField(required=False, validators=[]) sort_method = serializers.ChoiceField(required=False, choices=model.SORT_METHOD)
class SendVerifyCodeCaptchaValidator(serializers.Serializer): # 验证码类型 code_type = serializers.ChoiceField(choices=CODE_TYPE_CHOICES, required=True) # 手机号 cell_phone = serializers.CharField(required=True, validators=[cell_phone_validator]) # ####### 用于申请专用通道 ############# # 图片验证码hash key captcha_key = serializers.CharField(max_length=40, required=True, write_only=True) # 图片验证码的值 captcha_value = serializers.CharField(max_length=10, required=True, write_only=True) def validate(self, attrs): captcha_key = attrs["captcha_key"] captcha_value = attrs["captcha_value"] captcha_inst, error = captcha_validator(captcha_key=captcha_key, captcha_value=captcha_value) if error is not None: raise serializers.ValidationError(error) return attrs
class DescribeAlarmBindableResourceValidator(serializers.Serializer): resource_type = serializers.ChoiceField(required=True, choices=resource_type_choice, validators=[]) alarm_id = serializers.CharField(required=False, max_length=20, validators=[alarm_id_validator])
class NewHostSerializer(serializers.Serializer): # 所有者 owner = serializers.CharField( required=True, max_length=30, error_messages=serializers.CommonErrorMessages(_(u"用户"))) # zone zone = serializers.ChoiceField( required=True, choices=["dev", "test", "prod"], error_messages=serializers.CommonErrorMessages(_(u"区域"))) # 堡垒机IP jumper_ip = serializers.IPAddressField( required=True, error_messages=serializers.CommonErrorMessages(_(u"堡垒机IP"))) # 主机ID instance_id = serializers.CharField( required=True, max_length=30, error_messages=serializers.CommonErrorMessages(_(u"主机ID"))) # 主机名 instance_name = serializers.CharField( required=True, error_messages=serializers.CommonErrorMessages(_(u"主机名称"))) # 子网ID # net_id = serializers.ListField( # required=True, # error_messages=serializers.CommonErrorMessages(_(u"子网ID")) # ) # rdp端口 rdp_port = serializers.IntegerField( required=True, max_value=65536, error_messages=serializers.CommonErrorMessages(_(u"rdp端口号"))) # ssh端口 ssh_port = serializers.IntegerField( required=True, max_value=65536, error_messages=serializers.CommonErrorMessages(_(u"ssh端口号"))) # rdp键盘记录 enable_keyboard_record = serializers.BooleanField( required=True, error_messages=serializers.CommonErrorMessages(_(u"是否启用rdp键盘记录"))) # rdp打印机/驱动器映射 enable_disk_redirection = serializers.BooleanField( required=True, error_messages=serializers.CommonErrorMessages(_(u"是否启用rdp打印机/驱动器映射"))) # rdp剪切板 enable_clipboard = serializers.BooleanField( required=True, error_messages=serializers.CommonErrorMessages(_(u"是否启用rdp剪切板")))
class DeleteCmdbValidator(serializers.Serializer): type = serializers.ChoiceField( choices=CFG_TYPE_CHOICES, error_messages=serializers.CommonErrorMessages('type')) ids = serializers.ListField( error_messages=serializers.CommonErrorMessages('ids'))
class AppstoreBaseSerializer(serializers.Serializer): owner = serializers.CharField( required=True, error_messages=serializers.CommonErrorMessages(u"用户")) zone = serializers.ChoiceField( required=True, choices=["dev", "prod", "test", "all", "bj"], error_messages=serializers.CommonErrorMessages(u"分区"))
class WafBaseSerializer(serializers.Serializer): """ 每秒查询频率、HTTP连接数、CPU使用率、内存使用率 请求次数统计、响应时间统计、安全防护日志 基础防护、HTTP协议防护、防错误信息泄露、WAF规则 url白名单 系统信息 """ owner = serializers.CharField( required=True, error_messages=serializers.CommonErrorMessages(u"用户")) zone = serializers.ChoiceField( required=True, choices=["dev", "prod", "test"], error_messages=serializers.CommonErrorMessages(u"分区")) waf_id = serializers.CharField( required=True, error_messages=serializers.CommonErrorMessages(u"waf_id")) smc_ip = serializers.IPAddressField( required=True, error_messages=serializers.CommonErrorMessages(u"smc_ip")) page_index = serializers.IntegerField(default=1, required=False) page_size = serializers.IntegerField(default=0, required=False)
class SendVerifyCodeValidator(serializers.Serializer): # 验证码类型 code_type = serializers.ChoiceField(choices=CODE_TYPE_CHOICES, required=True) # 手机号 cell_phone = serializers.CharField(required=True, validators=[cell_phone_validator])
class DescribeBackupsValidator(serializers.Serializer): backup_type = serializers.ChoiceField(choices=BACKUP_TYPE_CHOICES) resource_id = serializers.CharField( max_length=20, required=False, default=None, ) status = serializers.CharField( max_length=100, required=False, default=None, ) backup_id = serializers.CharField( max_length=20, required=False, default=None, ) instance_to_image = serializers.IntegerField(required=False, min_value=0) hypervisor_type = serializers.CharField(required=False, ) search_key = serializers.CharField( required=False, default='', allow_blank=True, max_length=64, ) limit = serializers.IntegerField(required=False, min_value=0) offset = serializers.IntegerField(required=False, min_value=0)
class SystemValidator(serializers.Serializer): id = serializers.IntegerField( required=False, error_messages=serializers.CommonErrorMessages('id')) cfg_id = serializers.CharField( required=False, default=lambda: 'app-' + uuid.uuid4().get_hex(), max_length=100, error_messages=serializers.CommonErrorMessages(_(u'编号'))) name = serializers.CharField( max_length=100, error_messages=serializers.CommonErrorMessages(_(u'系统名称'))) version = serializers.CharField( max_length=100, error_messages=serializers.CommonErrorMessages(_(u'版本'))) man = serializers.CharField(max_length=100, error_messages=serializers.CommonErrorMessages( _(u'责任人'))) weight = serializers.ChoiceField( choices=WEIGHT_CHOICES, error_messages=serializers.CommonErrorMessages(_(u'重要级别'))) hosts = serializers.CharField( required=False, default='*', max_length=100, error_messages=serializers.CommonErrorMessages(_(u'所在主机')))
class UpdateCmdbValidator(serializers.Serializer): type = serializers.ChoiceField( choices=CFG_TYPE_CHOICES, error_messages=serializers.CommonErrorMessages('type')) cfg_items = serializers.ListField( error_messages=serializers.CommonErrorMessages('cfg_items'))
class ActivateNotifyMemberValidator(serializers.Serializer): member_id = serializers.CharField(required=True, max_length=20, validators=[member_id_validator]) method = serializers.ChoiceField(required=True, choices=("phone", "email"), validators=[])
class BindJumperPubIpSerializer(serializers.Serializer): owner = serializers.CharField( required=True, max_length=100, error_messages=serializers.CommonErrorMessages(_(u"用户"))) zone = serializers.ChoiceField( required=True, choices=["dev", "test", "prod"], error_messages=serializers.CommonErrorMessages(_(u"区域"))) jumper_id = serializers.CharField( required=True, max_length=200, error_messages=serializers.CommonErrorMessages(_(u"主机ID"))) ip_id = serializers.CharField( required=True, max_length=100, error_messages=serializers.CommonErrorMessages(_(u"IP_ID"))) # TODO: 二期需修改 pub_ip_type = serializers.CharField( required=False, max_length=100, default="virtual", error_messages=serializers.CommonErrorMessages(_(u"IP类型")))
class CreateStorageResourcePoolsValidator(serializers.Serializer): """ 校验创建存储资源池接口输入 """ owner = serializers.CharField( max_length=20, default="cloudin", error_messages=serializers.CommonErrorMessages(_(u"所有者")) ) zone = serializers.CharField( max_length=20, default="yz", error_messages=serializers.CommonErrorMessages(_(u"区信息")) ) name = serializers.CharField( max_length=20, error_messages=serializers.CommonErrorMessages(_(u"存储池名称")) ) kind = serializers.ChoiceField( choices=['ssd', 'sata'], error_messages=serializers.CommonErrorMessages(_(u"存储池类型")) ) size = serializers.IntegerField( min_value=2, error_messages=serializers.CommonErrorMessages(_(u"存储池名称")) )
class DescribeDisksValidator(serializers.Serializer): # 硬盘的唯一id, 非api disk id disk_id = serializers.CharField(required=False, max_length=11, validators=[disk_id_validator]) # 特定的要展示的硬盘id disks = serializers.ListField(required=False, validators=[disk_id_validator]) sort_key = serializers.CharField(required=False, max_length=20, validators=[disk_sort_key_valiator]) limit = serializers.IntegerField(required=False, min_value=0) offset = serializers.IntegerField(required=False, min_value=0) availability_zone = serializers.CharField(required=False, max_length=64) search_key = serializers.CharField(required=False, max_length=64, allow_blank=True) status = serializers.ChoiceField( required=False, choices=(('available', u'available'), ('in-use', u'in-use'), ('creating', u'creating'), ('deleting', u'deleting'), ('attaching', u'attaching'), ('detaching', u'detaching'), ('error', u'error'), ('error_deleting', u'error_deleting'), ('backing-up', u'backing-up'), ('restoring-backup', u'restoring-backup')))
class DescribeWafSeniorSerializer(WafBaseSerializer): """ 高级防护列表、监控列表、记录列表 """ type = serializers.ChoiceField( required=True, choices=["cc", "collision"], error_messages=serializers.CommonErrorMessages(u"类型"))
class DescribeWafIplistSerializer(WafBaseSerializer): """ 黑白名单列表 """ type = serializers.ChoiceField( required=True, choices=["blackip", "whiteip"], error_messages=serializers.CommonErrorMessages(u"类型"))
class ListWafAttacklogSerializer(WafBaseSerializer): """ 获取攻击日志 """ attack_type = serializers.ChoiceField( required=False, choices=[ "XSS", "CC", "Acl", "CSRF", "Http-Protocol", "Waf-Rule", "Http-Status", "Scanner", "Collision", "SQL", "Hotlink", "Directory-Traversal", "All" ], error_messages=serializers.CommonErrorMessages(u"攻击类型")) process_action = serializers.ChoiceField( required=False, choices=["pass", "notify", "deny", "captcha", "all"], error_messages=serializers.CommonErrorMessages(u"防护动作"))
class DescribeWafCookieSerializer(WafBaseSerializer): """ cookie防护列表 """ type = serializers.ChoiceField( required=True, choices=["cookie"], error_messages=serializers.CommonErrorMessages(u"查询类型"))