-- security_utils.lua
--
-- Just some handy utilities for the ProjectV security frameowork. Maybe it will be merged into the
-- commmand module at some point but it uses components that the RSM_web_base includes as deps.
-- Such as xmllint cmdline program.
--
module("security_utils", package.seeall)

require("luamods/command")

-- Edit config file inplace with a xml linter to fix growing files etc.
function cleanXmlConfigFile(dirtyConfigPath)
  -- NOTE: xml_pp may not be in vendor_perl dir forever. This is an unavoidable
  -- source of errors.
  local pipe = io.popen([[/usr/bin/vendor_perl/xml_pp ]]..dirtyConfigPath)

  local output = pipe:read("*a") or nil

  -- If the lint command failed don't destroy the config file.
  if output then
    command.writefile(dirtyConfigPath, output)
  end
end
