예제 #1
0
def main():
    if os.getuid() != 0:
        raise RuntimeError("need to be root, sorry about that")

    known_env_vars = (
        "MESHPING_REDIS_HOST",
        "MESHPING_PING_TIMEOUT",
        "MESHPING_PING_INTERVAL",
        "MESHPING_PEERS",
        "MESHPING_PROMETHEUS_URL",
        "MESHPING_PROMETHEUS_QUERY",
    )

    for key in os.environ.keys():
        if key.startswith("MESHPING_") and key not in known_env_vars:
            print("env var %s is unknown" % key, file=sys.stderr)
            sys.exit(1)

    app = QuartTrio(__name__, static_url_path="")
    app.config["TEMPLATES_AUTO_RELOAD"] = True
    app.secret_key = str(uuid4())
    app.debug = False

    redis = StrictRedis(
        host=os.environ.get("MESHPING_REDIS_HOST", "127.0.0.1"))
    mp = MeshPing(redis, int(os.environ.get("MESHPING_PING_TIMEOUT", 5)),
                  int(os.environ.get("MESHPING_PING_INTERVAL", 30)))

    add_api_views(app, mp)

    @app.before_serving
    async def startup():
        app.nursery.start_soon(mp.run)
        app.nursery.start_soon(run_peers, mp)

    app.run(host="::", port=9922)
예제 #2
0
from .utils import run_sync

logger = logging.getLogger(__name__)

serializer = URLSafeTimedSerializer(SIGNING_SECRET)

TOKEN_MAX_AGE = 1800 if not DEVELOPMENT else 3600000

app = QuartTrio(__name__)

# HACK: these three are set by Orisa in orisa.py.
send_ch = None
client = None
orisa = None

app.debug = DEVELOPMENT


async def render_message(message, is_error=False):
    return await render_template(
        "message.html",
        message=message,
        close_msg=_("You can close this window."),
        classes="bg-danger text-white"
        if is_error else "bg-success text-white",
    )


def create_token(guild_id):
    return serializer.dumps({"g": guild_id})