Skip to content

Commit

Permalink
jupyter extension - allow configuration via env var (#9615)
Browse files Browse the repository at this point in the history
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 <kevin.yang@hpe.com>
  • Loading branch information
kevyang and Kevin Yang committed Mar 5, 2024
1 parent 60f1ec0 commit 6e10af4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
3 changes: 3 additions & 0 deletions jupyter-extension/jupyterlab_pachyderm/env.py
Expand Up @@ -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:
Expand Down
29 changes: 25 additions & 4 deletions jupyter-extension/jupyterlab_pachyderm/handlers.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6e10af4

Please sign in to comment.