Skip to content

Commit 6b98dd6

Browse files
guptaakacopybara-github
authored andcommitted
Fix --proxy_options to use flags.DEFINE_list
PiperOrigin-RevId: 876395837
1 parent 3fd6095 commit 6b98dd6

2 files changed

Lines changed: 17 additions & 15 deletions

File tree

pathwaysutils/experimental/shared_pathways_service/isc_pathways.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Module for connecting to a Pathways server for interactive supercomputing."""
22

3-
from collections.abc import Iterator, Mapping
3+
from collections.abc import Iterable, Iterator, Mapping
44
import contextlib
55
import dataclasses
66
import gc
@@ -48,12 +48,14 @@ class ProxyOptions:
4848
use_insecure_credentials: bool = False
4949

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

5961

@@ -96,10 +98,12 @@ def _deploy_pathways_proxy_server(
9698

9799
proxy_options = proxy_options or ProxyOptions()
98100

99-
proxy_env_str = (
100-
' - name: IFRT_PROXY_USE_INSECURE_GRPC_CREDENTIALS\n'
101-
' value: "true"\n'
102-
) if proxy_options.use_insecure_credentials else ""
101+
proxy_env_str = ""
102+
if proxy_options.use_insecure_credentials:
103+
proxy_env_str = (
104+
' - name: IFRT_PROXY_USE_INSECURE_GRPC_CREDENTIALS\n'
105+
' value: "true"\n'
106+
)
103107

104108
template = string.Template(yaml_template)
105109
substituted_yaml = template.substitute(

pathwaysutils/experimental/shared_pathways_service/run_connect_example.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
from pathwaysutils.experimental.shared_pathways_service import isc_pathways
1010

1111

12-
from google3.pyglib.flags.contrib import dict_flag
13-
1412
FLAGS = flags.FLAGS
1513

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

60-
proxy_options = isc_pathways.ProxyOptions.from_dict(FLAGS.proxy_options)
58+
proxy_options = isc_pathways.ProxyOptions.from_list(FLAGS.proxy_options)
6159

6260
with isc_pathways.connect(
6361
cluster=FLAGS.cluster,

0 commit comments

Comments
 (0)