summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2015-11-05 14:52:32 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2015-11-05 14:52:32 +0000
commitbb5b3839d2031f0086da814d1f87c82c781108c9 (patch)
treee2ffdad7187a29c8ecb6b1be07a6cf3fd1bc83a0
parent25d58ff9f19c7af2eff8e90f97aa64d180151152 (diff)
downloadgitano-bb5b3839d2031f0086da814d1f87c82c781108c9.tar.bz2
Add support for auto_user_* and auto_group_*
-rw-r--r--lib/gitano/lace.lua37
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/gitano/lace.lua b/lib/gitano/lace.lua
index 53fe53e..2376cc8 100644
--- a/lib/gitano/lace.lua
+++ b/lib/gitano/lace.lua
@@ -11,6 +11,34 @@ local log = require 'gitano.log'
local pcre = require "rex_pcre"
+local function flatten_name(n)
+ return n:gsub("[^A-Za-z0-9]", "_")
+end
+local function generate_automatics(ctx)
+ local config = ctx.repo.config
+ local automatics = {}
+ for u in pairs(config.users) do
+ automatics["user_" .. flatten_name(u)] = "user " .. u
+ end
+ for g in pairs(config.groups) do
+ automatics["group_" .. flatten_name(g)] = "group " .. g
+ end
+ local ret = {}
+ for k, v in pairs(automatics) do
+ ret[#ret+1] = "define auto_" .. k .. " " .. v
+ end
+ ret[#ret+1] = "\n"
+ return table.concat(ret,"\n")
+end
+
+local global_lookaside = {
+ ["_automatics"] = generate_automatics,
+ ["_basis"] = [[
+include global:_automatics
+include global:core
+]]
+}
+
local function _loader(ctx, _name)
local global_name = _name:match("^global:(.+)$")
local name, tree, sha = global_name or _name
@@ -25,6 +53,13 @@ local function _loader(ctx, _name)
end
else
-- Global load
+ if global_lookaside[global_name] then
+ local resolved = global_lookaside[global_name]
+ if type(resolved) == "function" then
+ resolved = resolved(ctx)
+ end
+ return "global_lookaside::" .. global_name, resolved
+ end
if not ctx.global_tree then
ctx.global_tree = gall.tree.flatten(ctx.global.content.tree.content)
end
@@ -192,7 +227,7 @@ local function compile_ruleset(repo, adminsha, globaladminsha)
compcontext.global = repo.config.repo.git:get(globaladminsha)
end
- return lace.compiler.compile(compcontext, "global:core")
+ return lace.compiler.compile(compcontext, "global:_basis")
end
local function run_ruleset(ruleset, ctx)