From 6e10af4a978ffbdf75ab10fbd65951a132468442 Mon Sep 17 00:00:00 2001 From: kevyang Date: Tue, 5 Mar 2024 17:14:06 -0500 Subject: [PATCH] jupyter extension - allow configuration via env var (#9615) Allow the Pachyderm Jupyter extension address and token to be configured via env var for compatibility with the Determined launcher. [INT-1149](https://pachyderm.atlassian.net/browse/INT-1149) [INT-1149]: https://pachyderm.atlassian.net/browse/INT-1149?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --------- Co-authored-by: Kevin Yang --- jupyter-extension/jupyterlab_pachyderm/env.py | 3 ++ .../jupyterlab_pachyderm/handlers.py | 29 ++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/jupyter-extension/jupyterlab_pachyderm/env.py b/jupyter-extension/jupyterlab_pachyderm/env.py index 446eb122f66..868762404af 100644 --- a/jupyter-extension/jupyterlab_pachyderm/env.py +++ b/jupyter-extension/jupyterlab_pachyderm/env.py @@ -8,6 +8,9 @@ os.path.expanduser(os.environ.get("PACH_CONFIG", CONFIG_PATH_LOCAL)) ).resolve() PFS_MOUNT_DIR = os.environ.get("PFS_MOUNT_DIR", "/pfs") +PACHD_ADDRESS = os.environ.get("PACHD_ADDRESS", None) +# If specified, this is the ID_TOKEN used in auth +DEX_TOKEN = os.environ.get("DEX_TOKEN", None) PACHYDERM_EXT_DEBUG = strtobool(os.environ.get("PACHYDERM_EXT_DEBUG", "False").lower()) if PACHYDERM_EXT_DEBUG: diff --git a/jupyter-extension/jupyterlab_pachyderm/handlers.py b/jupyter-extension/jupyterlab_pachyderm/handlers.py index 391ed621980..186fb3488bc 100644 --- a/jupyter-extension/jupyterlab_pachyderm/handlers.py +++ b/jupyter-extension/jupyterlab_pachyderm/handlers.py @@ -19,6 +19,7 @@ import tornado.concurrent import tornado.web +from .env import PACHD_ADDRESS, DEX_TOKEN from .log import get_logger from .pfs_manager import PFSManager, DatumManager from .pps_client import PPSClient @@ -648,16 +649,36 @@ def write_config( def setup_handlers(web_app, config_file: Path): + """ + Sets up the Pachyderm client and the HTTP request handler. + + Config for the Pachyderm client will first be attempted by reading + the local config file. This falls back to the PACHD_ADDRESS and + DEX_TOKEN env vars, and finally defaulting to a localhost client + on the default port 30650 failing that. + """ + client = None try: client = Client().from_config(config_file) get_logger().debug( f"Created Pachyderm client for {client.address} from local config" ) except FileNotFoundError: - get_logger().debug( - "Could not find config file -- no pachyderm client instantiated" - ) - else: + if PACHD_ADDRESS: + client = Client().from_pachd_address(pachd_address=PACHD_ADDRESS) + if DEX_TOKEN: + client.auth_token = client.auth.authenticate( + id_token=DEX_TOKEN + ).pach_token + get_logger().debug( + f"Created Pachyderm client for {client.address} from env var" + ) + else: + get_logger().debug( + "Could not find config file -- no pachyderm client instantiated" + ) + + if client: web_app.settings["pachyderm_client"] = client web_app.settings["pachyderm_pps_client"] = PPSClient(client=client) web_app.settings["pfs_contents_manager"] = PFSManager(client=client)