Skip to content

Commit 9222be5

Browse files
committed
Clean up typing for proxy config
1 parent 41dfe7c commit 9222be5

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

infrahub_sdk/client.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import logging
66
import time
77
import warnings
8-
from collections.abc import Coroutine, MutableMapping
8+
from collections.abc import Coroutine, Mapping, MutableMapping
99
from functools import wraps
1010
from time import sleep
1111
from typing import (
@@ -61,6 +61,9 @@
6161
if TYPE_CHECKING:
6262
from types import TracebackType
6363

64+
from httpx._transports.base import AsyncBaseTransport, BaseTransport
65+
from httpx._types import ProxyTypes
66+
6467
from .context import RequestContext
6568

6669

@@ -73,6 +76,16 @@ class ProcessRelationsNode(TypedDict):
7376
related_nodes: list[InfrahubNode]
7477

7578

79+
class ProxyConfig(TypedDict):
80+
proxy: ProxyTypes | None
81+
mounts: Mapping[str, AsyncBaseTransport | None] | None
82+
83+
84+
class ProxyConfigSync(TypedDict):
85+
proxy: ProxyTypes | None
86+
mounts: Mapping[str, BaseTransport | None] | None
87+
88+
7689
class ProcessRelationsNodeSync(TypedDict):
7790
nodes: list[InfrahubNodeSync]
7891
related_nodes: list[InfrahubNodeSync]
@@ -1026,17 +1039,17 @@ async def _default_request_method(
10261039
if payload:
10271040
params["json"] = payload
10281041

1029-
proxy_config: dict[str, str | dict[str, httpx.HTTPTransport]] = {}
1042+
proxy_config: ProxyConfig = {"proxy": None, "mounts": None}
10301043
if self.config.proxy:
10311044
proxy_config["proxy"] = self.config.proxy
10321045
elif self.config.proxy_mounts.is_set:
10331046
proxy_config["mounts"] = {
1034-
key: httpx.HTTPTransport(proxy=value)
1047+
key: httpx.AsyncHTTPTransport(proxy=value)
10351048
for key, value in self.config.proxy_mounts.model_dump(by_alias=True).items()
10361049
}
10371050

10381051
async with httpx.AsyncClient(
1039-
**proxy_config, # type: ignore[arg-type]
1052+
**proxy_config,
10401053
verify=self.config.tls_ca_file if self.config.tls_ca_file else not self.config.tls_insecure,
10411054
) as client:
10421055
try:
@@ -2688,7 +2701,8 @@ def _default_request_method(
26882701
if payload:
26892702
params["json"] = payload
26902703

2691-
proxy_config: dict[str, str | dict[str, httpx.HTTPTransport]] = {}
2704+
proxy_config: ProxyConfigSync = {"proxy": None, "mounts": None}
2705+
26922706
if self.config.proxy:
26932707
proxy_config["proxy"] = self.config.proxy
26942708
elif self.config.proxy_mounts.is_set:
@@ -2698,7 +2712,7 @@ def _default_request_method(
26982712
}
26992713

27002714
with httpx.Client(
2701-
**proxy_config, # type: ignore[arg-type]
2715+
**proxy_config,
27022716
verify=self.config.tls_ca_file if self.config.tls_ca_file else not self.config.tls_insecure,
27032717
) as client:
27042718
try:

0 commit comments

Comments
 (0)