Project

General

Profile

Actions

Fix #9017

closed

[paddles] implement validation across all controller methods

Added by Alfredo Deza over 9 years ago. Updated almost 6 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
Category:
-
Target version:
-
% Done:

0%

Source:
Development
Tags:
Backport:
Reviewed:
Affected Versions:
ceph-qa-suite:
Pull request ID:
Crash signature (v1):
Crash signature (v2):

Description

paddles has a lot of boilerplate in controllers that look like:

    @index.when(method='POST', template='json')
    def index_post(self):
        # save to DB here
        try:
            name = request.json.get('name')
        except ValueError:
            rollback()
            error('/errors/invalid/', 'could not decode JSON body')
        if not name:
            error('/errors/invalid/', "could not find required key: 'name'")

        if not Run.query.filter_by(name=name).first():
            log.info("Creating run: %s", name)
            Run(name)
            return dict()
        else:
            error('/errors/invalid/', "run with name %s already exists" % name)

That pattern is repeated in a lot of places. This is how the above should look like with `pecan-notario`:

    @index.when(method='POST', template='json')
    @validate(('name', types.string), handler='/errors/schema')
    def index_post(self):
        name = request.json.get('name')
        if not Run.query.filter_by(name=name).first():
            log.info("Creating run: %s", name)
            Run(name)
            return dict()
        else:
            error('/errors/invalid/', "run with name %s already exists" % name)
Actions #1

Updated by Alfredo Deza over 9 years ago

  • Status changed from New to Fix Under Review
Actions #2

Updated by Sage Weil almost 6 years ago

  • Status changed from Fix Under Review to Rejected
Actions

Also available in: Atom PDF