Bertrand Lanson
1d71409b22
All checks were successful
test / Linting (push) Successful in 37s
test / Molecule tests (default, ubuntu2004) (push) Successful in 50s
test / Molecule tests (default, debian11) (push) Successful in 1m22s
test / Molecule tests (default, debian12) (push) Successful in 1m23s
test / Molecule tests (with_custom_flags, debian11) (push) Successful in 34s
test / Molecule tests (with_custom_flags, debian12) (push) Successful in 32s
test / Molecule tests (default, ubuntu2204) (push) Successful in 59s
test / Molecule tests (with_custom_flags, ubuntu2204) (push) Successful in 53s
test / Molecule tests (with_custom_flags, ubuntu2004) (push) Successful in 59s
33 lines
958 B
Python
33 lines
958 B
Python
# filter_plugins/docker_filters.py
|
|
|
|
def create_docker_flags(flags):
|
|
if flags:
|
|
filtered_flags = [
|
|
create_docker_flag(item) for item in flags if create_docker_flag(item)
|
|
]
|
|
return "\n".join(filtered_flags)
|
|
return None
|
|
|
|
|
|
def create_docker_flag(item):
|
|
if isinstance(item, dict):
|
|
key = list(item.keys())[0]
|
|
value = item[key]
|
|
if value is not None:
|
|
if isinstance(value, list):
|
|
flag_values = ['--{} "{}"'.format(key, val) for val in value]
|
|
joined_values = " \\\n".join(flag_values)
|
|
return f"{joined_values} \\" if joined_values else None
|
|
else:
|
|
return '--{} "{}" \\'.format(key, value)
|
|
elif isinstance(item, str):
|
|
return "--{} \\".format(item)
|
|
return None
|
|
|
|
|
|
class FilterModule(object):
|
|
def filters(self):
|
|
return {
|
|
"create_docker_flags": create_docker_flags,
|
|
}
|