[Validator Run] Don't rely on parameter file extension

This patch safely loads extra vars file using YAML method by default and
don't rely anymore on a probable existence of a file extension.

Change-Id: Ia09ca1de9502cd6c99910a6f18ee775c613c10dc
Signed-off-by: Gael Chamoulaud (Strider) <gchamoul@redhat.com>
(cherry picked from commit cd0e24bbe3)
(cherry picked from commit 6005878b4f)
This commit is contained in:
Gael Chamoulaud (Strider) 2020-10-19 11:27:51 +02:00 committed by mbu
parent b3d1b96565
commit 88c1231e4d
1 changed files with 8 additions and 5 deletions

View File

@ -346,11 +346,14 @@ class TripleOValidatorRun(command.Command):
limit = parsed_args.limit
extra_vars = parsed_args.extra_vars
if parsed_args.extra_vars_file:
with open(parsed_args.extra_vars_file, 'r') as env_file:
if '.json' in parsed_args.extra_vars_file:
extra_vars.update(json.load(env_file))
else:
extra_vars.update(yaml.load(env_file))
try:
with open(parsed_args.extra_vars_file, 'r') as env_file:
extra_vars.update(yaml.safe_load(env_file.read()))
except yaml.YAMLError as e:
error_msg = (
"The request body must be properly formatted YAML/JSON. "
"Details: %s." % e)
raise exceptions.CommandError(error_msg)
# We don't check if the file exists in order to support
# passing a string such as "localhost,", like we can do with