def __init__(self, libraries, opts, testing=False, notify_changes=None): ctx = Context(libraries, opts, testing=testing, notify_changes=notify_changes) self.auth_controller = None if opts.auth: has_ssl = opts.ssl_certfile is not None and opts.ssl_keyfile is not None prefer_basic_auth = { 'auto': has_ssl, 'basic': True }.get(opts.auth_mode, False) self.auth_controller = AuthController( user_credentials=ctx.user_manager, prefer_basic_auth=prefer_basic_auth, ban_time_in_minutes=opts.ban_for, ban_after=opts.ban_after) self.router = Router(ctx=ctx, url_prefix=opts.url_prefix, auth_controller=self.auth_controller) for module in SRV_MODULES: module = import_module('calibre.srv.' + module) self.router.load_routes(itervalues(vars(module))) self.router.finalize() self.router.ctx.url_for = self.router.url_for self.dispatch = self.router.dispatch
def router(prefer_basic_auth=False): from calibre.srv.auth import AuthController return Router(globals().itervalues(), auth_controller=AuthController( { 'testuser': '******', '!@#$%^&*()-=_+': '!@#$%^&*()-=_+' }, prefer_basic_auth=prefer_basic_auth, realm=REALM, max_age_seconds=1))
def router(prefer_basic_auth=False, ban_for=0, ban_after=5): from calibre.srv.auth import AuthController return Router(itervalues(globals()), auth_controller=AuthController( { 'testuser': '******', '!@#$%^&*()-=_+': '!@#$%^&*()-=_+' }, ban_time_in_minutes=ban_for, ban_after=ban_after, prefer_basic_auth=prefer_basic_auth, realm=REALM, max_age_seconds=1))
def __init__(self, libraries, opts, testing=False): ctx = Context(libraries, opts, testing=testing) self.auth_controller = None if opts.auth: has_ssl = opts.ssl_certfile is not None and opts.ssl_keyfile is not None prefer_basic_auth = { 'auto': has_ssl, 'basic': True }.get(opts.auth_mode, 'digest') self.auth_controller = AuthController( user_credentials=ctx.user_manager, prefer_basic_auth=prefer_basic_auth) self.router = Router(ctx=ctx, url_prefix=opts.url_prefix, auth_controller=self.auth_controller) for module in ('content', 'ajax', 'code'): module = import_module('calibre.srv.' + module) self.router.load_routes(vars(module).itervalues()) self.router.finalize() self.router.ctx.url_for = self.router.url_for self.dispatch = self.router.dispatch