Cornices/cornice

Removing default validator for particular service

dieka13 opened this issue · 1 comments

i'm using pyramid_jwt to authenticate my service. i want JWT to always checked except in /auth service. i followed the instruction from documentation, so i add it into DEFAULT_VALIDATORS:

from cornice.validators import DEFAULT_VALIDATORS

def check_jwt(request, **kwargs):
    if request.authenticated_userid is None:
        request.errors.add('header', 'Authorization', 'You need to provide a token')
        request.errors.status = 401

    return True

def includeme(config):
    DEFAULT_VALIDATORS.append(check_jwt)

so in my auth service i do this:

from ..routes import check_jwt

auth = Service(name='auth', path='/auth', description="")
auth.default_validators.remove(check_jwt)

but it always call check_jwt even after i remove it from default_validators. how do you remove a validator correctly?

Indeed, the default validators are passed to every service.

Can you try the exclude= parameter?

Something like auth = Service(...., exclude=(check_jwt,))

The documentation should be improved, there's just a small mention... I had to look into the code :/