ntopng/scripts/lua/modules/rest_utils.lua
Luca Deri ccf76ca54d Added "real" intefaceId validation
Initial work towards REST API
2020-05-17 20:47:46 +02:00

30 lines
712 B
Lua

--
-- (C) 2020 - ntop.org
--
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "lua_utils"
local json = require ("dkjson")
local rest_utils = {}
rest_utils.consts_ok = 0
rest_utils.consts_not_found = -1
rest_utils.consts_invalid_interface = -2
local rc_str_consts = {
[rest_utils.consts_ok] = "OK",
[rest_utils.consts_not_found] = "NOT_FOUND",
[rest_utils.consts_invalid_interface] = "INVALID_INTEFACE",
}
function rest_utils.rc(ret_code, response)
local client_rsp = { rc = ret_code, rc_str = rc_str_consts[ret_code], rsp = response or {} }
return(json.encode(client_rsp))
end
return rest_utils