parent
7e61cc33e5
commit
99de3e2ebd
3 changed files with 35 additions and 14 deletions
|
|
@ -21,5 +21,5 @@ FROM registry.cern.ch/docker.io/library/debian
|
||||||
|
|
||||||
COPY --from=conda /opt/app /opt/app
|
COPY --from=conda /opt/app /opt/app
|
||||||
CMD [ \
|
CMD [ \
|
||||||
"/opt/app/bin/python", "-m", "auth_service" \
|
"/opt/app/bin/python", "-m", "auth_service", "--no-debug" \
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -10,15 +10,14 @@ import typing
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from keycloak.aio.realm import KeycloakRealm
|
from keycloak.aio.realm import KeycloakRealm
|
||||||
import tornado.ioloop
|
from tornado.web import Application, RequestHandler
|
||||||
import tornado.log
|
import tornado.log
|
||||||
import tornado.web
|
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class BaseHandler(tornado.web.RequestHandler):
|
class BaseHandler(RequestHandler):
|
||||||
def set_session_cookie(self, session_data: dict, expiry_in_seconds: int) -> None:
|
def set_session_cookie(self, session_data: dict, expiry_in_seconds: int) -> None:
|
||||||
seconds_per_day = 60 * 60 * 24
|
seconds_per_day = 60 * 60 * 24
|
||||||
self.set_secure_cookie(
|
self.set_secure_cookie(
|
||||||
|
|
@ -152,18 +151,19 @@ class MainHandler(BaseHandler):
|
||||||
session = self.get_session_cookie()
|
session = self.get_session_cookie()
|
||||||
if session is None:
|
if session is None:
|
||||||
return self.finish("""
|
return self.finish("""
|
||||||
You are currently not logged in: <a href="/auth/login">Login</a>
|
You are currently not logged in: <a href="/auth/login">Login</a>
|
||||||
""")
|
""")
|
||||||
else:
|
else:
|
||||||
return self.finish(f"""
|
return self.finish(f"""
|
||||||
You are currently logged in as "{session['username']}":
|
You are currently logged in as "{session['username']}":
|
||||||
<a href="/auth/logout">Logout</a>
|
<a href="/auth/logout">Logout</a>
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
|
||||||
def make_app():
|
def make_app(debug: bool = False) -> Application:
|
||||||
tornado.log.enable_pretty_logging()
|
if debug:
|
||||||
return tornado.web.Application(
|
tornado.log.enable_pretty_logging()
|
||||||
|
return Application(
|
||||||
[
|
[
|
||||||
(r"/", MainHandler),
|
(r"/", MainHandler),
|
||||||
(r"/auth/probe", ProbeAuthentication),
|
(r"/auth/probe", ProbeAuthentication),
|
||||||
|
|
@ -174,7 +174,7 @@ def make_app():
|
||||||
(r'/auth/logout', Logout),
|
(r'/auth/logout', Logout),
|
||||||
],
|
],
|
||||||
cookie_secret=os.environ['COOKIE_SECRET'],
|
cookie_secret=os.environ['COOKIE_SECRET'],
|
||||||
debug=True,
|
debug=debug,
|
||||||
oicd_server=os.environ['OIDC_SERVER'],
|
oicd_server=os.environ['OIDC_SERVER'],
|
||||||
oicd_realm=os.environ['OIDC_REALM'],
|
oicd_realm=os.environ['OIDC_REALM'],
|
||||||
client_id=os.environ['CLIENT_ID'],
|
client_id=os.environ['CLIENT_ID'],
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,30 @@
|
||||||
import tornado.ioloop
|
import argparse
|
||||||
|
|
||||||
|
from tornado.ioloop import IOLoop
|
||||||
|
|
||||||
from . import make_app
|
from . import make_app
|
||||||
|
|
||||||
|
|
||||||
|
def configure_parser(parser) -> argparse.ArgumentParser:
|
||||||
|
parser.add_argument(
|
||||||
|
"--no-debug", help="Don't enable debug mode",
|
||||||
|
action="store_false",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--port",
|
||||||
|
help="The port to listen on",
|
||||||
|
default="8080"
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = configure_parser(argparse.ArgumentParser())
|
||||||
|
args = parser.parse_args()
|
||||||
|
app = make_app(debug=args.no_debug)
|
||||||
|
app.listen(args.port)
|
||||||
|
IOLoop.instance().start()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = make_app()
|
main()
|
||||||
app.listen(8080)
|
|
||||||
tornado.ioloop.IOLoop.current().start()
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue