Use generic logic for overriding config entries from values in yaml config files (#251)

This commit is contained in:
Francois Dupoux 2022-01-28 20:34:23 +00:00
parent 42dc684685
commit 35bd8314f3
2 changed files with 7 additions and 15 deletions

View file

@ -140,10 +140,10 @@ if config['global']['dovnc'] == True:
# ==============================================================================
ca_anchor_path = "/etc/ca-certificates/trust-source/anchors/"
if config['ca-trust']:
if config['sysconfig']['ca-trust']:
print(f"====> Adding trusted CA certificates ...")
for name, cert in sorted(config['ca-trust'].items()):
for name, cert in sorted(config['sysconfig']['ca-trust'].items()):
print (f"Adding certificate '{name}' ...")
with open(os.path.join(ca_anchor_path, name + ".pem"), "w") as certfile:
certfile.write(cert)

View file

@ -78,7 +78,9 @@ config = {
['ar_source'] = "",
['ar_suffixes'] = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F",
},
["ca-trust"] = {},
["sysconfig"] = {
["ca-trust"] = {},
},
}
-- ==============================================================================
@ -94,24 +96,14 @@ for _, confdir in ipairs(yamlconfdirs) do
local curconfig = yaml.loadpath(curfile)
--print("++++++++++++++\n"..yaml.dump(curconfig).."++++++++++++++\n")
if curconfig ~= nil then
-- Override specific pre-defined options
for _, scope in ipairs({"global", "autorun"}) do
for key, val in pairs(config[scope]) do
for scope, entries in pairs(config) do
for key, val in pairs(entries) do
if (curconfig[scope] ~= nil) and (curconfig[scope][key] ~= nil) then
print("- Overriding config['"..scope.."']['"..key.."'] with the value from the yaml file")
config[scope][key] = curconfig[scope][key]
end
end
end
-- Populate additional items
for _, scope in ipairs({"ca-trust"}) do
if curconfig[scope] ~= nil then
for key, val in pairs(curconfig[scope]) do
print("- Setting config['"..scope.."']['"..key.."'] with the value from the yaml file")
config[scope][key] = val
end
end
end
end
end
else