Commit 7d23b7e2 authored by Isabella Almeida da Silva's avatar Isabella Almeida da Silva
Browse files

[SOMA-3827][SOMA-4137] Tratar caso de definição duplicada de sga

- Limpando funções não mais usadas
- Criado esquema de warnings para casos de erro que não impedem a
continuação da execução do SGA
parent a4f5c64c
......@@ -3,7 +3,6 @@ local configuration = {}
local safer = require("safer")
local schema = require("schema")
local util = require("sga.util")
local function get(config_data, filename, config_default)
local config = {}
......@@ -37,21 +36,25 @@ local function get_from_multiple(filename, sga_name, config)
-- Indexes all sga configs by sga_name
local sgas = {}
for k,v in ipairs(sgas_data) do
local warning = ""
for key, data in ipairs(sgas_data) do
local sga_config, err_msg = {}
sga_config, err_msg = get(v, filename, config)
if not sga_config then
return nil, string.format(err, filename, err_msg)
sga_config, err_msg = get(data, filename, config)
if sga_config then
if sgas[sga_config.sga_name] then
warning = warning..string.format("[WARNING] Config file %s has duplicate configuration for sga '%s' \n", filename, sga_config.sga_name)
end
sgas[sga_config.sga_name] = sga_config
else
warning = warning..string.format("[WARNING] Config file %s has malformed configuration:\n %s \n", filename, data)
end
sgas[sga_config.sga_name] = sga_config
end
local config_data = sgas[sga_name]
if not config_data then
return nil, string.format(err, filename, "'"..sga_name.."' not found")
end
return config_data
return config_data, warning
end
function configuration.read(filename, sga_name)
......@@ -74,15 +77,16 @@ function configuration.read(filename, sga_name)
"Failed getting config '%s': file %s is not a valid multiple config file",
sga_name, filename)
end
local message = nil
if is_multiple then
config, err = get_from_multiple(filename, sga_name, config)
config, message = get_from_multiple(filename, sga_name, config)
if not config then
return nil, err
return nil, message
end
end
config = safer.readonly(config)
return config
return config, message
end
function configuration.check(config)
......@@ -105,7 +109,6 @@ function configuration.check(config)
driver_config = schema.Optional(schema.Map(schema.String, schema.Any)),
resources = schema.Optional(schema.Collection(schema.String)),
extra_config = schema.Optional(schema.Map(schema.String, schema.Any)),
sgas = schema.Optional(schema.Collection(schema.String)),
}
local err = schema.CheckSchema(config, config_schema)
if err then
......
......@@ -4,20 +4,6 @@ local util = {}
local lfs = require("lfs")
local stat = require("posix.sys.stat")
function util.table_shallow_copy(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in pairs(orig) do
copy[orig_key] = orig_value
end
else -- number, string, boolean, etc
copy = orig
end
return copy
end
function util.write_file(name, data)
local fd = io.open(name, "w")
if not fd then
......
......@@ -20,9 +20,11 @@ local function script_path()
return str:match("(.*)/") or "."
end
local config, err = configuration.read(args[1] or os.getenv("SGAD_CONFIG_FILE") or script_path().."/sgad.cfg", args[2])
local config, message = configuration.read(args[1] or os.getenv("SGAD_CONFIG_FILE") or script_path().."/sgad.cfg", args[2])
if message then
io.stderr:write(message.."\n")
end
if not config then
io.stderr:write(err.."\n")
os.exit(1)
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment