Add syntax checking of userdata YAML

This commit is contained in:
Joshua Boniface 2020-08-12 14:09:56 -04:00
parent 0d470ae5f6
commit 42f2dedf6d
1 changed files with 12 additions and 1 deletions

View File

@ -2759,9 +2759,14 @@ def provisioner_userdata_add(name, filename):
Add a new userdata document NAME from file FILENAME.
"""
# Open the XML file
# Open the YAML file
userdata = filename.read()
filename.close()
try:
yaml.load(userdata, Loader=yaml.FullLoader)
except Exception as e:
click.echo("Error: Userdata document is malformed")
cleanup(False, e)
params = dict()
params['name'] = name
@ -2833,6 +2838,12 @@ def provisioner_userdata_modify(name, filename, editor):
userdata = filename.read().strip()
filename.close()
try:
yaml.load(userdata, Loader=yaml.FullLoader)
except Exception as e:
click.echo("Error: Userdata document is malformed")
cleanup(False, e)
params = dict()
params['data'] = userdata