switch to explicit kwargs for headers and auth that are passed through to utils.http:query

This commit is contained in:
MKLeb 2022-10-05 12:25:48 -04:00 committed by Gareth J. Greenaway
parent 39ee1d396c
commit fa2855abfe
2 changed files with 35 additions and 14 deletions

View file

@ -57,7 +57,14 @@ def __virtual__():
def ext_pillar(
minion_id, pillar, url, with_grains=False, **kwargs
minion_id,
pillar,
url,
with_grains=False,
header_dict=None,
auth=None,
username=None,
password=None,
): # pylint: disable=W0613
"""
Read pillar data from HTTP response.
@ -65,18 +72,13 @@ def ext_pillar(
:param str url: Url to request.
:param bool with_grains: Whether to substitute strings in the url with their grain values.
:param dict header_dict: Extra headers to send
:param auth: special auth if needed
:param str username: username for auth
:param str pasword: password for auth
:param auth: special auth if needed
:return: A dictionary of the pillar data to add.
:rtype: dict
"""
# As we are dealing with kwargs, clean args that are hardcoded in this function
for arg in ["url", "decode", "decode_type"]:
if arg in kwargs:
del kwargs[arg]
url = url.replace("%s", urllib.parse.quote(minion_id))
grain_pattern = r"<(?P<grain_name>.*?)>"
@ -96,7 +98,15 @@ def ext_pillar(
url = re.sub("<{}>".format(grain_name), grain_value, url)
log.debug("Getting url: %s", url)
data = __salt__["http.query"](url=url, decode=True, decode_type="json", **kwargs)
data = __salt__["http.query"](
url=url,
decode=True,
decode_type="json",
header_dict=header_dict,
auth=auth,
username=username,
password=password,
)
if "dict" in data:
return data["dict"]

View file

@ -55,7 +55,14 @@ def __virtual__():
def ext_pillar(
minion_id, pillar, url, with_grains=False, **kwargs
minion_id,
pillar,
url,
with_grains=False,
header_dict=None,
auth=None,
username=None,
password=None,
): # pylint: disable=W0613
"""
Read pillar data from HTTP response.
@ -71,10 +78,6 @@ def ext_pillar(
:rtype: dict
"""
# As we are dealing with kwargs, clean args that are hardcoded in this function
for arg in ["url", "decode", "decode_type"]:
if arg in kwargs:
del kwargs[arg]
url = url.replace("%s", urllib.parse.quote(minion_id))
grain_pattern = r"<(?P<grain_name>.*?)>"
@ -94,7 +97,15 @@ def ext_pillar(
url = re.sub("<{}>".format(grain_name), grain_value, url)
log.debug("Getting url: %s", url)
data = __salt__["http.query"](url=url, decode=True, decode_type="yaml", **kwargs)
data = __salt__["http.query"](
url=url,
decode=True,
decode_type="yaml",
header_dict=header_dict,
auth=auth,
username=username,
password=password,
)
if "dict" in data:
return data["dict"]