コード例 #1
0
def main():
    args = sys.argv
    dry_run = False
    while len(args) > 1:
        arg = args.pop()
        if arg == "--dry-run":
            dry_run = True
        else:
            print(
                f"Unknown option: {arg}\nUsage: python3 -m flagger [--dry-run]"
            )
            exit(1)
    if dry_run:
        print("Dry run: not making any actual changes")
    with session_handler() as session:
        domains = queries.find_domains(session)
    print(f"{len(domains)} domain(s) found")
    for domain in domains:
        aws.create_semaphore(domain, dry_run)
    with session_handler() as session:
        domain_cdns = queries.find_cdn_aliases(session)
    for domain_cdn in domain_cdns:
        aws.create_cdn_alias(*domain_cdn, dry_run)
    with session_handler() as session:
        domain_albs = queries.find_domain_aliases(session)
    for domain_alb in domain_albs:
        aws.create_domain_alias(*domain_alb, dry_run)
コード例 #2
0
def clean_db():
    with session_handler() as session:
        session.execute("TRUNCATE TABLE user_data CASCADE", bind=cdn_engine)
        session.execute("TRUNCATE TABLE routes CASCADE", bind=cdn_engine)
        session.execute("TRUNCATE TABLE certificates CASCADE", bind=cdn_engine)
        session.execute("TRUNCATE TABLE user_data CASCADE", bind=domain_engine)
        session.execute("TRUNCATE TABLE routes CASCADE", bind=domain_engine)
        session.execute("TRUNCATE TABLE certificates CASCADE",
                        bind=domain_engine)
        session.execute("TRUNCATE TABLE alb_proxies CASCADE",
                        bind=domain_engine)
        session.commit()
        session.close()
        yield session
        session.execute("TRUNCATE TABLE user_data CASCADE", bind=cdn_engine)
        session.execute("TRUNCATE TABLE routes CASCADE", bind=cdn_engine)
        session.execute("TRUNCATE TABLE certificates CASCADE", bind=cdn_engine)
        session.execute("TRUNCATE TABLE user_data CASCADE", bind=domain_engine)
        session.execute("TRUNCATE TABLE routes CASCADE", bind=domain_engine)
        session.execute("TRUNCATE TABLE certificates CASCADE",
                        bind=domain_engine)
        session.execute("TRUNCATE TABLE alb_proxies CASCADE",
                        bind=domain_engine)
        session.commit()
        session.close()
コード例 #3
0
def main():
    logging.basicConfig(level=logging.DEBUG)
    args = parse_args(sys.argv[1:])
    check_connections()
    if args.cron:
        schedule.every().tuesday.at(config.MIGRATION_TIME).do(run_and_report)
        schedule.every().wednesday.at(config.MIGRATION_TIME).do(run_and_report)
        schedule.every().thursday.at(config.MIGRATION_TIME).do(run_and_report)
        while True:
            time.sleep(1)
            schedule.run_pending()
    elif args.instance:
        with session_handler() as session:
            migrate_single_instance(
                args.instance, session, get_cf_client(config), skip_dns_check=args.force
            )
コード例 #4
0
def test_can_create_route():
    # the assertion here is really just that no exceptions are raised

    # note that we shouldn't _actually_ be creating routes in this project
    # but this is a test we can do with an empty database
    with db.session_handler() as session:
        route = models.CdnRoute()
        route.id = 12345
        route.instance_id = "disposable-route-id"
        route.state = "deprovisioned"
        session.add(route)
        session.commit()

        route = session.query(models.CdnRoute).filter_by(id=12345).first()
        session.delete(route)
        session.commit()
        session.close()
コード例 #5
0
def test_can_create_route():
    # the assertion here is really just that no exceptions are raised

    # note that we shouldn't _actually_ be creating routes in this project
    # but this is a test we can do with an empty database
    with db.session_handler() as session:
        route = models.DomainRoute()
        route.instance_id = "12345"
        route.state = "deprovisioned"
        route.domains = ["example1.com", "example2.com", "example3.com"]

        session.add(route)
        session.commit()

        route = session.query(
            models.DomainRoute).filter_by(instance_id="12345").first()
        session.delete(route)
        session.commit()
        session.close()
コード例 #6
0
def run_and_report():
    with session_handler() as session:
        results = migrate_ready_instances(session, get_cf_client(config))
    send_report_email(results)
コード例 #7
0
def test_can_get_session():
    with db.session_handler() as session:
        result = session.execute("SELECT count(1) FROM certificates",
                                 bind=db.domain_engine)
        assert result.first() == (0, )