def certidude_serve(user, port, listen, enable_signature): logging.basicConfig( filename='/var/log/certidude.log', level=logging.DEBUG) click.echo("Serving API at %s:%d" % (listen, port)) import pwd from wsgiref.simple_server import make_server, WSGIServer from socketserver import ThreadingMixIn from certidude.api import certidude_app, StaticResource class ThreadingWSGIServer(ThreadingMixIn, WSGIServer): pass click.echo("Listening on %s:%d" % (listen, port)) app = certidude_app() app.add_sink(StaticResource(os.path.join(os.path.dirname(__file__), "static"))) httpd = make_server(listen, port, app, ThreadingWSGIServer) if user: # Load required utils which cannot be imported from chroot # TODO: Figure out better approach from jinja2.debug import make_traceback as _make_traceback "".encode("charmap") _, _, uid, gid, gecos, root, shell = pwd.getpwnam(user) if uid == 0: click.echo("Please specify unprivileged user") exit(254) click.echo("Switching to user %s (uid=%d, gid=%d)" % (user, uid, gid)) os.setgid(gid) os.setuid(uid) os.umask(0o007) elif os.getuid() == 0: click.echo("Warning: running as root, this is not recommended!") httpd.serve_forever()
def certidude_serve(user, port, listen, enable_signature): logging.basicConfig(filename='/var/log/certidude.log', level=logging.DEBUG) click.echo("Serving API at %s:%d" % (listen, port)) import pwd from wsgiref.simple_server import make_server, WSGIServer from socketserver import ThreadingMixIn from certidude.api import certidude_app, StaticResource class ThreadingWSGIServer(ThreadingMixIn, WSGIServer): pass click.echo("Listening on %s:%d" % (listen, port)) app = certidude_app() app.add_sink( StaticResource(os.path.join(os.path.dirname(__file__), "static"))) httpd = make_server(listen, port, app, ThreadingWSGIServer) if user: # Load required utils which cannot be imported from chroot # TODO: Figure out better approach from jinja2.debug import make_traceback as _make_traceback "".encode("charmap") _, _, uid, gid, gecos, root, shell = pwd.getpwnam(user) if uid == 0: click.echo("Please specify unprivileged user") exit(254) click.echo("Switching to user %s (uid=%d, gid=%d)" % (user, uid, gid)) os.setgid(gid) os.setuid(uid) os.umask(0o007) elif os.getuid() == 0: click.echo("Warning: running as root, this is not recommended!") httpd.serve_forever()
""" certidude.wsgi ~~~~~~~~~~~~~~ Certidude web app factory for WSGI-compatible web servers """ import os from certidude.api import certidude_app # TODO: set up /run/certidude/api paths and permissions assert os.getenv("PUSH_SUBSCRIBE"), "Please set PUSH_SUBSCRIBE to your web server's subscription URL" assert os.getenv("PUSH_PUBLISH"), "Please set PUSH_PUBLISH to your web server's publishing URL" app = certidude_app()
""" certidude.wsgi ~~~~~~~~~~~~~~ Certidude web app factory for WSGI-compatible web servers """ import os from certidude.api import certidude_app # TODO: set up /run/certidude/api paths and permissions assert os.getenv( "PUSH_SUBSCRIBE" ), "Please set PUSH_SUBSCRIBE to your web server's subscription URL" assert os.getenv( "PUSH_PUBLISH" ), "Please set PUSH_PUBLISH to your web server's publishing URL" app = certidude_app()