def test_obfuscation(self): req = make_request("/__debug__", _ENVIRON) controller = StandardController(None) def _more_secret(*args): return ['stuff', 'and', 'pymysql://*****:*****@localhost/sync'] controller._debug_server = _more_secret debug = controller._debug(req) # make sure we don't have any password left self.assertTrue('xxxx' not in debug.body)
def __init__(self, urls, controllers, config=None, auth_class=Authentication): self.mapper = Mapper() if config is not None: self.config = config else: self.config = {} # global config self.retry_after = self.config.get('global.retry_after', 1800) # heartbeat page self.heartbeat_page = self.config.get('global.heartbeat_page', '__heartbeat__') # debug page, if any self.debug_page = self.config.get('global.debug_page') # loading the authentication tool self.auth = None if auth_class is None else auth_class(self.config) # loading and connecting controllers self.controllers = dict([(name, klass(self)) for name, klass in controllers.items()]) for url in urls: if len(url) == 4: verbs, match, controller, action = url extras = {} elif len(url) == 5: verbs, match, controller, action, extras = url else: msg = "Each URL description needs 4 or 5 elements. Got %s" \ % str(url) raise ValueError(msg) if isinstance(verbs, str): verbs = [verbs] self.mapper.connect(None, match, controller=controller, action=action, conditions=dict(method=verbs), **extras) # loads host-specific configuration self._host_configs = {} # heartbeat & debug pages self.standard_controller = StandardController(self) # rehooked overridable points so they can be overridden in the base app self.standard_controller._debug_server = self._debug_server self.standard_controller._check_server = self._check_server
def __init__(self, urls, controllers, config=None, auth_class=None): self.mapper = Mapper() if config is None: self.config = Config() elif isinstance(config, Config): self.config = config else: # try to convert to config object self.config = Config(config) # global config self.retry_after = self.config.get('global.retry_after', 1800) # heartbeat page self.heartbeat_page = self.config.get('global.heartbeat_page', '__heartbeat__') # debug page, if any self.debug_page = self.config.get('global.debug_page') # check if we want to clean when the app ends self.sigclean = self.config.get('global.clean_shutdown', True) # load the specified plugin modules self.modules = dict() app_modules = self.config.get('app.modules', []) if isinstance(app_modules, basestring): app_modules = [app_modules] for module in app_modules: self.modules[module] = load_and_configure(self.config, module) if self.modules.get('metlog_loader') is not None: # stash the metlog client in a more convenient spot self.logger = self.modules.get('metlog_loader').default_client else: # there was no metlog config, default to using StdLibLoggingSender sender = StdLibLoggingSender('syncserver', json_types=[]) metlog = MetlogClient(sender, 'syncserver') CLIENT_HOLDER.set_client(metlog.logger, metlog) self.logger = metlog if not hasattr(self.logger, "cef"): log_cef_fn = metlog_cef.cef_plugin.config_plugin(dict()) self.logger.add_method(log_cef_fn) # XXX: this should be converted to auto-load in self.modules # loading the authentication tool self.auth = None if auth_class is None else auth_class(self.config) # loading and connecting controllers self.controllers = dict([(name, klass(self)) for name, klass in controllers.items()]) for url in urls: if len(url) == 4: verbs, match, controller, action = url extras = {} elif len(url) == 5: verbs, match, controller, action, extras = url else: msg = "Each URL description needs 4 or 5 elements. Got %s" \ % str(url) raise ValueError(msg) if isinstance(verbs, str): verbs = [verbs] # wrap action methods w/ metlog decorators controller_instance = self.controllers.get(controller) if controller_instance is not None: wrapped_name = '_%s_wrapped' % action method = getattr(controller_instance, action, None) if ((method is not None) and (not hasattr(controller_instance, wrapped_name))): # add wrapped method wrapped = svc_timeit(method) wrapped = incr_count(wrapped) wrapped = send_services_data(wrapped) setattr(controller_instance, wrapped_name, wrapped) self.mapper.connect(None, match, controller=controller, action=action, conditions=dict(method=verbs), **extras) # loads host-specific configuration self._host_configs = {} # heartbeat & debug pages self.standard_controller = StandardController(self) # rehooked overridable points so they can be overridden in the base app self.standard_controller._debug_server = self._debug_server self.standard_controller._check_server = self._check_server # hooking callbacks when the app shuts down self.killing = self.shutting = False self.graceful_shutdown_interval = self.config.get( 'global.graceful_shutdown_interval', 1.) self.hard_shutdown_interval = self.config.get( 'global.hard_shutdown_interval', 1.) if self.sigclean: signal.signal(signal.SIGTERM, self._sigterm) signal.signal(signal.SIGINT, self._sigterm)