Пример #1
0
    def validate_config(self, config):
        """We only validate the config if passed.

        Also we use the JobSpecification to check if this config was
        intended as job.
        """
        validate_job_spec_config(config)
        return config
Пример #2
0
    def validate_content(self, content):
        """We only validate the content if passed.

        Also we use the JobSpecification to check if this content was
        intended as job.
        """
        # content is optional
        if not content:
            return content

        validate_job_spec_config(content)
        return content
Пример #3
0
    def post(self, request, *args, **kwargs):
        ttl = self.request.data.get(RedisTTL.TTL_KEY)
        if ttl:
            try:
                ttl = RedisTTL.validate_ttl(ttl)
            except ValueError:
                raise ValidationError('ttl must be an integer.')

        auditor.record(event_type=self.event_type,
                       instance=self.job,
                       actor_id=self.request.user.id,
                       actor_name=self.request.user.username)

        description = None
        config = None
        update_code_reference = False
        if 'config' in request.data:
            spec = validate_job_spec_config(
                [self.job.specification.parsed_data, request.data['config']], raise_for_rest=True)
            config = spec.parsed_data
        if 'update_code' in request.data:
            try:
                update_code_reference = to_bool(request.data['update_code'])
            except TypeError:
                raise ValidationError('update_code should be a boolean')
        if 'description' in request.data:
            description = request.data['description']
        new_obj = self.clone(obj=self.job,
                             config=config,
                             update_code_reference=update_code_reference,
                             description=description)
        if ttl:
            RedisTTL.set_for_job(job_id=new_obj.id, value=ttl)
        serializer = self.get_serializer(new_obj)
        return Response(status=status.HTTP_201_CREATED, data=serializer.data)
Пример #4
0
    def post(self, request, *args, **kwargs):
        obj = self.get_object()
        auditor.record(event_type=self.event_type,
                       instance=obj,
                       actor_id=self.request.user.id)

        description = None
        config = None
        update_code_reference = False
        if 'config' in request.data:
            spec = validate_job_spec_config(
                [obj.specification.parsed_data, request.data['config']],
                raise_for_rest=True)
            config = spec.parsed_data
        if 'update_code' in request.data:
            try:
                update_code_reference = to_bool(request.data['update_code'])
            except TypeError:
                raise ValidationError('update_code should be a boolean')
        if 'description' in request.data:
            description = request.data['description']
        new_obj = self.clone(obj=obj,
                             config=config,
                             update_code_reference=update_code_reference,
                             description=description)
        serializer = self.get_serializer(new_obj)
        return Response(status=status.HTTP_201_CREATED, data=serializer.data)
Пример #5
0
 def create(self, validated_data):
     """Check the params or set the value from the specification."""
     config = None
     if validated_data.get('config'):
         config = validate_job_spec_config(validated_data['config'])
     if not validated_data.get('tags') and config:
         validated_data['tags'] = config.tags
     return super().create(validated_data=validated_data)
Пример #6
0
    def validate_config(self, config):
        """We only validate the config if passed.

        Also we use the JobSpecification to check if this config was
        intended as job.
        """
        spec = validate_job_spec_config(config)

        if spec.is_job:
            # Resume normal creation
            return config

        # Raise an error to tell the user to use job creation instead
        raise ValidationError(
            'Current job creation could not be performed.\n'
            'The reason is that the specification sent correspond '
            'to a `{}`.\n'.format(spec.kind))