summaryrefslogtreecommitdiff
path: root/lib/gitano/config.lua
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-08-25 09:55:54 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-08-25 09:55:54 +0100
commit07b3006b6fd822357765c2586ed65e22b932892f (patch)
tree2026ad0f260f4ad37e7cd316c34e95fa40167e5d /lib/gitano/config.lua
parente74ff1ecc68f1423de93b5ece969c6a722a1684a (diff)
downloadgitano-07b3006b6fd822357765c2586ed65e22b932892f.tar.gz
CONFIG: Swap global config settings, and users, to using Clod
Diffstat (limited to 'lib/gitano/config.lua')
-rw-r--r--lib/gitano/config.lua55
1 files changed, 33 insertions, 22 deletions
diff --git a/lib/gitano/config.lua b/lib/gitano/config.lua
index f49d4cb..a49b643 100644
--- a/lib/gitano/config.lua
+++ b/lib/gitano/config.lua
@@ -13,6 +13,7 @@ local git = require 'gitano.git'
local log = require 'gitano.log'
local lace = require 'gitano.lace'
local sio = require 'luxio.simple'
+local clod = require 'clod'
local pcall = pcall
local pairs = pairs
@@ -34,6 +35,17 @@ local function repository()
return require 'gitano.repository'
end
+-- Handy Metatable so user.real_name etc works
+local user_mt = {}
+
+function user_mt:__index(key)
+ return self.clod.settings[key]
+end
+
+function user_mt:__newindex(key, value)
+ self.clod.settings[key] = value
+end
+
local function parse_admin_config(commit)
local gittree = commit.content.tree
local flat_tree = git.tree.flatten(gittree.content)
@@ -49,19 +61,19 @@ local function parse_admin_config(commit)
return nil, "No core rules file"
end
- local ok, conf_globals =
- sb.safe_load(flat_tree["site.conf"].obj.content,
+ local conf, err =
+ clod.parse(flat_tree["site.conf"].obj.content,
"gitano-admin:" .. commit.sha .. ":site.conf")
- if not ok then
- return nil, conf_globals
+ if not conf then
+ return nil, err
end
-- Parsed site.conf, check for core config entries
for k, t in pairs(required_confs) do
- if type(conf_globals[k]) ~= t then
- return nil, ("Error in %s [%s] expected %s got %s"):format("gitano-admin:" .. commit.sha .. ":site.conf", k, t, type(conf_globals[k]))
+ if type(conf.settings[k]) ~= t then
+ return nil, ("Error in %s [%s] expected %s got %s"):format("gitano-admin:" .. commit.sha .. ":site.conf", k, t, type(conf.settings[k]))
end
end
@@ -77,24 +89,25 @@ local function parse_admin_config(commit)
return nil, "Duplicate user name: " .. username
end
-- Found a user, fill them out
- local ok, user_globals =
- sb.safe_load(obj.obj.content,
+ local user_clod, err =
+ clod.parse(obj.obj.content,
commit.sha .. ":" .. prefix .. username .. "/user.conf")
- if not ok then
- return nil, user_globals
+ if not user_clod then
+ return nil, err
end
- if type(user_globals.real_name) ~= "string" then
+ if type(user_clod.settings.real_name) ~= "string" then
return nil, "gitano-admin:" .. commit.sha .. ":" .. prefix .. username .. "/user.conf missing real_name"
end
- if (user_globals.email_address and
- type(user_globals.email_address) ~= "string") then
+ if (user_clod.settings.email_address and
+ type(user_clod.settings.email_address) ~= "string") then
return nil, "gitano-admin:" .. commit.sha .. ":" .. prefix .. username .. "/user.conf email_address is bad"
end
- users[username] = user_globals
- users[username].keys = {}
- users[username].meta = { prefix = prefix }
+ users[username] = setmetatable({ clod = user_clod,
+ keys = {},
+ meta = { prefix = prefix },
+ }, user_mt)
end
end
@@ -218,7 +231,8 @@ local function parse_admin_config(commit)
-- Finally, return an object representing this configuration
local config = {
- global = conf_globals,
+ clod = conf,
+ global = conf.settings,
users = users,
groups = groups,
content = flat_tree,
@@ -351,15 +365,12 @@ local function commit_config_changes(conf, desc, username)
end
-- Write out the site.conf
local obj = conf.repo.git:hash_object("blob",
- serialise_conf(conf.global),
+ conf.clod:serialise(),
true)
newtree["site.conf"] = conf.repo.git:get(obj)
-- Construct all the users and write them out.
for u, utab in pairs(conf.users) do
- local str = serialise_conf {
- real_name = utab.real_name,
- email_address = utab.email_address
- }
+ local str = utab.clod:serialise()
local obj = conf.repo.git:hash_object("blob", str, true)
newtree[utab.meta.prefix .. u .. "/user.conf"] = conf.repo.git:get(obj)
-- Now the keys