fix: unknown variable
This commit is contained in:
parent
61dc196e85
commit
9dad912ab3
3 changed files with 96 additions and 6 deletions
|
|
@ -56,6 +56,8 @@ class RougailUserDataYaml:
|
||||||
) -> None:
|
) -> None:
|
||||||
self.yaml = YAML(typ='safe', pure=True)
|
self.yaml = YAML(typ='safe', pure=True)
|
||||||
user_datas = []
|
user_datas = []
|
||||||
|
if self.file_with_secrets == "last":
|
||||||
|
last_filename_idx = len(self.filenames) - 1
|
||||||
for idx, filename in enumerate(self.filenames):
|
for idx, filename in enumerate(self.filenames):
|
||||||
filename = Path(filename)
|
filename = Path(filename)
|
||||||
if filename.is_file():
|
if filename.is_file():
|
||||||
|
|
@ -85,9 +87,7 @@ class RougailUserDataYaml:
|
||||||
elif self.file_with_secrets == "first":
|
elif self.file_with_secrets == "first":
|
||||||
allow_secrets_variables = idx == 0
|
allow_secrets_variables = idx == 0
|
||||||
elif self.file_with_secrets == "last":
|
elif self.file_with_secrets == "last":
|
||||||
if not idx:
|
allow_secrets_variables = idx == last_filename_idx
|
||||||
last_filenames = len(self.filenames) - 1
|
|
||||||
allow_secrets_variables = idx == last_filenames
|
|
||||||
else:
|
else:
|
||||||
allow_secrets_variables = True
|
allow_secrets_variables = True
|
||||||
user_datas.append(
|
user_datas.append(
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ def get_rougail_config(
|
||||||
yaml:
|
yaml:
|
||||||
description: {_("Configuration rougail-user-data-yaml")}
|
description: {_("Configuration rougail-user-data-yaml")}
|
||||||
disabled:
|
disabled:
|
||||||
type: jinja
|
|
||||||
jinja: |
|
jinja: |
|
||||||
{{% if step.user_data is propertyerror or 'yaml' not in step.user_data %}}
|
{{% if step.user_data is propertyerror or 'yaml' not in step.user_data %}}
|
||||||
disabled
|
disabled
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ from json import load, dump, loads, dumps
|
||||||
from ruamel.yaml import YAML
|
from ruamel.yaml import YAML
|
||||||
#########################
|
#########################
|
||||||
|
|
||||||
from rougail_tests.utils import get_structures_list, get_rougail_config, get_values_for_config, config_to_dict
|
from rougail_tests.utils import get_structures_list, get_rougail_config, get_values_for_config, config_to_dict, root_test_dir
|
||||||
|
|
||||||
EXT = "yml"
|
EXT = "yml"
|
||||||
|
|
||||||
|
|
@ -20,7 +20,7 @@ excludes = [
|
||||||
]
|
]
|
||||||
|
|
||||||
test_ok = get_structures_list(excludes)
|
test_ok = get_structures_list(excludes)
|
||||||
# test_ok = [Path('../rougail-tests/structures/20_9family_absolute')]
|
# test_ok = [Path('../rougail-tests/structures/60_6family_dynamic_sub_dynamic_empty2')]
|
||||||
|
|
||||||
|
|
||||||
def idfn(fixture_value):
|
def idfn(fixture_value):
|
||||||
|
|
@ -214,3 +214,94 @@ def test_structural_files_directory():
|
||||||
with open(data_file) as json_file:
|
with open(data_file) as json_file:
|
||||||
expected = load(json_file)
|
expected = load(json_file)
|
||||||
assert expected == data, data_file
|
assert expected == data, data_file
|
||||||
|
|
||||||
|
|
||||||
|
def test_secret_all():
|
||||||
|
root_test_dir / '00_6secret'
|
||||||
|
rougailconfig = get_rougail_config(root_test_dir / '00_6secret', namespace=False)
|
||||||
|
rougailconfig['step.user_data'] = ['yaml']
|
||||||
|
rougailconfig["yaml.file_with_secrets"] = "all"
|
||||||
|
rougailconfig["yaml.filename"] = ["tests/secrets/secret.yml"]
|
||||||
|
rougail = Rougail(rougailconfig)
|
||||||
|
config = rougail.run()
|
||||||
|
user_data = RougailUserData(config, rougailconfig=rougailconfig).run()
|
||||||
|
errors = rougail.user_datas(user_data)
|
||||||
|
assert errors == {'errors': [], 'warnings': []}
|
||||||
|
config_dict = dict(config_to_dict(config.value.get()))
|
||||||
|
assert config_dict == {'secret1': "my_password", 'secret2': 'value'}
|
||||||
|
|
||||||
|
|
||||||
|
def test_secret_none():
|
||||||
|
root_test_dir / '00_6secret'
|
||||||
|
rougailconfig = get_rougail_config(root_test_dir / '00_6secret', namespace=False)
|
||||||
|
rougailconfig['step.user_data'] = ['yaml']
|
||||||
|
rougailconfig["yaml.file_with_secrets"] = "none"
|
||||||
|
rougailconfig["yaml.filename"] = ["tests/secrets/secret.yml"]
|
||||||
|
rougail = Rougail(rougailconfig)
|
||||||
|
config = rougail.run()
|
||||||
|
user_data = RougailUserData(config, rougailconfig=rougailconfig).run()
|
||||||
|
errors = rougail.user_datas(user_data)
|
||||||
|
assert errors == {'errors': ['the variable "secret1" contains secrets and should not be defined in the YAML file "tests/secrets/secret.yml"'], 'warnings': []}
|
||||||
|
config_dict = dict(config_to_dict(config.value.get()))
|
||||||
|
assert config_dict == {'secret1': None, 'secret2': 'value'}
|
||||||
|
|
||||||
|
|
||||||
|
def test_secret_first():
|
||||||
|
root_test_dir / '00_6secret'
|
||||||
|
rougailconfig = get_rougail_config(root_test_dir / '00_6secret', namespace=False)
|
||||||
|
rougailconfig['step.user_data'] = ['yaml']
|
||||||
|
rougailconfig["yaml.file_with_secrets"] = "first"
|
||||||
|
rougailconfig["yaml.filename"] = ["tests/secrets/secret.yml", "tests/secrets/no_secret.yml"]
|
||||||
|
rougail = Rougail(rougailconfig)
|
||||||
|
config = rougail.run()
|
||||||
|
user_data = RougailUserData(config, rougailconfig=rougailconfig).run()
|
||||||
|
errors = rougail.user_datas(user_data)
|
||||||
|
assert errors == {'errors': [], 'warnings': []}
|
||||||
|
config_dict = dict(config_to_dict(config.value.get()))
|
||||||
|
assert config_dict == {'secret1': "my_password", 'secret2': 'value'}
|
||||||
|
|
||||||
|
|
||||||
|
def test_secret_first_error():
|
||||||
|
root_test_dir / '00_6secret'
|
||||||
|
rougailconfig = get_rougail_config(root_test_dir / '00_6secret', namespace=False)
|
||||||
|
rougailconfig['step.user_data'] = ['yaml']
|
||||||
|
rougailconfig["yaml.file_with_secrets"] = "first"
|
||||||
|
rougailconfig["yaml.filename"] = ["tests/secrets/no_secret.yml", "tests/secrets/secret.yml"]
|
||||||
|
rougail = Rougail(rougailconfig)
|
||||||
|
config = rougail.run()
|
||||||
|
user_data = RougailUserData(config, rougailconfig=rougailconfig).run()
|
||||||
|
errors = rougail.user_datas(user_data)
|
||||||
|
assert errors == {'errors': ['the variable "secret1" contains secrets and should not be defined in the YAML file "tests/secrets/secret.yml"'], 'warnings': []}
|
||||||
|
config_dict = dict(config_to_dict(config.value.get()))
|
||||||
|
assert config_dict == {'secret1': None, 'secret2': 'value'}
|
||||||
|
|
||||||
|
|
||||||
|
def test_secret_last():
|
||||||
|
root_test_dir / '00_6secret'
|
||||||
|
rougailconfig = get_rougail_config(root_test_dir / '00_6secret', namespace=False)
|
||||||
|
rougailconfig['step.user_data'] = ['yaml']
|
||||||
|
rougailconfig["yaml.file_with_secrets"] = "last"
|
||||||
|
rougailconfig["yaml.filename"] = ["tests/secrets/no_secret.yml", "tests/secrets/secret.yml"]
|
||||||
|
rougail = Rougail(rougailconfig)
|
||||||
|
config = rougail.run()
|
||||||
|
user_data = RougailUserData(config, rougailconfig=rougailconfig).run()
|
||||||
|
errors = rougail.user_datas(user_data)
|
||||||
|
assert errors == {'errors': [], 'warnings': []}
|
||||||
|
config_dict = dict(config_to_dict(config.value.get()))
|
||||||
|
assert config_dict == {'secret1': "my_password", 'secret2': 'value'}
|
||||||
|
|
||||||
|
|
||||||
|
def test_secret_last_error():
|
||||||
|
root_test_dir / '00_6secret'
|
||||||
|
rougailconfig = get_rougail_config(root_test_dir / '00_6secret', namespace=False)
|
||||||
|
rougailconfig['step.user_data'] = ['yaml']
|
||||||
|
rougailconfig["yaml.file_with_secrets"] = "last"
|
||||||
|
rougailconfig["yaml.filename"] = ["tests/secrets/secret.yml", "tests/secrets/no_secret.yml"]
|
||||||
|
rougail = Rougail(rougailconfig)
|
||||||
|
config = rougail.run()
|
||||||
|
user_data = RougailUserData(config, rougailconfig=rougailconfig).run()
|
||||||
|
errors = rougail.user_datas(user_data)
|
||||||
|
assert errors == {'errors': ['the variable "secret1" contains secrets and should not be defined in the YAML file "tests/secrets/secret.yml"'], 'warnings': []}
|
||||||
|
config_dict = dict(config_to_dict(config.value.get()))
|
||||||
|
assert config_dict == {'secret1': None, 'secret2': 'value'}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue