Skip to content

Commit

Permalink
chore(code): encode proxy username and password
Browse files Browse the repository at this point in the history
  • Loading branch information
rmoolya-crest committed Nov 21, 2022
1 parent 655c6a0 commit f4d7497
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cloudconnectlib/core/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from cloudconnectlib.core import defaults
from cloudconnectlib.core.exceptions import HTTPError

import urllib.parse

_logger = get_cc_logger()


Expand Down Expand Up @@ -116,6 +118,7 @@ def get_proxy_info(proxy_config: dict) -> dict:
"proxy_rdns": 0 or 1,
}
"""

proxy_info = {}

if not proxy_config or not is_true(proxy_config.get("proxy_enabled")):
Expand Down Expand Up @@ -144,7 +147,11 @@ def get_proxy_info(proxy_config: dict) -> dict:
password = proxy_config.get("proxy_password")

if all((user, password)):
proxy_info["http"] = f"{proxy_type}://{user}:{password}@{url}:{int(port)}"
encoded_user = urllib.parse.quote(user)
encoded_password = urllib.parse.quote(password)
proxy_info[
"http"
] = f"{proxy_type}://{encoded_user}:{encoded_password}@{url}:{int(port)}"
else:
_logger.info("Proxy has no credentials found")

Expand Down Expand Up @@ -263,7 +270,7 @@ def _retry_send_request_if_needed(self, uri, method="GET", headers=None, body=No
status = resp.status_code

if self._is_need_retry(status, i, retries):
delay = 2**i
delay = 2 ** i
_logger.warning(
"The response status=%s of request which url=%s and"
" method=%s. Retry after %s seconds.",
Expand Down

0 comments on commit f4d7497

Please sign in to comment.