def setUpClass(cls): cls.config = testing.setUp() settings = {} try: fileConfig(cls.get_ini()) except NoSectionError: pass load_into_settings(cls.get_ini(), settings) cls.config.add_settings(settings) metlog_wrapper = load_from_settings('metlog', cls.config.registry.settings) for logger in ('tokenserver', 'mozsvc', 'powerhose'): hook_logger(logger, metlog_wrapper.client) cls.config.registry['metlog'] = metlog_wrapper.client cls.config.include("tokenserver") load_and_register("tokenserver", cls.config) cls.backend = cls.config.registry.getUtility(INodeAssignment) cls.cluster = get_cluster( 'tokenserver.tests.mockworker.crypto_worker', numprocesses=1, background=True, # debug=True, worker_params={'config': cls.get_ini()}) cls.cluster.start() time.sleep(1.)
def includeme(config): settings = config.registry.settings if settings.get('tokenserver.monkey_patch_gevent', True): monkey_patch_gevent() config.include("cornice") config.include("mozsvc") config.include("tokenserver.tweens") config.scan("tokenserver.views") # initializes the assignment backend load_and_register("tokenserver", config) # initialize the browserid backend if it exists if "browserid.backend" in settings: load_and_register("browserid", config) # initialize the auth backend if it exists if "oauth.backend" in settings: load_and_register("oauth", config) # load apps and set them up back in the setting key = 'tokenserver.applications' applications = defaultdict(list) for element in settings.get(key, '').split(','): element = element.strip() if element == '': continue element = element.split('-') if len(element) != 2: continue app, version = element applications[app].append(version) settings[key] = applications # load the secrets backend, with a b/w-compat hook # for the old 'secrets_file' setting. secrets_file = settings.get('tokenserver.secrets_file') if secrets_file is not None: if 'tokenserver.secrets.backend' in settings: raise ValueError("can't use secrets_file with secrets.backend") if isinstance(secrets_file, basestring): secrets_file = secrets_file.split() settings['tokenserver.secrets.backend'] = 'mozsvc.secrets.Secrets' settings['tokenserver.secrets.filename'] = secrets_file secrets = load_from_settings('tokenserver.secrets', settings) settings['tokenserver.secrets'] = secrets # ensure the metrics_id_secret_key is an ascii string. id_key = settings.get('fxa.metrics_uid_secret_key') if id_key is None: logger.warning( 'fxa.metrics_uid_secret_key is not set. ' 'This will allow PII to be more easily identified') elif isinstance(id_key, unicode): settings['fxa.metrics_uid_secret_key'] = id_key.encode('ascii') read_endpoints(config)
def includeme(config): settings = config.registry.settings config.include("cornice") config.include("mozsvc") config.include("tokenserver.tweens") config.scan("tokenserver.views") # initializes the assignment backend load_and_register("tokenserver", config) # initialize the browserid backend if it exists if "browserid.backend" in settings: load_and_register("browserid", config) # initialize the oauth backend if it exists if "oauth.backend" in settings: load_and_register("oauth", config) # initialize node-type classifier load_node_type_classifier(config) # load apps and set them up back in the setting key = 'tokenserver.applications' applications = defaultdict(list) for element in settings.get(key, '').split(','): element = element.strip() if element == '': continue element = element.split('-') if len(element) != 2: continue app, version = element applications[app].append(version) settings[key] = applications # load the secrets backend, with a b/w-compat hook # for the old 'secrets_file' setting. secrets_file = settings.get('tokenserver.secrets_file') if secrets_file is not None: if 'tokenserver.secrets.backend' in settings: raise ValueError("can't use secrets_file with secrets.backend") if isinstance(secrets_file, basestring): secrets_file = secrets_file.split() settings['tokenserver.secrets.backend'] = 'mozsvc.secrets.Secrets' settings['tokenserver.secrets.filename'] = secrets_file secrets = load_from_settings('tokenserver.secrets', settings) settings['tokenserver.secrets'] = secrets # ensure the metrics_id_secret_key is an ascii string. id_key = settings.get('fxa.metrics_uid_secret_key') if id_key is None: logger.warning( 'fxa.metrics_uid_secret_key is not set. ' 'This will allow PII to be more easily identified') elif isinstance(id_key, unicode): settings['fxa.metrics_uid_secret_key'] = id_key.encode('ascii') read_endpoints(config)
def includeme(config): settings = config.registry.settings if settings.get('tokenserver.monkey_patch_gevent', True): monkey_patch_gevent() config.include("cornice") config.include("mozsvc") config.include("tokenserver.tweens") config.scan("tokenserver.views") # initializes the assignment backend load_and_register("tokenserver", config) # initialize the and browserid backend if it exists if "browserid.backend" in settings: load_and_register("browserid", config) # load apps and set them up back in the setting key = 'tokenserver.applications' applications = defaultdict(list) for element in settings.get(key, '').split(','): element = element.strip() if element == '': continue element = element.split('-') if len(element) != 2: continue app, version = element applications[app].append(version) settings[key] = applications # load the secrets backend, with a b/w-compat hook # for the old 'secrets_file' setting. secrets_file = settings.get('tokenserver.secrets_file') if secrets_file is not None: if 'tokenserver.secrets.backend' in settings: raise ValueError("can't use secrets_file with secrets.backend") if isinstance(secrets_file, basestring): secrets_file = secrets_file.split() settings['tokenserver.secrets.backend'] = 'mozsvc.secrets.Secrets' settings['tokenserver.secrets.filename'] = secrets_file secrets = load_from_settings('tokenserver.secrets', settings) settings['tokenserver.secrets'] = secrets read_endpoints(config)
def setUp(self): self.config = testing.setUp() settings = {} load_into_settings(self.get_ini(), settings) self.config.add_settings(settings) metlog_wrapper = load_from_settings('metlog', self.config.registry.settings) for logger in ('tokenserver', 'mozsvc', 'powerhose'): hook_logger(logger, metlog_wrapper.client) self.config.registry['metlog'] = metlog_wrapper.client self.config.include("tokenserver") load_and_register("tokenserver", self.config) self.backend = self.config.registry.getUtility(INodeAssignment) wsgiapp = self.config.make_wsgi_app() wsgiapp = CatchErrors(wsgiapp) self.app = TestApp(wsgiapp) # Mock out the verifier to return successfully by default. self.mock_verifier_context = self.mock_verifier() self.mock_verifier_context.__enter__()
def load_metlog_client(config): """Load and return a metlog client for the given Pyramid Configurator. This is a shortcut function to load and return the metlog client specified by the given Pyramid Configurator object. If the configuration does not specify any metlog settings, a default client is constructed that routes all messages into the stdlib logging routines. The metlog client is cached in the Configurator's registry, so multiple calls to this function will return a single instance. """ settings = config.registry.settings client = config.registry.get("metlog") if client is None: if "metlog.backend" not in settings: settings.update(DEFAULT_METLOG_SETTINGS) client = load_from_settings('metlog', settings).client config.registry['metlog'] = client if not isinstance(client.sender, StdLibLoggingSender): hook_logger("mozsvc", client) return client
def includeme(config): config.include("cornice") config.include("mozsvc") config.scan("fxap.views") settings = config.registry.settings # default metlog setup if "metlog.backend" not in settings: settings["metlog.backend"] = "mozsvc.metrics.MetlogPlugin" settings["metlog.enabled"] = True settings["metlog.sender_class"] = "metlog.senders.StdOutSender" metlog_wrapper = load_from_settings("metlog", settings) if settings["metlog.enabled"]: for logger in ("fxap", "mozsvc"): hook_logger(logger, metlog_wrapper.client) config.registry["metlog"] = metlog_wrapper.client # initializes the backend load_and_register("fxap", config)
def setUpClass(cls): cls.config = testing.setUp() settings = {} try: fileConfig(cls.get_ini()) except NoSectionError: pass load_into_settings(cls.get_ini(), settings) cls.config.add_settings(settings) metlog_wrapper = load_from_settings('metlog', cls.config.registry.settings) for logger in ('tokenserver', 'mozsvc', 'powerhose'): hook_logger(logger, metlog_wrapper.client) cls.config.registry['metlog'] = metlog_wrapper.client cls.config.include("tokenserver") load_and_register("tokenserver", cls.config) cls.backend = cls.config.registry.getUtility(INodeAssignment) cls.cluster = get_cluster('tokenserver.tests.mockworker.crypto_worker', numprocesses=1, background=True, #debug=True, worker_params={'config': cls.get_ini()}) cls.cluster.start() time.sleep(1.)
def setUp(self): self.config = testing.setUp() settings = {} load_into_settings(self.get_ini(), settings) self.config.add_settings(settings) metlog_wrapper = load_from_settings('metlog', self.config.registry.settings) for logger in ('tokenserver', 'mozsvc', 'powerhose'): hook_logger(logger, metlog_wrapper.client) self.config.registry['metlog'] = metlog_wrapper.client self.config.include("tokenserver") load_and_register("tokenserver", self.config) self.backend = self.config.registry.getUtility(INodeAssignment) wsgiapp = self.config.make_wsgi_app() wsgiapp = CatchErrors(wsgiapp) self.app = TestApp(wsgiapp) self.patched = patched_supportdoc_fetching() self.patched.__enter__() # by default the conditions are accepted self.backend.set_accepted_conditions_flag('aitc-1.0', True)
def includeme(config): settings = config.registry.settings if settings.get('tokenserver.monkey_patch_gevent', True): monkey_patch_gevent() config.include("cornice") config.include("mozsvc") config.include("tokenserver.tweens") config.scan("tokenserver.views") # default metlog setup if 'metlog.backend' not in settings: settings['metlog.backend'] = 'mozsvc.metrics.MetlogPlugin' settings['metlog.enabled'] = True settings['metlog.sender_class'] = 'metlog.senders.StdOutSender' metlog_wrapper = load_from_settings('metlog', settings) if settings['metlog.enabled']: for logger in ('tokenserver', 'mozsvc', 'powerhose'): hook_logger(logger, metlog_wrapper.client) config.registry['metlog'] = metlog_wrapper.client # initializes the assignment backend load_and_register("tokenserver", config) # initialize the powerhose and browserid backends if they exist if "powerhose.backend" in settings: load_and_register("powerhose", config) if "browserid.backend" in settings: load_and_register("browserid", config) # load apps and set them up back in the setting key = 'tokenserver.applications' applications = defaultdict(list) for element in settings.get(key, '').split(','): element = element.strip() if element == '': continue element = element.split('-') if len(element) != 2: continue app, version = element applications[app].append(version) settings[key] = applications # load the secrets backend, with a b/w-compat hook # for the old 'secrets_file' setting. secrets_file = settings.get('tokenserver.secrets_file') if secrets_file is not None: if 'tokenserver.secrets.backend' in settings: raise ValueError("can't use secrets_file with secrets.backend") if isinstance(secrets_file, basestring): secrets_file = secrets_file.split() settings['tokenserver.secrets.backend'] = 'mozsvc.secrets.Secrets' settings['tokenserver.secrets.filename'] = secrets_file secrets = load_from_settings('tokenserver.secrets', settings) settings['tokenserver.secrets'] = secrets read_endpoints(config)
def includeme(config): try: from gevent import monkey from gevent_zeromq import monkey_patch monkey.patch_all() monkey_patch() except ImportError: pass config.include("cornice") config.include("mozsvc") config.scan("tokenserver.views") settings = config.registry.settings # default metlog setup if 'metlog.backend' not in settings: settings['metlog.backend'] = 'mozsvc.metrics.MetlogPlugin' settings['metlog.enabled'] = True settings['metlog.sender_class'] = \ 'metlog.senders.StdOutSender' metlog_wrapper = load_from_settings('metlog', settings) if settings['metlog.enabled']: for logger in ('tokenserver', 'mozsvc', 'powerhose'): hook_logger(logger, metlog_wrapper.client) config.registry['metlog'] = metlog_wrapper.client # initializes the assignment backend load_and_register("tokenserver", config) # initialize the powerhose and browserid backends if they exist for section in ("powerhose", "browserid"): try: load_and_register(section, config) except NoSectionError: pass # load apps and set them up back in the setting key = 'tokenserver.applications' applications = defaultdict(list) for element in settings.get(key, '').split(','): element = element.strip() if element == '': continue element = element.split('-') if len(element) != 2: continue app, version = element applications[app].append(version) settings[key] = applications # load the secrets file(s) key = 'tokenserver.secrets_file' secret_file = settings[key] if not isinstance(secret_file, list): secret_file = [secret_file] files = [] for line in secret_file: secret_file = [file for file in [file.strip() for file in line.split()] if file != ''] files.extend(secret_file) settings[key] = Secrets(files) read_endpoints(config)