Skip to content
Merged
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: 20 additions & 6 deletions infrahub_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import time
import warnings
from collections.abc import Coroutine, MutableMapping
from collections.abc import Coroutine, Mapping, MutableMapping
from functools import wraps
from time import sleep
from typing import (
Expand Down Expand Up @@ -61,6 +61,9 @@
if TYPE_CHECKING:
from types import TracebackType

from httpx._transports.base import AsyncBaseTransport, BaseTransport
from httpx._types import ProxyTypes

from .context import RequestContext


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


class ProxyConfig(TypedDict):
proxy: ProxyTypes | None
mounts: Mapping[str, AsyncBaseTransport | None] | None


class ProxyConfigSync(TypedDict):
proxy: ProxyTypes | None
mounts: Mapping[str, BaseTransport | None] | None


class ProcessRelationsNodeSync(TypedDict):
nodes: list[InfrahubNodeSync]
related_nodes: list[InfrahubNodeSync]
Expand Down Expand Up @@ -1026,17 +1039,17 @@ async def _default_request_method(
if payload:
params["json"] = payload

proxy_config: dict[str, str | dict[str, httpx.HTTPTransport]] = {}
proxy_config: ProxyConfig = {"proxy": None, "mounts": None}
if self.config.proxy:
proxy_config["proxy"] = self.config.proxy
elif self.config.proxy_mounts.is_set:
proxy_config["mounts"] = {
key: httpx.HTTPTransport(proxy=value)
key: httpx.AsyncHTTPTransport(proxy=value)
for key, value in self.config.proxy_mounts.model_dump(by_alias=True).items()
}

async with httpx.AsyncClient(
**proxy_config, # type: ignore[arg-type]
**proxy_config,
verify=self.config.tls_ca_file if self.config.tls_ca_file else not self.config.tls_insecure,
) as client:
try:
Expand Down Expand Up @@ -2688,7 +2701,8 @@ def _default_request_method(
if payload:
params["json"] = payload

proxy_config: dict[str, str | dict[str, httpx.HTTPTransport]] = {}
proxy_config: ProxyConfigSync = {"proxy": None, "mounts": None}

if self.config.proxy:
proxy_config["proxy"] = self.config.proxy
elif self.config.proxy_mounts.is_set:
Expand All @@ -2698,7 +2712,7 @@ def _default_request_method(
}

with httpx.Client(
**proxy_config, # type: ignore[arg-type]
**proxy_config,
verify=self.config.tls_ca_file if self.config.tls_ca_file else not self.config.tls_insecure,
) as client:
try:
Expand Down