summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-05-16 15:33:42 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-05-16 15:33:42 +0100
commit07a32394d6453dacd4a88703657cb9bd1e476368 (patch)
tree5cc9a162554a31aa1cb751b8b71f5e359a806f8a /bin
parent110ae14990387c6b8a48d19067fc77a609f46ba8 (diff)
downloadgitano-07a32394d6453dacd4a88703657cb9bd1e476368.tar.gz
LACE: Switch over to Lace for rulesets. Untested
Diffstat (limited to 'bin')
-rw-r--r--bin/gitano-auth35
-rw-r--r--bin/gitano-update-hook63
2 files changed, 46 insertions, 52 deletions
diff --git a/bin/gitano-auth b/bin/gitano-auth
index 0905819..e989b15 100644
--- a/bin/gitano-auth
+++ b/bin/gitano-auth
@@ -103,40 +103,37 @@ if not cmd.validate(config, repo, parsed_cmdline) then
gitano.log.fatal("Validation of commandline failed")
end
--- Now prep, this returns an initial tagset for the rules.
-local tags = cmd.prep(config, repo, parsed_cmdline)
-if not tags then
+-- Now prep, this returns an initial context for the ruleset.
+local context = cmd.prep(config, repo, parsed_cmdline)
+if not context then
gitano.log.fatal("Unable to prepare tag set for rules parse")
end
if repo then
- repo:populate_tags(tags)
+ repo:populate_context(context)
end
-tags["gitano/source"] = "ssh"
-gitano.config.populate_tags(config, tags, username)
+context["source"] = "ssh"
+gitano.config.populate_context(config, context, username)
--- Run the ruleset given the tagset
+-- Run the ruleset given the contextet
-local finished
+local action, reason
-if tags["gitano/operation"] then
- finished = gitano.rules.execute(config, repo, tags)
+if context["operation"] then
+ action, reason = gitano.lace.execute(context)
else
- finished = true
- tags["gitano/action"] = "allow"
+ action = "allow"
+ reason = "Nothing to test"
end
-if not finished then
+if not action then
+ gitano.log.crit(reason)
gitano.log.fatal("Ruleset did not complete cleanly")
end
-if not tags["gitano/action"] then
- gitano.log.fatal("Ruleset did not set gitano/action")
-end
-
-if tags["gitano/action"] ~= "allow" then
- gitano.log.critical(tags["gitano/reason"] or "No reason provided")
+if action ~= "allow" then
+ gitano.log.critical(reason)
gitano.log.fatal("Ruleset denied action. Sorry")
end
diff --git a/bin/gitano-update-hook b/bin/gitano-update-hook
index 7fb3dab..a588f6a 100644
--- a/bin/gitano-update-hook
+++ b/bin/gitano-update-hook
@@ -75,29 +75,29 @@ end
-- Prepare an update operation
-local tags = {
- ["gitano/source"] = source,
- ["gitano/ref"] = refname,
- ["gitano/oldsha"] = oldsha,
- ["gitano/newsha"] = newsha,
+local context = {
+ ["source"] = source,
+ ["ref"] = refname,
+ ["oldsha"] = oldsha,
+ ["newsha"] = newsha,
}
-repo:populate_tags(tags)
-gitano.config.populate_tags(config, tags, username)
+repo:populate_context(context)
+gitano.config.populate_context(config, context, username)
-- Attempt to work out what's going on regarding the update.
if oldsha == nullsha and newsha ~= nullsha then
- tags["gitano/operation"] = "createref"
+ context["operation"] = "createref"
elseif oldsha ~= nullsha and newsha == nullsha then
- tags["gitano/operation"] = "deleteref"
+ context["operation"] = "deleteref"
else
local base, msg = repo.git:merge_base(oldsha, newsha)
if not base then
gitano.log.fatal(msg)
elseif (base == true) or ((base) and (base == newsha)) then
- tags["gitano/operation"] = "updaterefnonff"
+ context["operation"] = "updaterefnonff"
else
- tags["gitano/operation"] = "updaterefff"
+ context["operation"] = "updaterefff"
end
end
@@ -121,7 +121,7 @@ end
local function set_list(tag, entries)
table.sort(entries)
entries[#entries+1] = ""
- tags[tag] = table.concat({"", unpack(entries)}, "\0")
+ context[tag] = table.concat({"", unpack(entries)}, "\0")
end
local function populate_tree(tag, tree)
@@ -133,8 +133,8 @@ local function populate_tree(tag, tree)
set_list(tag, names)
end
-populate_tree("gitano/starttree", oldtree)
-populate_tree("gitano/targettree", newtree)
+populate_tree("starttree", oldtree)
+populate_tree("targettree", newtree)
-- Now gitano/treedelta
local delta = oldtree:diff_to(newtree)
@@ -164,38 +164,35 @@ for i = 1, #delta do
renamedto[#renamedto+1] = fname
end
- tags["gitano/treediff/kind/" .. fname] = details.endkind
- tags["gitano/treediff/oldkind/" .. fname] = details.startkind
+ context["treediff/kind/" .. fname] = details.endkind
+ context["treediff/oldkind/" .. fname] = details.startkind
end
-set_list("gitano/treediff/targets", targets)
-set_list("gitano/treediff/added", added)
-set_list("gitano/treediff/deleted", deleted)
-set_list("gitano/treediff/modified", modified)
-set_list("gitano/treediff/renamed", renamed)
-set_list("gitano/treediff/renamedto", renamedto)
+set_list("treediff/targets", targets)
+set_list("treediff/added", added)
+set_list("treediff/deleted", deleted)
+set_list("treediff/modified", modified)
+set_list("treediff/renamed", renamed)
+set_list("treediff/renamedto", renamedto)
--- Run the ruleset given the tagset
+-- Run the ruleset given the contextet
-local finished = gitano.rules.execute(config, repo, tags)
+local action, reason = gitano.lace.execute(context)
-if not finished then
+if not action then
+ gitano.log.crit(reason)
gitano.log.fatal("Ruleset did not complete cleanly")
end
-if not tags["gitano/action"] then
- gitano.log.fatal("Ruleset did not set gitano/action")
-end
-
-if tags["gitano/action"] ~= "allow" then
- gitano.log.critical("Rules refused update:",
- tags["gitano/reason"] or "No reason provided")
+if action ~= "allow" then
+ gitano.log.critical("Rules refused update:", reason)
gitano.log.fatal("Ruleset denied action. Sorry")
end
-- Now perform any special hook checks (e.g. for the admin hook)
gitano.log.ddebug("Ruleset allowed the action, let's run builtin action")
-local allow, msg = gitano.actions.update_actions(conf, repo, tags)
+
+local allow, msg = gitano.actions.update_actions(conf, repo, context)
if not allow then
gitano.log.critical("Builtin actions said:", msg)
gitano.log.fatal("Actions denied action. Sorry")