Skip to content

Commit

Permalink
Feat/add debug (#94)
Browse files Browse the repository at this point in the history
feat: add proxyfix, and debug logs to k8s auth
  • Loading branch information
jawadqur authored Jan 21, 2025
1 parent 4a4bc15 commit d041ae9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions wts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@
from .utils import get_config_var as get_var
from .version_data import VERSION, COMMIT

from werkzeug.middleware.proxy_fix import ProxyFix


app = Flask(__name__)
app.logger = get_logger(__name__, log_level="info")

# https://flask.palletsprojects.com/en/stable/deploying/proxy_fix/
app.wsgi_app = ProxyFix(app.wsgi_app)


def load_settings(app):
"""
Expand Down
12 changes: 12 additions & 0 deletions wts/auth_plugins/k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


def get_username_from_ip(ip):
flask.current_app.logger.debug("Getting username from IP {}".format(ip))
# Fail if we can't load kubernetes config...
try:
kubernetes.config.load_incluster_config()
Expand All @@ -24,14 +25,25 @@ def get_username_from_ip(ip):
pod.metadata.annotations
and POD_USERNAME_ANNOTATION in pod.metadata.annotations
):
flask.current_app.logger.debug(
"Found username {} for IP {}".format(
pod.metadata.annotations[POD_USERNAME_ANNOTATION], ip
)
)
return pod.metadata.annotations[POD_USERNAME_ANNOTATION]
elif (
pod.metadata.annotations
and JUPYTER_POD_ANNOTATION in pod.metadata.annotations
):
flask.current_app.logger.debug(
"Found username {} for IP {}".format(
pod.metadata.annotations[JUPYTER_POD_ANNOTATION], ip
)
)
return pod.metadata.annotations[JUPYTER_POD_ANNOTATION]

# No matching pod found
flask.current_app.logger.debug("No username found for IP {}".format(ip))
return None


Expand Down

0 comments on commit d041ae9

Please sign in to comment.