Skip to content

Commit

Permalink
Interpolation helper method cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdlaird committed Nov 6, 2024
1 parent 534a442 commit 8fd1cdd
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions pyngrok/ngrok.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ def _apply_edge_to_tunnel(tunnel: NgrokTunnel,
tunnel.proto = edges_prefix


def _interpolate_tunnel_definition(addr: Optional[str] = None,
def _interpolate_tunnel_definition(pyngrok_config: PyngrokConfig,
options: Dict[str, Any],
addr: Optional[str] = None,
proto: Optional[Union[str, int]] = None,
name: Optional[str] = None,
pyngrok_config: Optional[PyngrokConfig] = None,
**options: Any):
name: Optional[str] = None) -> None:
config_path = conf.get_config_path(pyngrok_config)

if os.path.exists(config_path):
Expand Down Expand Up @@ -232,11 +232,11 @@ def _interpolate_tunnel_definition(addr: Optional[str] = None,
else:
name = f"{proto}-file-{uuid.uuid4()}"

config = {
options.update({
"name": name,
"addr": addr
}
options.update(config)
"addr": addr,
"proto": proto
})


def connect(addr: Optional[str] = None,
Expand Down Expand Up @@ -291,13 +291,16 @@ def connect(addr: Optional[str] = None,
if pyngrok_config is None:
pyngrok_config = conf.get_default()

_interpolate_tunnel_definition(addr, proto, name, pyngrok_config, **options)
_interpolate_tunnel_definition(pyngrok_config, options, addr, proto, name)

proto = options.get("proto")
name = options.get("name")

logger.info(f"Opening tunnel named: {name}")

# Only apply proto when "labels" is not defined
if "labels" not in options:
options["proto"] = proto
# Remove proto when "labels" is defined
if "labels" in options:
options.pop("proto")

# Upgrade legacy parameters, if present
if pyngrok_config.ngrok_version == "v3":
Expand Down

0 comments on commit 8fd1cdd

Please sign in to comment.