Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions pathwaysutils/experimental/shared_pathways_service/isc_pathways.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Module for connecting to a Pathways server for interactive supercomputing."""

from collections.abc import Iterator, Mapping
from collections.abc import Iterable, Iterator, Mapping
import contextlib
import dataclasses
import gc
Expand Down Expand Up @@ -48,12 +48,14 @@ class ProxyOptions:
use_insecure_credentials: bool = False

@classmethod
def from_dict(cls, options: Mapping[str, str] | None) -> "ProxyOptions":
"""Creates a ProxyOptions object from a dictionary of options."""
options = options or {}
use_insecure = (
options.get("use_insecure_credentials", "false").lower() == "true"
)
def from_list(cls, options: Iterable[str] | None) -> "ProxyOptions":
"""Creates a ProxyOptions object from a list of 'key:value' strings."""
use_insecure = False
for option in options or []:
if ":" in option:
key, value = option.split(":", 1)
if key.strip().lower() == "use_insecure_credentials":
use_insecure = value.strip().lower() == "true"
return cls(use_insecure_credentials=use_insecure)


Expand Down Expand Up @@ -96,10 +98,12 @@ def _deploy_pathways_proxy_server(

proxy_options = proxy_options or ProxyOptions()

proxy_env_str = (
' - name: IFRT_PROXY_USE_INSECURE_GRPC_CREDENTIALS\n'
' value: "true"\n'
) if proxy_options.use_insecure_credentials else ""
proxy_env_str = ""
if proxy_options.use_insecure_credentials:
proxy_env_str = (
' - name: IFRT_PROXY_USE_INSECURE_GRPC_CREDENTIALS\n'
' value: "true"\n'
)

template = string.Template(yaml_template)
substituted_yaml = template.substitute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
from pathwaysutils.experimental.shared_pathways_service import isc_pathways


from google3.pyglib.flags.contrib import dict_flag

FLAGS = flags.FLAGS

flags.DEFINE_string("cluster", None, "The name of the GKE cluster.")
Expand All @@ -37,7 +35,7 @@
None,
"The proxy server image to use. If not provided, a default will be used.",
)
dict_flag.DEFINE_dict(
flags.DEFINE_list(
"proxy_options",
None,
"Configuration options for the Pathways proxy. Specify entries in the form"
Expand All @@ -57,7 +55,7 @@ def main(argv: Sequence[str]) -> None:
if len(argv) > 1:
raise app.UsageError("Too many command-line arguments.")

proxy_options = isc_pathways.ProxyOptions.from_dict(FLAGS.proxy_options)
proxy_options = isc_pathways.ProxyOptions.from_list(FLAGS.proxy_options)

with isc_pathways.connect(
cluster=FLAGS.cluster,
Expand Down
Loading