From 781097daaef25ba6869b7c7d0fa7464adef17ff3 Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Sep 25 2019 13:47:09 +0000 Subject: Merge branch 'safe-yaml-load' into 'production' Load YAML data safely in several Python scripts See merge request infra/salt!262 --- diff --git a/bin/get_formulas.py b/bin/get_formulas.py index 63ddc2f..affe16f 100755 --- a/bin/get_formulas.py +++ b/bin/get_formulas.py @@ -150,7 +150,7 @@ def checkout_remote_and_branch(REMOTE_BRANCH, DEST): with open('pillar/FORMULAS.yaml', 'r') as f: - FORMULAS_YAML = yaml.load(f) + FORMULAS_YAML = yaml.safe_load(f) FORMULAS = copy(FORMULAS_YAML) diff --git a/bin/get_roles.py b/bin/get_roles.py index 76dac05..1ae6a18 100755 --- a/bin/get_roles.py +++ b/bin/get_roles.py @@ -23,7 +23,7 @@ def read_file_skip_jinja(filename): def get_roles_of_one_minion(minion): content = read_file_skip_jinja("pillar/id/%s" % minion) try: - roles = yaml.load(content)['grains']['roles'] + roles = yaml.safe_load(content)['grains']['roles'] except KeyError: roles = [] diff --git a/bin/get_valid_custom_grains.py b/bin/get_valid_custom_grains.py index 4766df5..70e2ac1 100755 --- a/bin/get_valid_custom_grains.py +++ b/bin/get_valid_custom_grains.py @@ -8,7 +8,7 @@ import yaml def get_valid_custom_grains(): with open('pillar/valid_custom_grains.yaml', 'r') as f: - VALID_CUSTOM_GRAINS = yaml.load(f) + VALID_CUSTOM_GRAINS = yaml.safe_load(f) return VALID_CUSTOM_GRAINS diff --git a/bin/test_custom_grains.py b/bin/test_custom_grains.py index 40e705a..23a2607 100755 --- a/bin/test_custom_grains.py +++ b/bin/test_custom_grains.py @@ -46,7 +46,7 @@ all_valid_localized_grains = get_all_valid_localized_grains() all_ids = sorted(os.listdir('pillar/id')) for sls in all_ids: content = read_file_skip_jinja("pillar/id/%s" % sls) - mygrains = yaml.load(content)['grains'] + mygrains = yaml.safe_load(content)['grains'] for key, valid_values in valid_global_grains.items(): status = test_custom_grain(mygrains, sls, key, valid_values, status)