Commit 8dd40541 authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

deterministic ordering in 'awall dump'

parent 4e6cf81a
......@@ -136,6 +136,7 @@ if not call(
local awall = require('awall')
local printtabular = util.printtabular
local sortedkeys = util.sortedkeys
local policyset = awall.PolicySet(pol_paths)
......@@ -143,7 +144,7 @@ if not call(
local imported = policyset:load().policies
local data = {}
for i, name in util.sortedkeys(policyset.policies) do
for i, name in sortedkeys(policyset.policies) do
local policy = policyset.policies[name]
if all or policy.type == 'optional' then
......@@ -200,38 +201,41 @@ if not call(
return cls:sub(1, 1):upper()..cls:sub(2, -1)
end
for cls, objs in pairs(input.data) do
for _, cls in sortedkeys(input.data) do
if level > 2 or (level == 2 and cls ~= 'service') or contains(
{'variable', 'zone'},
cls
) then
if level == 0 then print(capitalize(cls)..'s:') end
local clsdata = input.data[cls]
local items = {}
for k, v in pairs(objs) do
local exp = expinput[cls][k]
for _, key in sortedkeys(clsdata) do
local exp = expinput[cls][key]
local expj = json.encode(exp)
local src = input.source[cls][k]
local src = input.source[cls][key]
if level == 0 then table.insert(items, {k, expj, src})
if level == 0 then table.insert(items, {key, expj, src})
else
local value = clsdata[key]
local data = {
{capitalize(cls)..' '..k, json.encode(v)},
{capitalize(cls)..' '..key, json.encode(value)},
{
'('..src..')',
util.compare(exp, v) and '' or '-> '..expj
util.compare(exp, value) and '' or '-> '..expj
}
}
if level > 3 then
local obj = config.objects[cls][k]
local obj = config.objects[cls][key]
if type(obj) == 'table' and obj.info then
util.extend(data, obj:info())
end
end
table.insert(items, {k, data})
table.insert(items, {key, data})
end
end
table.sort(items, function(a, b) return a[1] < b[1] end)
......
......@@ -4,6 +4,10 @@ Copyright (C) 2012-2014 Kaarle Ritvanen
See LICENSE file for license details
]]--
local sortedkeys = require('awall.util').sortedkeys
local IPSet = require('awall.class')()
function IPSet:init(config) self.config = config or {} end
......@@ -25,7 +29,7 @@ function IPSet:create()
end
function IPSet:print()
for name, ipset in pairs(self.config) do
for _, name in sortedkeys(self.config) do
self:dumpfile(name, io.stdout)
io.stdout:write('\n')
end
......
......@@ -39,7 +39,7 @@ local backupdir = '/var/run/awall'
local BaseIPTables = class()
function BaseIPTables:print()
for family, tbls in pairs(families) do
for _, family in sortedkeys(families) do
self:dumpfile(family, io.stdout)
print()
end
......
Markdown is supported
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