Exemple #1
0
def test_project_keys_without_mysql():
    config = Config()
    config.PROJECT_KEYS = [
        (1, "public1", "secret1"),
        (2, "public2", "secret2"),
        (1, "public1.2", "secret1.2"),
    ]
    config.MYSQL_HOST = None
    project_loader = ProjectLoader(config)
    project_keys = project_loader.get_project_keys()
    expect(project_keys).to_equal({
        1: {"public_key": ["public1", "public1.2"], "secret_key": ["secret1", "secret1.2"]},
        2: {"public_key": ["public2"], "secret_key": ["secret2"]},
    })
Exemple #2
0
def test_project_keys_without_db():
    config = Config()
    config.PROJECT_KEYS = [
        (1, "public1", "secret1"),
        (2, "public2", "secret2"),
        (1, "public1.2", "secret1.2"),
    ]
    config.DB_HOST = None
    project_loader = ProjectLoader(config)
    project_keys = project_loader.get_project_keys()
    expect(project_keys).to_equal({
        1: {
            "public_key": ["public1", "public1.2"],
            "secret_key": ["secret1", "secret1.2"]
        },
        2: {
            "public_key": ["public2"],
            "secret_key": ["secret2"]
        },
    })
Exemple #3
0
def get_config(*args, **kw):
    if not kw:
        kw = {}
    kw['DB_NAME'] = 'sentry_tests'
    env_prefix = 'CYCLOPS_TEST_'
    for env_name, env_value in os.environ.items():
        if env_name.startswith(
                'CYCLOPS_TEST_') and len(env_name) > len(env_prefix):
            kw[env_name[len(env_prefix):]] = env_value

    return Config(**kw)
Exemple #4
0
def main(args=None, main_loop=None, app=CyclopsApp, server_impl=HTTPServer, get_ioloop=get_ioloop):
    if args is None:
        args = sys.argv[1:]

    parser = argparse.ArgumentParser()
    parser.add_argument('--port', '-p', type=int, default="9999", help="Port to start the server with.")
    parser.add_argument('--bind', '-b', default="0.0.0.0", help="IP to bind the server to.")
    parser.add_argument('--conf', '-c', default=DEFAULT_CONFIG_PATH, help="Path to configuration file.")
    parser.add_argument('--verbose', '-v', action='count', default=0, help='Log level: v=warning, vv=info, vvv=debug.')
    parser.add_argument(
        '--debug',
        '-d',
        action='store_true',
        default=False,
        help='Indicates whether to run tornado in debug mode.'
    )

    options = parser.parse_args(args)

    log_level = LOGS[options.verbose].upper()
    logging.basicConfig(level=getattr(logging, log_level), format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

    if not isabs(options.conf):
        logging.debug("Configuration file {0} is not absolute. Converting to abspath".format(options.conf))
        options.conf = abspath(options.conf)

    logging.info("Loading configuration file at {0}...".format(options.conf))

    config = Config.load(path=options.conf, conf_name=split(options.conf)[-1], lookup_paths=[
        os.curdir,
        expanduser('~'),
        '/etc/',
    ])

    logging.info("Using configuration file at {0}.".format(config.config_file))

    if main_loop is None:
        main_loop = get_ioloop()

    application = app(config, options.debug, main_loop)

    server = server_impl(application, xheaders=True)

    server.bind(options.port, options.bind)
    server.start(1)

    logging.info('-- Cyclops started listening in %s:%d --' % (options.bind, options.port))
    try:
        main_loop.start()
    except KeyboardInterrupt:
        logging.info('')
        logging.info('-- Cyclops closed by user interruption --')
Exemple #5
0
def get_config(*args, **kw):
    if not kw:
        kw = {}
    kw['DB_NAME'] = 'sentry_tests'

    return Config(**kw)
Exemple #6
0
def main(args=None,
         main_loop=None,
         app=CyclopsApp,
         server_impl=HTTPServer,
         get_ioloop=get_ioloop):
    if args is None:
        args = sys.argv[1:]

    parser = argparse.ArgumentParser()
    parser.add_argument('--port',
                        '-p',
                        type=int,
                        default="9999",
                        help="Port to start the server with.")
    parser.add_argument('--bind',
                        '-b',
                        default="0.0.0.0",
                        help="IP to bind the server to.")
    parser.add_argument('--conf',
                        '-c',
                        default=DEFAULT_CONFIG_PATH,
                        help="Path to configuration file.")
    parser.add_argument('--verbose',
                        '-v',
                        action='count',
                        default=0,
                        help='Log level: v=warning, vv=info, vvv=debug.')
    parser.add_argument('--debug',
                        '-d',
                        action='store_true',
                        default=False,
                        help='Indicates whether to run tornado in debug mode.')

    options = parser.parse_args(args)

    log_level = LOGS[options.verbose].upper()
    logging.basicConfig(
        level=getattr(logging, log_level),
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

    if not isabs(options.conf):
        logging.debug(
            "Configuration file {0} is not absolute. Converting to abspath".
            format(options.conf))
        options.conf = abspath(options.conf)

    logging.info("Loading configuration file at {0}...".format(options.conf))

    config = Config.load(path=options.conf,
                         conf_name=split(options.conf)[-1],
                         lookup_paths=[
                             os.curdir,
                             expanduser('~'),
                             '/etc/',
                         ])

    logging.info("Using configuration file at {0}.".format(config.config_file))

    if main_loop is None:
        main_loop = get_ioloop()

    application = app(config, options.debug, main_loop)

    server = server_impl(application, xheaders=True)

    server.bind(options.port, options.bind)
    server.start(1)

    logging.info('-- Cyclops started listening in %s:%d --' %
                 (options.bind, options.port))
    try:
        main_loop.start()
    except KeyboardInterrupt:
        logging.info('')
        logging.info('-- Cyclops closed by user interruption --')
Exemple #7
0
def generate_configuration_file(path):
    with open(path, 'w') as f:
        f.write(Config().get_config_text())