def test_scrubbed_logs(logger):
    """Test Depot ID TBD.

    Verify if sensitive messages are getting scrubbed.
    """
    config = LoggingConfig(ignore_env=True, **{'enable_scrubbing': True})
    configure_logging(config)
    for msg in ['123456789', '123445677888', '11aa123456789a']:
        logger.info(msg)
        assert '<<SCRUBBED>>' in logger_stream_contents(logger)
        # Clear the stream after each iteration so we have clean stream
        logger_stream_reset(logger)

        # Also check the same thing works for a child logger
        logging.getLogger('dirbs.import').info(msg)
        assert '<<SCRUBBED>>' in logger_stream_contents(logger)
        logger_stream_reset(logger)
Example #2
0
docs_v1 = ApiDoc(app, version='v1')
docs_v2 = ApiDoc(app, version='v2')

# Parse config
try:
    cp = ConfigParser()
    app.config['DIRBS_CONFIG'] = cp.parse_config(ignore_env=False)
except ConfigParseException:
    logger = logging.getLogger('dirbs.config')
    logger.critical(
        'Exception encountered during parsing of config (.yml file). '
        'See console above for details...')
    sys.exit(1)

# Update the logging based on the parsed config
configure_logging(app.config['DIRBS_CONFIG'].log_config)

# Initialize file logging
setup_file_logging(app.config['DIRBS_CONFIG'].log_config, 'dirbs-api')

# Init statsd client
statsd = StatsClient(app.config['DIRBS_CONFIG'].statsd_config)

# Init custom JSONEncoder (handles dates, etc.)
app.json_encoder = utils.JSONEncoder


def _metrics_type_from_req_ctxt(req: callable) -> str:
    """
    Utility method to get a metrics path for the API type.