Skip to content

Commit

Permalink
Quick fix for https config sources
Browse files Browse the repository at this point in the history
this change disables certificate validation checks when attempting to
download a config file from an https source.

also added a quick fix for yaml structure output.
  • Loading branch information
JacobCallahan committed Oct 14, 2024
1 parent b8f46f1 commit 37ae95b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion broker/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _import_config(self, source, is_url=False):
import requests

click.echo(f"Downloading example file from: {source}")
return requests.get(source, timeout=60).text
return requests.get(source, timeout=60, verify=False).text
else:
return source.read_text()

Expand Down
12 changes: 10 additions & 2 deletions broker/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,23 @@ def update_inventory(add=None, remove=None):
yaml.dump(inv_data, settings.inventory_path)


def yaml_format(in_struct):
def yaml_format(in_struct, force_yaml_dict=False):
"""Convert a yaml-compatible structure to a yaml dumped string.
:param in_struct: yaml-compatible structure or string containing structure
:param force_yaml_dict: force the in_struct to be converted to a dictionary before dumping
:return: yaml-formatted string
"""
if isinstance(in_struct, str):
in_struct = yaml.load(in_struct)
# first try to load is as json
try:
in_struct = json.loads(in_struct)
except json.JSONDecodeError:
# then try yaml
in_struct = yaml.load(in_struct)
if force_yaml_dict:
in_struct = dict(in_struct)
output = BytesIO() # ruamel doesn't natively allow for string output
yaml.dump(in_struct, output)
return output.getvalue().decode("utf-8")
Expand Down

0 comments on commit 37ae95b

Please sign in to comment.