add various validation for schedule extra_data

This commit is contained in:
AlanCoding
2017-07-14 23:48:42 -04:00
parent 8482ed0432
commit ed7e558575
2 changed files with 30 additions and 0 deletions

View File

@@ -3427,6 +3427,24 @@ class ScheduleSerializer(BaseSerializer):
'Schedule its source project `{}` instead.'.format(value.source_project.name)))
return value
def validate_extra_data(self, value):
if isinstance(value, dict):
return value
return vars_validate_or_raise(value)
def validate(self, attrs):
extra_data = parse_yaml_or_json(attrs.get('extra_data', {}))
if extra_data:
ujt = None
if 'unified_job_template' in attrs:
ujt = attrs['unified_job_template']
elif self.instance:
ujt = self.instance.unified_job_template
if ujt and isinstance(ujt, (Project, InventorySource)):
raise serializers.ValidationError({'extra_data': _(
'Projects and inventory updates cannot accept extra variables.')})
return super(ScheduleSerializer, self).validate(attrs)
# We reject rrules if:
# - DTSTART is not include
# - INTERVAL is not included