From 37ae95b3bfee33d6fd6c7c829199bb66769ea729 Mon Sep 17 00:00:00 2001 From: Jacob Callahan Date: Mon, 14 Oct 2024 16:20:44 -0400 Subject: [PATCH] Quick fix for https config sources 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. --- broker/config_manager.py | 2 +- broker/helpers.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/broker/config_manager.py b/broker/config_manager.py index fff3172..cbba8d3 100644 --- a/broker/config_manager.py +++ b/broker/config_manager.py @@ -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() diff --git a/broker/helpers.py b/broker/helpers.py index 77f2ddd..05e4e9e 100644 --- a/broker/helpers.py +++ b/broker/helpers.py @@ -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")