summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--aconf/model/root.lua6
-rw-r--r--aconf/modules/dns-zone.lua2
-rw-r--r--aconf/modules/dnsmasq.lua9
-rw-r--r--aconf/modules/network.lua14
-rw-r--r--aconf/modules/openssh.lua4
-rw-r--r--aconf/persistence/backends/augeas.lua58
6 files changed, 46 insertions, 47 deletions
diff --git a/aconf/model/root.lua b/aconf/model/root.lua
index a407b07..949005e 100644
--- a/aconf/model/root.lua
+++ b/aconf/model/root.lua
@@ -83,11 +83,7 @@ function M.register(name, field, params)
local mode = record.be_mode
if mode then
- if object.isinstance(
- mode, require('aconf.path.address.special').SpecialMode
- ) then
- mode = {['.']=mode}
- end
+ if type(mode) == 'string' then mode = {['.']=mode} end
for addr, m in pairs(mode) do
set('mode', m, addr == '.' and top or top(addr, true))
end
diff --git a/aconf/modules/dns-zone.lua b/aconf/modules/dns-zone.lua
index f0bd3e1..6527d62 100644
--- a/aconf/modules/dns-zone.lua
+++ b/aconf/modules/dns-zone.lua
@@ -69,7 +69,7 @@ M.register(
type=M.Collection{
type=M.List{
type=M.Model{model=Record, addr='*/*'},
- be_mode=M.addr.special.enum_keys,
+ be_mode='enumerate',
ui_member='Record'
},
ui_member=''
diff --git a/aconf/modules/dnsmasq.lua b/aconf/modules/dnsmasq.lua
index f46e4a0..770a1d1 100644
--- a/aconf/modules/dnsmasq.lua
+++ b/aconf/modules/dnsmasq.lua
@@ -8,7 +8,7 @@ local M = require('aconf.model')
local filter_conf = '/etc/dnsmasq-filter.conf'
local Address = M.new()
-Address.address = M.net.IPAddress{be_mode=M.addr.special.value}
+Address.address = M.net.IPAddress{be_mode='parent-value'}
Address.domain = M.String
local Filter = M.new()
@@ -43,15 +43,12 @@ local Dnsmasq = M.new()
Dnsmasq.filter = M.Model{
model=Filter,
addr='/augeas'..filter_conf,
- be_mode={
- server=M.addr.special.value_equals(),
- ['server/\\#/domain']=M.addr.special.enum_keys
- }
+ be_mode={server='value', ['server/\\#/domain']='enumerate'}
}
Dnsmasq.conf_file = M.Set{
type=M.String,
addr='/augeas/etc/dnsmasq.conf/conf-file',
- be_mode=M.addr.special.enum_keys,
+ be_mode='enumerate',
visible=false
}
diff --git a/aconf/modules/network.lua b/aconf/modules/network.lua
index 05d8576..51d7589 100644
--- a/aconf/modules/network.lua
+++ b/aconf/modules/network.lua
@@ -13,7 +13,7 @@ Host.address = M.net.IPAddress{required=true, addr='ipaddr'}
Host.canonical = M.String{required=true, ui_name='Canonical name'}
Host.alias = M.Set{
type=M.String,
- be_mode=M.addr.special.enum_keys,
+ be_mode='enumerate',
ui_name='Aliases',
ui_member='Alias',
detail=false
@@ -23,13 +23,13 @@ local Resolv = M.new()
Resolv.servers = M.List{
type=M.net.IPAddress,
addr='nameserver',
- be_mode=M.addr.special.enum_keys,
+ be_mode='enumerate',
widget='inline'
}
Resolv.search_domains = M.List{
type=M.String,
addr='search/domain',
- be_mode=M.addr.special.enum_keys,
+ be_mode='enumerate',
widget='inline'
}
@@ -255,16 +255,16 @@ Net.resolver = M.Model{
Net.enabled_ifaces = M.Set{
type=M.Reference{scope='../interfaces', addr='*/*', on_delete='set-null'},
addr=iface_aug_addr..'/auto',
- be_mode=M.addr.special.enum_keys,
+ be_mode='enumerate',
visible=false
}
Net.interfaces = M.Collection{
type=Interface,
addr=iface_aug_addr..'/iface',
be_mode={
- ['.']=M.addr.special.value_equals(),
- ['*']=M.addr.special.value_equals('family'),
- ['*/link']=M.addr.special.value_equals('method')
+ ['.']='value',
+ ['*']='child-value:family',
+ ['*/link']='child-value:method'
},
widget='inline'
}
diff --git a/aconf/modules/openssh.lua b/aconf/modules/openssh.lua
index 4592c71..c1db8b9 100644
--- a/aconf/modules/openssh.lua
+++ b/aconf/modules/openssh.lua
@@ -17,7 +17,7 @@ SshKey.type = M.String{
{'ssh-rsa', 'ssh-rsa'}
}
}
-SshKey.key = M.String{be_mode=M.addr.special.value}
+SshKey.key = M.String{be_mode='parent-value'}
SshKey.comment = M.String
local Sshd = M.service('sshd')
@@ -36,7 +36,7 @@ Sshd.agent_forward = M.Boolean{
Sshd.root_auth_keys = M.List{
type=SshKey,
addr='/augeas/root/.ssh/authorized_keys/key',
- be_mode=M.addr.special.enum_keys,
+ be_mode='enumerate',
ui_name='Root login keys',
ui_member='Key'
}
diff --git a/aconf/persistence/backends/augeas.lua b/aconf/persistence/backends/augeas.lua
index 2210346..46d3ea9 100644
--- a/aconf/persistence/backends/augeas.lua
+++ b/aconf/persistence/backends/augeas.lua
@@ -4,13 +4,8 @@ See LICENSE file for license details
--]]
local topology = require('aconf.model.root').topology
-
-local object = require('aconf.object')
-local class = object.class
-local isinstance = object.isinstance
-
+local class = require('aconf.object').class
local address = require('aconf.path.address')
-local special = require('aconf.path.address.special')
local tostr = require('aconf.persistence.util').tostring
local util = require('aconf.util')
@@ -18,6 +13,9 @@ local contains = util.contains
local copy = util.copy
+local stringy = require('stringy')
+
+
local function array_join(tbl, value)
local res = copy(tbl)
table.insert(res, value)
@@ -45,7 +43,14 @@ local function append_key_pred(path, key, value)
return append_pred(path, key.." = '"..value.."'")
end
-local function key(mode) return mode.key or '.' end
+local function key(mode)
+ if mode == 'value' then return '.' end
+ if mode and stringy.startswith(mode, 'child-value:') then
+ return mode:sub(13, -1)
+ end
+end
+
+local function is_selector(mode) return mode and mode ~= 'parent-value' end
@@ -69,15 +74,15 @@ local function conv_path(path)
local comp = path[1]
if mode then
- if isinstance(mode, special.EnumKeys) then
+ if mode == 'enumerate' then
assert(type(comp) == 'number')
res = append_pred(res, comp)
- elseif isinstance(mode, special.ValueEquals) then
- assert(type(comp) == 'string' and comp:match('^[%w %_%-%.%#]+$'))
+ else
local k = key(mode)
+ assert(k and type(comp) == 'string' and comp:match('^[%w %_%-%.%#]+$'))
res = append_key_pred(res, k, comp)
table.insert(keys, k)
- else assert(false) end
+ end
parent = nil
@@ -93,7 +98,7 @@ local function conv_path(path)
table.remove(path, 1)
until #path == 0
- if isinstance(mode, special.Value) then
+ if mode == 'parent-value' then
assert(parent)
res = parent
end
@@ -116,17 +121,16 @@ function backend:get(path, top)
if tbl and top.subtype == 'model' then mode = nil end
local leaf = not tbl and not mode
- if isinstance(mode, special.Value) then
+ if mode == 'parent-value' then
assert(not tbl)
leaf = true
end
local matches = self.aug:match(apath..(not leaf and not mode and '/*' or ''))
- local is_selector = isinstance(mode, special.Selector)
- if #matches == 0 and not is_selector then return end
+ if #matches == 0 and not is_selector(mode) then return end
- if is_selector and #path > 1 and not self:get(
+ if is_selector(mode) and #path > 1 and not self:get(
array_without_last(path), true
) then
return
@@ -135,7 +139,7 @@ function backend:get(path, top)
if not tpe and not mode then
if #matches > 1 then
leaf = false
- mode = address.special.enum_keys
+ mode = 'enumerate'
else
local children = self.aug:match(apath..'/*')
if #children > 0 then
@@ -160,10 +164,12 @@ function backend:get(path, top)
name = basename(child)
name = tonumber(name) or name
if contains(keys, name) then name = nil end
- elseif isinstance(mode, special.EnumKeys) then name = i
- elseif isinstance(mode, special.ValueEquals) then
- name = self.aug:get(child..(mode.key and '/'..mode.key or ''))
- else assert(false) end
+ elseif mode == 'enumerate' then name = i
+ else
+ local k = key(mode)
+ assert(k)
+ name = self.aug:get(child..(k == '.' and '' or '/'..k))
+ end
if name and self:get(array_join(path, name), true) then
names[name] = true
@@ -187,10 +193,10 @@ function backend:set(mods)
local parent = array_without_last(path)
local ppath, pmode = conv_path(parent)
- if isinstance(pmode, special.Selector) then
+ if is_selector(pmode) then
gc[address.join('/', table.unpack(parent))] = false
- if isinstance(pmode, special.EnumKeys) then
+ if pmode == 'enumerate' then
local count = #self.aug:match(ppath)
while count < name do
insert(parent, true)
@@ -205,9 +211,9 @@ function backend:set(mods)
if count > 0 and not new then return apath, keys end
- if isinstance(pmode, special.ValueEquals) then
- apath = pmode.key and append_pred(
- ppath, 'count('..pmode.key..') = 0'
+ if key(pmode) then
+ apath = key(pmode) and append_pred(
+ ppath, 'count('..key(pmode)..') = 0'
) or append_key_pred(ppath, '.', '')
matches = self.aug:match(apath)