From 7e252d37fce37d815cf6ab71a74a4c570e0dff06 Mon Sep 17 00:00:00 2001 From: telcobot <147593099+telcobot@users.noreply.github.com> Date: Thu, 7 Mar 2024 01:34:17 -0500 Subject: [PATCH] chore: Update charm libraries (#80) --- lib/charms/loki_k8s/v1/loki_push_api.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/charms/loki_k8s/v1/loki_push_api.py b/lib/charms/loki_k8s/v1/loki_push_api.py index a83b1ae..6c8549c 100644 --- a/lib/charms/loki_k8s/v1/loki_push_api.py +++ b/lib/charms/loki_k8s/v1/loki_push_api.py @@ -518,7 +518,7 @@ def _alert_rules_error(self, event): # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 4 +LIBPATCH = 5 logger = logging.getLogger(__name__) @@ -2094,15 +2094,18 @@ def _download_and_push_promtail_to_workload( container: container into which promtail is to be uploaded. """ # Check for Juju proxy variables and fall back to standard ones if not set - proxies: Optional[Dict[str, str]] = {} - if proxies and os.environ.get("JUJU_CHARM_HTTP_PROXY"): - proxies.update({"http": os.environ["JUJU_CHARM_HTTP_PROXY"]}) - if proxies and os.environ.get("JUJU_CHARM_HTTPS_PROXY"): - proxies.update({"https": os.environ["JUJU_CHARM_HTTPS_PROXY"]}) - if proxies and os.environ.get("JUJU_CHARM_NO_PROXY"): - proxies.update({"no_proxy": os.environ["JUJU_CHARM_NO_PROXY"]}) - else: - proxies = None + # If no Juju proxy variable was set, we set proxies to None to let the ProxyHandler get + # the proxy env variables from the environment + proxies = { + # The ProxyHandler uses only the protocol names as keys + # https://docs.python.org/3/library/urllib.request.html#urllib.request.ProxyHandler + "https": os.environ.get("JUJU_CHARM_HTTPS_PROXY", ""), + "http": os.environ.get("JUJU_CHARM_HTTP_PROXY", ""), + # The ProxyHandler uses `no` for the no_proxy key + # https://github.com/python/cpython/blob/3.12/Lib/urllib/request.py#L2553 + "no": os.environ.get("JUJU_CHARM_NO_PROXY", ""), + } + proxies = {k: v for k, v in proxies.items() if v != ""} or None proxy_handler = request.ProxyHandler(proxies) opener = request.build_opener(proxy_handler)