Skip to content

Commit cb6b6ea

Browse files
committed
feat(proxies): update priority:
1. QDT_PROXY_HTTP 2. System settings ---> pac or raw defined 3. HTTP_PROXY
1 parent 4f1087f commit cb6b6ea

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

qgis_deployment_toolbelt/utils/proxies.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def get_proxy_settings(url: str | None = None) -> dict:
3939
"""Retrieves network proxy settings from operating system configuration or
4040
environment variables.
4141
Args:
42-
url (str): url for request in case of PAC file use
42+
url (str, optional): url for request in case of PAC file use
4343
Returns:
4444
dict: proxy settings with protocl as key and URL as value
4545
"""
@@ -54,6 +54,23 @@ def get_proxy_settings(url: str | None = None) -> dict:
5454
"Proxies settings from custom QDT in environment vars (QDT_PROXY_HTTP): "
5555
f"{proxy_settings}"
5656
)
57+
elif qdt_pac_file := environ.get("QDT_PAC_FILE"):
58+
if pac := load_pac_file_from_environment_variable(qdt_pac_file=qdt_pac_file):
59+
proxy_settings = get_proxy_settings_from_pac_file(url=url, pac=pac)
60+
logger.info(
61+
f"Proxies settings from environment vars PAC file: {environ.get('QDT_PAC_FILE')}"
62+
f"{proxy_settings}"
63+
)
64+
else:
65+
logger.warning(
66+
f"Invalid PAC file from environment vars PAC file : {environ.get('QDT_PAC_FILE')}. No proxy use."
67+
)
68+
elif pac := get_pac():
69+
proxy_settings = get_proxy_settings_from_pac_file(url=url, pac=pac)
70+
logger.info("Proxies settings from system PAC file: " f"{proxy_settings}")
71+
elif getproxies():
72+
proxy_settings = getproxies()
73+
logger.debug(f"Proxies settings found in the OS: {proxy_settings}")
5774
elif environ.get("HTTP_PROXY") or environ.get("HTTPS_PROXY"):
5875
if environ.get("HTTP_PROXY") and environ.get("HTTPS_PROXY"):
5976
proxy_settings = {
@@ -80,23 +97,6 @@ def get_proxy_settings(url: str | None = None) -> dict:
8097
"Proxies settings from generic environment vars (HTTPS_PROXY only): "
8198
f"{proxy_settings}"
8299
)
83-
elif qdt_pac_file := environ.get("QDT_PAC_FILE"):
84-
if pac := load_pac_file_from_environment_variable(qdt_pac_file=qdt_pac_file):
85-
proxy_settings = get_proxy_settings_from_pac_file(url=url, pac=pac)
86-
logger.info(
87-
f"Proxies settings from environment vars PAC file: {environ.get('QDT_PAC_FILE')}"
88-
f"{proxy_settings}"
89-
)
90-
else:
91-
logger.warning(
92-
f"Invalid PAC file from environment vars PAC file : {environ.get('QDT_PAC_FILE')}. No proxy use."
93-
)
94-
elif getproxies():
95-
proxy_settings = getproxies()
96-
logger.debug(f"Proxies settings found in the OS: {proxy_settings}")
97-
elif pac := get_pac():
98-
proxy_settings = get_proxy_settings_from_pac_file(url=url, pac=pac)
99-
logger.info("Proxies settings from system PAC file: " f"{proxy_settings}")
100100
else:
101101
logger.debug(
102102
"No proxy settings found in environment vars nor OS settings nor PAC File."

0 commit comments

Comments
 (0)