<s> import logging <EOL> import re <EOL> from jumpgate . common import exceptions <EOL> from jumpgate . common import hooks <EOL> from jumpgate . identity . drivers import core as identity <EOL> LOG = logging . getLogger ( __name__ ) <EOL> NOAUTH = [ re . compile ( e ) for e in [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ] <EOL> def protected ( target ) : <EOL> for expr in NOAUTH : <EOL> if expr . match ( target ) : <EOL> return False <EOL> return True <EOL> @ hooks . request_hook ( True ) <EOL> def validate_token ( req , resp , kwargs ) : <EOL> tenant_id = req . env . get ( '<STR_LIT>' , None ) <EOL> token = req . headers . get ( '<STR_LIT>' , None ) <EOL> if ( req . env . get ( '<STR_LIT>' , None ) is not None or <EOL> req . env . get ( '<STR_LIT>' , False ) or <EOL> req . env . get ( '<STR_LIT>' , None ) is not None ) : <EOL> return <EOL> if token is not None : <EOL> if tenant_id is None : <EOL> tenant_id = kwargs . get ( '<STR_LIT>' , <EOL> req . headers . get ( '<STR_LIT>' ) ) <EOL> req . env [ '<STR_LIT>' ] = tenant_id <EOL> LOG . debug ( "<STR_LIT>" % ( token ) ) <EOL> identity . validate_token_id ( token , tenant_id = tenant_id ) <EOL> req . env [ '<STR_LIT>' ] = identity . token_id_driver ( ) . token_from_id ( token ) <EOL> elif protected ( "<STR_LIT>" % ( req . method , req . path ) ) : <EOL> raise exceptions . Unauthorized ( '<STR_LIT>' ) </s>
