summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/gitano/actions.lua14
-rw-r--r--lib/gitano/admincommand.lua716
-rw-r--r--lib/gitano/auth.lua6
-rw-r--r--lib/gitano/command.lua406
-rw-r--r--lib/gitano/config.lua232
-rw-r--r--lib/gitano/copycommand.lua12
-rw-r--r--lib/gitano/i18n.lua20
-rw-r--r--lib/gitano/lace.lua52
-rw-r--r--lib/gitano/log.lua51
-rw-r--r--lib/gitano/plugins.lua22
-rw-r--r--lib/gitano/repocommand.lua16
-rw-r--r--lib/gitano/repository.lua284
-rw-r--r--lib/gitano/supple.lua10
-rw-r--r--lib/gitano/usercommand.lua92
-rw-r--r--lib/gitano/util.lua268
15 files changed, 1099 insertions, 1102 deletions
diff --git a/lib/gitano/actions.lua b/lib/gitano/actions.lua
index 336a71f..c71d5da 100644
--- a/lib/gitano/actions.lua
+++ b/lib/gitano/actions.lua
@@ -16,14 +16,14 @@ local subprocess = require 'luxio.subprocess'
local function update_actions(conf, repo, tags)
log.ddebug("Repo", repo.name, "ref", tags["ref"])
- if repo.name == "gitano-admin" and
- tags["ref"] == "refs/heads/master" then
+ if repo.name == "gitano-admin" and
+ tags["ref"] == "refs/heads/master" then
-- Update to the master branch of the gitano-admin repo, perform a conf
-- check based on the target sha
log.chat(i18n.expand("VERIFY_NEW_GITANO_ADMIN"))
local conf, msg = config.parse(repo.git:get(tags["newsha"]))
if not conf then
- return false, msg
+ return false, msg
end
log.chat(i18n.expand("LOOKS_OKAY"))
end
@@ -33,7 +33,7 @@ local function update_actions(conf, repo, tags)
log.chat(i18n.expand("VERIFY_NEW_ADMIN_SHA", {sha=tags["newsha"]}))
local ok, msg = repo:validate_admin_sha(tags["newsha"])
if not ok then
- return false, msg
+ return false, msg
end
log.chat(i18n.expand("LOOKS_OKAY"))
end
@@ -46,7 +46,7 @@ end
local function _curl_txn(url, headers, body, content_type)
local method = (body and body ~= "") and "POST" or "GET"
local args = { "curl", "--max-filesize", tostring(1024*1024),
- "--insecure", "-X", method, "-D-", "-s" }
+ "--insecure", "-X", method, "-D-", "-s" }
if type(url) ~= "string" then
return "500", "url must be a string", {}, ""
end
@@ -104,8 +104,8 @@ local function set_supple_globals(action)
local logcopy = {}
for _, k in pairs({ "state", "crit", "critical", "err", "error", "warn",
- "warning", "chat", "info", "debug", "ddebug",
- "deepdebug" }) do
+ "warning", "chat", "info", "debug", "ddebug",
+ "deepdebug" }) do
logcopy[k] = log[k]
end
globs["log"] = logcopy
diff --git a/lib/gitano/admincommand.lua b/lib/gitano/admincommand.lua
index af0e1e9..bd9b6b6 100644
--- a/lib/gitano/admincommand.lua
+++ b/lib/gitano/admincommand.lua
@@ -56,8 +56,8 @@ local function builtin_as_validate(config, _, cmdline)
-- Acquire the repository object for the target repo
repo, cmdline.copy = cmd.detect_repo(config, cmdline.copy)
if not repo and not cmdline.copy then
- log.error("Unable to continue")
- return false
+ log.error("Unable to continue")
+ return false
end
cmdline.repo = repo
end
@@ -81,7 +81,7 @@ local function builtin_as_prep(conf, _, cmdline, context)
if res == "allow" then
-- Check to see if the user exists
if conf.users[cmdline[2]] == nil then
- res, msg = "deny", "User '" .. cmdline[2] .. "' does not exist."
+ res, msg = "deny", "User '" .. cmdline[2] .. "' does not exist."
end
end
return res, msg
@@ -185,17 +185,17 @@ local function builtin_user_run(conf, _, cmdline, env)
-- Listing all the users
local users = {}
for k in pairs(conf.users) do
- users[#users+1] = k
+ users[#users+1] = k
end
table.sort(users)
for _, username in ipairs(users) do
- log.stdout(username .. ":" ..
- conf.users[username].email_address .. ":" ..
- conf.users[username].real_name)
+ log.stdout(username .. ":" ..
+ conf.users[username].email_address .. ":" ..
+ conf.users[username].real_name)
end
elseif cmdline[2] == "add" then
if conf.users[cmdline[3]] then
- log.fatal("User", cmdline[3], "already exists")
+ log.fatal("User", cmdline[3], "already exists")
end
local new_name = util.deep_copy(cmdline)
table.remove(new_name, 1)
@@ -207,9 +207,9 @@ local function builtin_user_run(conf, _, cmdline, env)
new_clod.settings.email_address = cmdline[4]
new_clod.settings.real_name = new_name
local utab = {
- clod = new_clod,
- meta = { prefix = "users/" },
- keys = {}
+ clod = new_clod,
+ meta = { prefix = "users/" },
+ keys = {}
}
conf.users[cmdline[3]] = utab
reason = "Create user " .. cmdline[3]
@@ -217,7 +217,7 @@ local function builtin_user_run(conf, _, cmdline, env)
-- Find the named user
local utab = conf.users[cmdline[3]]
if not utab then
- log.fatal("Could not find user:", cmdline[3])
+ log.fatal("Could not find user:", cmdline[3])
end
local new_name = util.deep_copy(cmdline)
table.remove(new_name, 1)
@@ -225,96 +225,96 @@ local function builtin_user_run(conf, _, cmdline, env)
table.remove(new_name, 1)
new_name = table.concat(new_name, " ")
if utab.real_name ~= new_name then
- utab.real_name = new_name
- reason = "Change real name of " .. cmdline[3]
+ utab.real_name = new_name
+ reason = "Change real name of " .. cmdline[3]
end
elseif cmdline[2] == "email" then
-- Find the named user
local utab = conf.users[cmdline[3]]
if not utab then
- log.fatal("Could not find user:", cmdline[3])
+ log.fatal("Could not find user:", cmdline[3])
end
if utab.email_address ~= cmdline[4] then
- utab.email_address = cmdline[4]
- reason = "Change email address of " .. cmdline[3]
+ utab.email_address = cmdline[4]
+ reason = "Change email address of " .. cmdline[3]
end
elseif cmdline[2] == "del" then
local username = cmdline[3]
local utab = conf.users[username]
if not utab then
- log.fatal("Could not find user:", username)
+ log.fatal("Could not find user:", username)
end
local token = conf.repo:generate_confirmation("delete " .. username)
if not cmdline[4] then
- log.state("In order to delete", username, "you must supply the following token:")
- log.state(token)
+ log.state("In order to delete", username, "you must supply the following token:")
+ log.state(token)
elseif cmdline[4] ~= token and cmdline[4] ~= '--force' then
- log.error("Tokens do not match. Did someone else do administrative actions?")
+ log.error("Tokens do not match. Did someone else do administrative actions?")
else
- -- Iterate groups and remove the user from any group it is
- -- a direct member of
- for g, gtab in pairs(conf.groups) do
- if gtab.members[username] then
- table.remove(gtab.members, gtab.members[username])
- gtab.members[username] = nil
- gtab.changed_tables()
- log.state("Removed", username, "from membership of", g)
- end
- end
- -- Now remove the user
- conf.users[username] = nil
- -- And explain what
- reason = "Delete user " .. username
+ -- Iterate groups and remove the user from any group it is
+ -- a direct member of
+ for g, gtab in pairs(conf.groups) do
+ if gtab.members[username] then
+ table.remove(gtab.members, gtab.members[username])
+ gtab.members[username] = nil
+ gtab.changed_tables()
+ log.state("Removed", username, "from membership of", g)
+ end
+ end
+ -- Now remove the user
+ conf.users[username] = nil
+ -- And explain what
+ reason = "Delete user " .. username
end
elseif cmdline[2] == "rename" then
local oldusername = cmdline[3]
local newusername = cmdline[4]
local utab = conf.users[oldusername]
if not utab then
- log.fatal("Could not find user:", oldusername)
+ log.fatal("Could not find user:", oldusername)
end
if conf.users[newusername] then
- log.fatal("New username already exists:", newusername)
+ log.fatal("New username already exists:", newusername)
end
local token = conf.repo:generate_confirmation("rename " .. oldusername ..
- " to " .. newusername)
+ " to " .. newusername)
if not cmdline[5] then
- log.state("In order to rename", oldusername, "you must supply the following token:")
- log.state(token)
+ log.state("In order to rename", oldusername, "you must supply the following token:")
+ log.state(token)
elseif cmdline[5] ~= token and cmdline[5] ~= '--force' then
- log.error("Tokens do not match. Did someone else do administrative actions?")
+ log.error("Tokens do not match. Did someone else do administrative actions?")
else
- -- Iterate groups and rename the user in any group it is
- -- a direct member of
- for g, gtab in pairs(conf.groups) do
- if gtab.members[oldusername] then
- gtab.members[gtab.members[oldusername]] = newusername
- gtab.members[newusername] = gtab.members[oldusername]
- gtab.members[oldusername] = nil
- gtab.changed_tables()
- log.state("Renamed:", oldusername, "to", newusername,
- "in membership of group:", g)
- end
- end
- -- Now rename the user itself
- conf.users[newusername] = utab
- conf.users[oldusername] = nil
- -- And explain what
- reason = "Rename user " .. oldusername .. " to " .. newusername
- -- Finally update the environment if necessary
- if env.GITANO_USER == oldusername then
- env.GITANO_USER = newusername
- end
- if env.GITANO_ORIG_USER == oldusername then
- env.GITANO_ORIG_USER = newusername
- end
+ -- Iterate groups and rename the user in any group it is
+ -- a direct member of
+ for g, gtab in pairs(conf.groups) do
+ if gtab.members[oldusername] then
+ gtab.members[gtab.members[oldusername]] = newusername
+ gtab.members[newusername] = gtab.members[oldusername]
+ gtab.members[oldusername] = nil
+ gtab.changed_tables()
+ log.state("Renamed:", oldusername, "to", newusername,
+ "in membership of group:", g)
+ end
+ end
+ -- Now rename the user itself
+ conf.users[newusername] = utab
+ conf.users[oldusername] = nil
+ -- And explain what
+ reason = "Rename user " .. oldusername .. " to " .. newusername
+ -- Finally update the environment if necessary
+ if env.GITANO_USER == oldusername then
+ env.GITANO_USER = newusername
+ end
+ if env.GITANO_ORIG_USER == oldusername then
+ env.GITANO_ORIG_USER = newusername
+ end
end
end
if reason then
-- Need to try and make a config commit
local ok, commit = config.commit(conf, reason, env.GITANO_USER, env.GITANO_ORIG_USER)
if not ok then
- log.fatal(commit)
+ log.fatal(commit)
end
log.state("Committed: " .. reason)
end
@@ -360,7 +360,7 @@ local function builtin_group_validate(conf, _, cmdline)
cmdline[2] = "list"
end
local groupsubs = util.set {"list", "show", "add", "del", "rename",
- "adduser", "deluser", "addgroup", "delgroup", "description"}
+ "adduser", "deluser", "addgroup", "delgroup", "description"}
if not groupsubs[cmdline[2]] then
log.error("Unknown sub command", cmdline[2], "for group")
return false
@@ -421,10 +421,10 @@ end
local function builtin_group_prep(conf, _, cmdline, context)
context.operation = "group" .. cmdline[2]
util.add_splitable(context, "targetgroup", cmdline[3],
- "-", "prefix", "suffix")
+ "-", "prefix", "suffix")
if cmdline[2]:match("user") or cmdline[2]:match("group") then
util.add_splitable(context, "member", cmdline[4],
- "-", "prefix", "suffix")
+ "-", "prefix", "suffix")
end
return conf.repo:run_lace(context)
end
@@ -434,28 +434,28 @@ local function builtin_group_run(conf, _, cmdline, env)
if cmdline[2] == "list" then
local groups = {}
for g in pairs(conf.groups) do
- groups[#groups+1] = g
+ groups[#groups+1] = g
end
table.sort(groups)
for _, g in ipairs(groups) do
- log.stdout(g .. ":" .. conf.groups[g].settings.description)
+ log.stdout(g .. ":" .. conf.groups[g].settings.description)
end
elseif cmdline[2] == "show" then
local g, gtab = cmdline[3], conf.groups[cmdline[3]]
if not gtab then
- log.fatal("Unknown group", g)
+ log.fatal("Unknown group", g)
end
log.stdout(g .. ":" .. gtab.settings.description)
for i, m in ipairs(gtab.members) do
- log.stdout(" => " .. m)
+ log.stdout(" => " .. m)
end
for i, gg in ipairs(gtab.subgroups) do
- log.stdout(" [] " .. gg)
+ log.stdout(" [] " .. gg)
end
elseif cmdline[2] == "add" then
local g = cmdline[3]
if conf.groups[g] then
- log.fatal("Group", g, "already exists")
+ log.fatal("Group", g, "already exists")
end
local new_desc = util.deep_copy(cmdline)
table.remove(new_desc, 1)
@@ -465,17 +465,17 @@ local function builtin_group_run(conf, _, cmdline, env)
local new_clod = clod.parse("")
new_clod.settings.description = new_desc
local gtab = {
- clod = new_clod,
- members = {},
- subgroups = {},
- meta = { prefix = "groups/" }
+ clod = new_clod,
+ members = {},
+ subgroups = {},
+ meta = { prefix = "groups/" }
}
conf.groups[g] = gtab
reason = "Create group " .. g
elseif cmdline[2] == "description" then
local g, gtab = cmdline[3], conf.groups[cmdline[3]]
if not gtab then
- log.fatal("Unknown group", g)
+ log.fatal("Unknown group", g)
end
local new_desc = util.deep_copy(cmdline)
table.remove(new_desc, 1)
@@ -483,151 +483,151 @@ local function builtin_group_run(conf, _, cmdline, env)
table.remove(new_desc, 1)
new_desc = table.concat(new_desc, " ")
if gtab.settings.description ~= new_desc then
- gtab.settings.description = new_desc
- reason = "Change group description of " .. g
+ gtab.settings.description = new_desc
+ reason = "Change group description of " .. g
end
elseif cmdline[2] == "del" then
local g = cmdline[3]
if not conf.groups[g] then
- log.fatal("Unknown group", g)
+ log.fatal("Unknown group", g)
end
local token = conf.repo:generate_confirmation("delete group " .. g)
if not cmdline[4] then
- log.state("In order to delete group", g, "you must supply the following token:")
- log.state(token)
+ log.state("In order to delete group", g, "you must supply the following token:")
+ log.state(token)
elseif cmdline[4] ~= token and cmdline[4] ~= '--force' then
- log.fatal("Token does not match. Has someone else done administrative actions?")
+ log.fatal("Token does not match. Has someone else done administrative actions?")
else
- for gg, gtab in pairs(conf.groups) do
- if gtab.subgroups[g] then
- table.remove(gtab.subgroups, gtab.subgroups[g])
- gtab.subgroups[g] = nil
- gtab.changed_tables()
- log.state("Removed:", g, "from subgroup membership of", gg)
- end
- end
- conf.groups[g] = nil
- reason = "Delete group " .. g
+ for gg, gtab in pairs(conf.groups) do
+ if gtab.subgroups[g] then
+ table.remove(gtab.subgroups, gtab.subgroups[g])
+ gtab.subgroups[g] = nil
+ gtab.changed_tables()
+ log.state("Removed:", g, "from subgroup membership of", gg)
+ end
+ end
+ conf.groups[g] = nil
+ reason = "Delete group " .. g
end
elseif cmdline[2] == "rename" then
local g = cmdline[3]
if not conf.groups[g] then
- log.fatal("Unknown group", g)
+ log.fatal("Unknown group", g)
end
local newg = cmdline[4]
if conf.groups[newg] then
- log.fatal("New group", newg, "already exists.")
+ log.fatal("New group", newg, "already exists.")
end
local token = conf.repo:generate_confirmation("rename group " .. g ..
- " to " .. newg)
+ " to " .. newg)
if not cmdline[5] then
- log.state("In order to rename group", g, "to", newg,
- "you must supply the following token:")
- log.state(token)
+ log.state("In order to rename group", g, "to", newg,
+ "you must supply the following token:")
+ log.state(token)
elseif cmdline[5] ~= token and cmdline[5] ~= '--force' then
- log.fatal("Token does not match. Has someone else done administrative actions?")
+ log.fatal("Token does not match. Has someone else done administrative actions?")
else
- for gg, gtab in pairs(conf.groups) do
- if gtab.subgroups[g] then
- gtab.subgroups[gtab.subgroups[g]] = newg
- gtab.subgroups[newg] = gtab.subgroups[g]
- gtab.subgroups[g] = nil
- gtab.changed_tables()
- log.state("Renamed:", g, "to", newg,
- "in subgroup membership of", gg)
- end
- end
- conf.groups[newg] = conf.groups[g]
- conf.groups[g] = nil
- reason = "Rename group " .. g .. " to " .. newg
+ for gg, gtab in pairs(conf.groups) do
+ if gtab.subgroups[g] then
+ gtab.subgroups[gtab.subgroups[g]] = newg
+ gtab.subgroups[newg] = gtab.subgroups[g]
+ gtab.subgroups[g] = nil
+ gtab.changed_tables()
+ log.state("Renamed:", g, "to", newg,
+ "in subgroup membership of", gg)
+ end
+ end
+ conf.groups[newg] = conf.groups[g]
+ conf.groups[g] = nil
+ reason = "Rename group " .. g .. " to " .. newg
end
elseif cmdline[2] == "adduser" then
- local g, gtab, u, utab =
- cmdline[3], conf.groups[cmdline[3]],
- cmdline[4], conf.users[cmdline[4]]
+ local g, gtab, u, utab =
+ cmdline[3], conf.groups[cmdline[3]],
+ cmdline[4], conf.users[cmdline[4]]
if not gtab then
- log.fatal("Unknown group", g)
+ log.fatal("Unknown group", g)
end
if not utab then
- log.fatal("Unknown user", u)
+ log.fatal("Unknown user", u)
end
if not gtab.members[u] then
- gtab.members[#gtab.members+1] = u
- gtab.members[u] = #gtab.members
- gtab.changed_tables()
- reason = "Add " .. u .. " to " .. g
+ gtab.members[#gtab.members+1] = u
+ gtab.members[u] = #gtab.members
+ gtab.changed_tables()
+ reason = "Add " .. u .. " to " .. g
else
- log.state("User", u, "already a member of", g)
+ log.state("User", u, "already a member of", g)
end
elseif cmdline[2] == "deluser" then
- local g, gtab, u, utab =
- cmdline[3], conf.groups[cmdline[3]],
- cmdline[4], conf.users[cmdline[4]]
+ local g, gtab, u, utab =
+ cmdline[3], conf.groups[cmdline[3]],
+ cmdline[4], conf.users[cmdline[4]]
if not gtab then
- log.fatal("Unknown group", g)
+ log.fatal("Unknown group", g)
end
if not utab then
- log.fatal("Unknown user", u)
+ log.fatal("Unknown user", u)
end
if not gtab.members[u] then
- log.fatal("User", u, "is not a member of", g)
+ log.fatal("User", u, "is not a member of", g)
end
local token = conf.repo:generate_confirmation("delete user " .. u ..
- " from group " .. g)
+ " from group " .. g)
if not cmdline[5] then
- log.state("To delete user", u, "from group", g, "you will need this token:")
- log.state(token)
+ log.state("To delete user", u, "from group", g, "you will need this token:")
+ log.state(token)
elseif cmdline[5] ~= token and cmdline[5] ~= '--force' then
- log.fatal("Token does not match. Did someone else do administrative actions?")
+ log.fatal("Token does not match. Did someone else do administrative actions?")
else
- table.remove(gtab.members, gtab.members[u])
- gtab.members[u] = nil
- gtab.changed_tables()
- reason = "Remove " .. u .. " from " .. g
+ table.remove(gtab.members, gtab.members[u])
+ gtab.members[u] = nil
+ gtab.changed_tables()
+ reason = "Remove " .. u .. " from " .. g
end
elseif cmdline[2] == "addgroup" then
- local g, gtab, g2, g2tab =
- cmdline[3], conf.groups[cmdline[3]],
- cmdline[4], conf.groups[cmdline[4]]
+ local g, gtab, g2, g2tab =
+ cmdline[3], conf.groups[cmdline[3]],
+ cmdline[4], conf.groups[cmdline[4]]
if not gtab then
- log.fatal("Unknown group", g)
+ log.fatal("Unknown group", g)
end
if not g2tab then
- log.fatal("Unknown group", g2)
+ log.fatal("Unknown group", g2)
end
if not gtab.subgroups[g2] then
- gtab.subgroups[#gtab.subgroups+1] = g2
- gtab.subgroups[g2] = #gtab.subgroups
- gtab.changed_tables()
- reason = "Add group " .. g2 .. " to " .. g
+ gtab.subgroups[#gtab.subgroups+1] = g2
+ gtab.subgroups[g2] = #gtab.subgroups
+ gtab.changed_tables()
+ reason = "Add group " .. g2 .. " to " .. g
else
- log.state("Group", g2, "already a subgroup of", g)
+ log.state("Group", g2, "already a subgroup of", g)
end
elseif cmdline[2] == "delgroup" then
- local g, gtab, g2, g2tab =
- cmdline[3], conf.groups[cmdline[3]],
- cmdline[4], conf.groups[cmdline[4]]
+ local g, gtab, g2, g2tab =
+ cmdline[3], conf.groups[cmdline[3]],
+ cmdline[4], conf.groups[cmdline[4]]
if not gtab then
- log.fatal("Unknown group", g)
+ log.fatal("Unknown group", g)
end
if not g2tab then
- log.fatal("Unknown group", g2)
+ log.fatal("Unknown group", g2)
end
if not gtab.subgroups[g2] then
- log.fatal("Group", g2, "is not a subgroup of", g)
+ log.fatal("Group", g2, "is not a subgroup of", g)
end
local token = conf.repo:generate_confirmation("delete group " .. g ..
- "from group " .. g2)
+ "from group " .. g2)
if not cmdline[5] then
- log.state("To delete group", g2, "from group", g, "you will need this token:")
- log.state(token)
+ log.state("To delete group", g2, "from group", g, "you will need this token:")
+ log.state(token)
elseif cmdline[5] ~= token and cmdline[5] ~= '--force' then
- log.fatal("Token does not match. Did someone else do administrative actions?")
+ log.fatal("Token does not match. Did someone else do administrative actions?")
else
- table.remove(gtab.subgroups, gtab.subgroups[g2])
- gtab.members[g2] = nil
- gtab.changed_tables()
- reason = "Remove group " .. g2 .. " from " .. g
+ table.remove(gtab.subgroups, gtab.subgroups[g2])
+ gtab.members[g2] = nil
+ gtab.changed_tables()
+ reason = "Remove group " .. g2 .. " from " .. g
end
else
log.fatal("Unknown sub command", cmdline[2])
@@ -635,7 +635,7 @@ local function builtin_group_run(conf, _, cmdline, env)
if reason then
local ok, commit = config.commit(conf, reason, env.GITANO_USER, env.GITANO_ORIG_USER)
if not ok then
- log.fatal(commit)
+ log.fatal(commit)
end
log.state("Committed: " .. reason)
end
@@ -678,57 +678,57 @@ local function builtin_keyring_validate(conf, _, cmdline)
end
if cmdline[2] == "list" then
if #cmdline == 2 then
- return true
+ return true
end
log.error("usage: keyring list")
end
if cmdline[2] == "create" then
if #cmdline == 3 then
- return true
+ return true
end
log.error("usage: keyring create <keyring>")
end
if cmdline[2] == "destroy" then
if #cmdline == 3 or #cmdline == 4 then
- return true
+ return true
end
log.error("usage: keyring destroy <keyring> [<token>]")
end
if cmdline[2] == "show" then
if #cmdline == 3 then
- return true
+ return true
end
log.error("usage: keyring show <keyring>")
end
if cmdline[2] == "import" then
if #cmdline == 3 then
- return true
+ return true
end
log.error("usage: keyring import <keyring>")
end
if cmdline[2] == "export" then
if #cmdline == 3 then
- return true
+ return true
end
if #cmdline > 3 then
- local ok = true
- for i = 4, #cmdline do
- if not cmdline[i]:match("^" .. string.rep("[0-9A-Fa-f]", 40) .. "$") then
- log.error("error: '" .. cmdline[i] .. "' is not a valid fingerprint")
- ok = false
- end
- end
- return ok
+ local ok = true
+ for i = 4, #cmdline do
+ if not cmdline[i]:match("^" .. string.rep("[0-9A-Fa-f]", 40) .. "$") then
+ log.error("error: '" .. cmdline[i] .. "' is not a valid fingerprint")
+ ok = false
+ end
+ end
+ return ok
end
log.error("usage: keyring export <keyring> [<fingerprint>...]")
end
if cmdline[2] == "delkey" then
if #cmdline == 4 or #cmdline == 5 then
- if not cmdline[4]:match("^" .. string.rep("[0-9A-Fa-f]", 40) .. "$") then
- log.error("error: '" .. cmdline[i] .. "' is not a valid fingerprint")
- return false
- end
- return true
+ if not cmdline[4]:match("^" .. string.rep("[0-9A-Fa-f]", 40) .. "$") then
+ log.error("error: '" .. cmdline[i] .. "' is not a valid fingerprint")
+ return false
+ end
+ return true
end
log.error("usage: keyring delkey <keyring> <fingerprint> [<token>]")
end
@@ -752,57 +752,57 @@ local function builtin_keyring_run(conf, _, cmdline, env)
if cmdline[2] == "list" then
local keyrings = {}
for k, ktab in pairs(conf.keyrings) do
- local ctx = util.deep_copy(cmdline._stolen_context)
- ctx.keyring = k
- local result = conf.repo:run_lace(ctx)
- if result == "allow" then keyrings[#keyrings+1] = k end
+ local ctx = util.deep_copy(cmdline._stolen_context)
+ ctx.keyring = k
+ local result = conf.repo:run_lace(ctx)
+ if result == "allow" then keyrings[#keyrings+1] = k end
end
table.sort(keyrings)
for _, k in ipairs(keyrings) do
- log.stdout(k)
+ log.stdout(k)
end
end
local reason = nil
if cmdline[2] == "create" then
local keyringname = cmdline[3]
if conf.keyrings[keyringname] then
- log.error("Keyring " .. keyringname .. " already exists")
- return "exit", 1
+ log.error("Keyring " .. keyringname .. " already exists")
+ return "exit", 1
end
if not keyringname:match("^[a-z][a-z0-9_.-]+$") then
- log.error("Keyring " .. keyringname .. " is not lower-alphanumeric")
- return "exit", 1
+ log.error("Keyring " .. keyringname .. " is not lower-alphanumeric")
+ return "exit", 1
end
local emptysha = conf.repo.git:hash_object("blob", "", true)
conf.keyrings[keyringname] = {
- meta = { prefix = "keyrings/" },
- blob = conf.repo.git:get(emptysha)
+ meta = { prefix = "keyrings/" },
+ blob = conf.repo.git:get(emptysha)
}
reason = "create keyring " .. keyringname
end
if cmdline[2] == "destroy" then
local keyringname = cmdline[3]
if not conf.keyrings[keyringname] then
- log.error("Keyring " .. keyringname .. " does not exist")
- return "exit", 1
+ log.error("Keyring " .. keyringname .. " does not exist")
+ return "exit", 1
end
local token = conf.repo:generate_confirmation("keyring destroy " .. keyringname)
if not cmdline[4] then
- log.state("In order to destroy", keyringname, "you must supply the following token:")
- log.state(token)
+ log.state("In order to destroy", keyringname, "you must supply the following token:")
+ log.state(token)
elseif cmdline[4] ~= token and cmdline[4] ~= '--force' then
- log.error("Tokens do not match. Did someone else do administrative actions?")
- return "exit", 1
+ log.error("Tokens do not match. Did someone else do administrative actions?")
+ return "exit", 1
else
- conf.keyrings[keyringname] = nil
- reason = "destroy keyring " .. keyringname
+ conf.keyrings[keyringname] = nil
+ reason = "destroy keyring " .. keyringname
end
end
if cmdline[2] == "show" then
local keyringname = cmdline[3]
if not conf.keyrings[keyringname] then
- log.error("Keyring " .. keyringname .. " does not exist")
- return "exit", 1
+ log.error("Keyring " .. keyringname .. " does not exist")
+ return "exit", 1
end
local fd, filename = util.tempfile(conf.repo)
local sfd = sio.wrap_fd(fd, false, filename)
@@ -810,28 +810,28 @@ local function builtin_keyring_run(conf, _, cmdline, env)
local w = 0
local _b, err
while w < #b do
- _b, err = sfd:write(b, w)
- if _b == nil or _b < 1 then
- -- I know we're not handling EINTR/EAGAIN, I don't care
- w = -1
- break
- end
- w = w + _b
+ _b, err = sfd:write(b, w)
+ if _b == nil or _b < 1 then
+ -- I know we're not handling EINTR/EAGAIN, I don't care
+ w = -1
+ break
+ end
+ w = w + _b
end
sfd:close()
if w == -1 then
- -- Failure to write keyring out...
- luxio.unlink(filename)
- log.fatal("Unable to write keyring out: " .. err)
+ -- Failure to write keyring out...
+ luxio.unlink(filename)
+ log.fatal("Unable to write keyring out: " .. err)
end
-- Keyring was written out, now we need to get GPG to add stdin to it...
local null = luxio.open("/dev/null", luxio.O_RDWR)
local proc = sp.spawn_simple({
- "gpg", "--no-default-keyring", "--keyring", filename,
- "--primary-keyring", filename, "--with-colons", "--fingerprint",
- "--list-keys",
- stdout = sp.PIPE,
- stderr = null,
+ "gpg", "--no-default-keyring", "--keyring", filename,
+ "--primary-keyring", filename, "--with-colons", "--fingerprint",
+ "--list-keys",
+ stdout = sp.PIPE,
+ stderr = null,
})
luxio.close(null)
local alloutput = proc.stdout:read("*a")
@@ -839,17 +839,17 @@ local function builtin_keyring_run(conf, _, cmdline, env)
local _, code = proc:wait()
luxio.unlink(filename)
if code ~= 0 then
- log.fatal("Unable to list keyring: GPG returned " .. tostring(code))
+ log.fatal("Unable to list keyring: GPG returned " .. tostring(code))
end
for fingerprint in alloutput:gmatch("fpr:::::::::([0-9A-F]+):") do
- log.stdout(fingerprint)
+ log.stdout(fingerprint)
end
end
if cmdline[2] == "import" then
local keyringname = cmdline[3]
if not conf.keyrings[keyringname] then
- log.error("Keyring " .. keyringname .. " does not exist")
- return "exit", 1
+ log.error("Keyring " .. keyringname .. " does not exist")
+ return "exit", 1
end
local fd, filename = util.tempfile(conf.repo)
local sfd = sio.wrap_fd(fd, false, filename)
@@ -857,50 +857,50 @@ local function builtin_keyring_run(conf, _, cmdline, env)
local w = 0
local _b, err
while w < #b do
- _b, err = sfd:write(b, w)
- if _b == nil or _b < 1 then
- -- I know we're not handling EINTR/EAGAIN, I don't care
- w = -1
- break
- end
- w = w + _b
+ _b, err = sfd:write(b, w)
+ if _b == nil or _b < 1 then
+ -- I know we're not handling EINTR/EAGAIN, I don't care
+ w = -1
+ break
+ end
+ w = w + _b
end
sfd:close()
if w == -1 then
- -- Failure to write keyring out...
- luxio.unlink(filename)
- log.fatal("Unable to write keyring out: " .. err)
+ -- Failure to write keyring out...
+ luxio.unlink(filename)
+ log.fatal("Unable to write keyring out: " .. err)
end
-- Keyring was written out, now we need to get GPG to add stdin to it...
local null = luxio.open("/dev/null", luxio.O_RDWR)
local proc = sp.spawn_simple({
- "gpg", "--no-default-keyring", "--keyring", filename,
- "--primary-keyring", filename, "--import",
- stdout = null,
- stderr = null,
+ "gpg", "--no-default-keyring", "--keyring", filename,
+ "--primary-keyring", filename, "--import",
+ stdout = null,
+ stderr = null,
})
luxio.close(null)
local _, code = proc:wait()
if code ~= 0 then
- luxio.unlink(filename)
- log.fatal("Unable to update keyring: GPG returned " .. tostring(code))
+ luxio.unlink(filename)
+ log.fatal("Unable to update keyring: GPG returned " .. tostring(code))
end
-- Keyring was updated, need to reload it...
local ret, sdat = luxio.lstat(filename)
if ret ~= 0 then
- luxio.unlink(filename)
- log.fatal("Unable to stat keyring")
+ luxio.unlink(filename)
+ log.fatal("Unable to stat keyring")
end
if sdat.size > MAX_KEYRING_SIZE then
- luxio.unlink(filename)
- log.fatal("Unable to update keyring, size " .. tostring(sdat.size) ..
- " is more than maximum size of " .. tostring(MAX_KEYRING_SIZE))
+ luxio.unlink(filename)
+ log.fatal("Unable to update keyring, size " .. tostring(sdat.size) ..
+ " is more than maximum size of " .. tostring(MAX_KEYRING_SIZE))
end
-- Load the keyring into an object
sfd, err = sio.open(filename, "r")
if not sfd then
- luxio.unlink(filename)
- log.fatal("Unable to update keyring, cannot reload it: " .. err)
+ luxio.unlink(filename)
+ log.fatal("Unable to update keyring, cannot reload it: " .. err)
end
b = sfd:read("*a")
sfd:close()
@@ -913,8 +913,8 @@ local function builtin_keyring_run(conf, _, cmdline, env)
if cmdline[2] == "export" then
local keyringname = cmdline[3]
if not conf.keyrings[keyringname] then
- log.error("Keyring " .. keyringname .. " does not exist")
- return "exit", 1
+ log.error("Keyring " .. keyringname .. " does not exist")
+ return "exit", 1
end
local fd, filename = util.tempfile(conf.repo)
local sfd = sio.wrap_fd(fd, false, filename)
@@ -922,36 +922,36 @@ local function builtin_keyring_run(conf, _, cmdline, env)
local w = 0
local _b, err
while w < #b do
- _b, err = sfd:write(b, w)
- if _b == nil or _b < 1 then
- -- I know we're not handling EINTR/EAGAIN, I don't care
- w = -1
- break
- end
- w = w + _b
+ _b, err = sfd:write(b, w)
+ if _b == nil or _b < 1 then
+ -- I know we're not handling EINTR/EAGAIN, I don't care
+ w = -1
+ break
+ end
+ w = w + _b
end
sfd:close()
if w == -1 then
- -- Failure to write keyring out...
- luxio.unlink(filename)
- log.fatal("Unable to write keyring out: " .. err)
+ -- Failure to write keyring out...
+ luxio.unlink(filename)
+ log.fatal("Unable to write keyring out: " .. err)
end
-- Keyring was written out, now we need to get GPG to add stdin to it...
local null = luxio.open("/dev/null", luxio.O_RDWR)
local args = {
- "gpg", "--no-default-keyring", "--keyring", filename,
- "--primary-keyring", filename, "--armor", "--export",
- stderr = null,
+ "gpg", "--no-default-keyring", "--keyring", filename,
+ "--primary-keyring", filename, "--armor", "--export",
+ stderr = null,
}
for i = 4, #cmdline do
- args[#args+1] = cmdline[i]
+ args[#args+1] = cmdline[i]
end
local proc = sp.spawn_simple(args)
luxio.close(null)
local _, code = proc:wait()
luxio.unlink(filename)
if code ~= 0 then
- log.fatal("Unable to export keys: GPG returned " .. tostring(code))
+ log.fatal("Unable to export keys: GPG returned " .. tostring(code))
end
end
if cmdline[2] == "delkey" then
@@ -959,17 +959,17 @@ local function builtin_keyring_run(conf, _, cmdline, env)
local fingerprint = cmdline[4]
local token = conf.repo:generate_confirmation("delkey " .. keyringname .. fingerprint)
if not conf.keyrings[keyringname] then
- log.error("Keyring " .. keyringname .. " does not exist")
- return "exit", 1
+ log.error("Keyring " .. keyringname .. " does not exist")
+ return "exit", 1
end
if not cmdline[5] then
- log.state("In order to remove", fingerprint, "from", keyringname,
- "you must supply the following token:")
- log.state(token)
- return "exit", 0
+ log.state("In order to remove", fingerprint, "from", keyringname,
+ "you must supply the following token:")
+ log.state(token)
+ return "exit", 0
elseif cmdline[5] ~= token and cmdline[5] ~= '--force' then
- log.error("Tokens do not match. Did someone else do administrative actions?")
- return "exit", 1
+ log.error("Tokens do not match. Did someone else do administrative actions?")
+ return "exit", 1
end
local fd, filename = util.tempfile(conf.repo)
local sfd = sio.wrap_fd(fd, false, filename)
@@ -977,50 +977,50 @@ local function builtin_keyring_run(conf, _, cmdline, env)
local w = 0
local _b, err
while w < #b do
- _b, err = sfd:write(b, w)
- if _b == nil or _b < 1 then
- -- I know we're not handling EINTR/EAGAIN, I don't care
- w = -1
- break
- end
- w = w + _b
+ _b, err = sfd:write(b, w)
+ if _b == nil or _b < 1 then
+ -- I know we're not handling EINTR/EAGAIN, I don't care
+ w = -1
+ break
+ end
+ w = w + _b
end
sfd:close()
if w == -1 then
- -- Failure to write keyring out...
- luxio.unlink(filename)
- log.fatal("Unable to write keyring out: " .. err)
+ -- Failure to write keyring out...
+ luxio.unlink(filename)
+ log.fatal("Unable to write keyring out: " .. err)
end
-- Keyring was written out, now we need to get GPG to add stdin to it...
local null = luxio.open("/dev/null", luxio.O_RDWR)
local proc = sp.spawn_simple({
- "gpg", "--no-default-keyring", "--keyring", filename,
- "--primary-keyring", filename, "--batch", "--delete-key", fingerprint,
- stdout = null,
- stderr = null,
+ "gpg", "--no-default-keyring", "--keyring", filename,
+ "--primary-keyring", filename, "--batch", "--delete-key", fingerprint,
+ stdout = null,
+ stderr = null,
})
luxio.close(null)
local _, code = proc:wait()
if code ~= 0 then
- luxio.unlink(filename)
- log.fatal("Unable to update keyring: GPG returned " .. tostring(code))
+ luxio.unlink(filename)
+ log.fatal("Unable to update keyring: GPG returned " .. tostring(code))
end
-- Keyring was updated, need to reload it...
local ret, sdat = luxio.lstat(filename)
if ret ~= 0 then
- luxio.unlink(filename)
- log.fatal("Unable to stat keyring")
+ luxio.unlink(filename)
+ log.fatal("Unable to stat keyring")
end
if sdat.size > MAX_KEYRING_SIZE then
- luxio.unlink(filename)
- log.fatal("Unable to update keyring, size " .. tostring(sdat.size) ..
- " is more than maximum size of " .. tostring(MAX_KEYRING_SIZE))
+ luxio.unlink(filename)
+ log.fatal("Unable to update keyring, size " .. tostring(sdat.size) ..
+ " is more than maximum size of " .. tostring(MAX_KEYRING_SIZE))
end
-- Load the keyring into an object
sfd, err = sio.open(filename, "r")
if not sfd then
- luxio.unlink(filename)
- log.fatal("Unable to update keyring, cannot reload it: " .. err)
+ luxio.unlink(filename)
+ log.fatal("Unable to update keyring, cannot reload it: " .. err)
end
b = sfd:read("*a")
sfd:close()
@@ -1034,7 +1034,7 @@ local function builtin_keyring_run(conf, _, cmdline, env)
-- Need to try and make a config commit
local ok, commit = config.commit(conf, reason, env.GITANO_USER, env.GITANO_ORIG_USER)
if not ok then
- log.fatal(commit)
+ log.fatal(commit)
end
log.state("Committed: " .. reason)
end
@@ -1065,23 +1065,23 @@ local function builtin_graveyard_validate(conf, _, cmdline)
end
if cmdline[2] == "list" then
if #cmdline == 2 then
- return true
+ return true
end
log.error("usage: graveyard list")
end
if cmdline[2] == "restore" then
if #cmdline == 4 then
- cmdline[3] = cmdline[3]:gsub("/", "")
- return true
+ cmdline[3] = cmdline[3]:gsub("/", "")
+ return true
end
log.error("usage: graveyard restore <entry> <name>")
end
if cmdline[2] == "purge" then
if #cmdline < 4 then
- if cmdline[3] then
- cmdline[3] = cmdline[3]:gsub("/", "")
- end
- return true
+ if cmdline[3] then
+ cmdline[3] = cmdline[3]:gsub("/", "")
+ end
+ return true
end
log.error("usage: graveyard purge [<entry>]")
end
@@ -1112,90 +1112,90 @@ local function builtin_graveyard_run(conf, _, cmdline, env)
-- List the contents of the graveyard.
local dirp, err = luxio.opendir(graveyard_base)
if not dirp then
- if err == luxio.ENOTDIR then
- log.error("Graveyard is not present, or empty")
- return "exit", 1
- end
- log.error("Error opening graveyard: " .. luxio.strerror(err))
- return "exit", 1
+ if err == luxio.ENOTDIR then
+ log.error("Graveyard is not present, or empty")
+ return "exit", 1
+ end
+ log.error("Error opening graveyard: " .. luxio.strerror(err))
+ return "exit", 1
end
local e, i
repeat
- e, i = luxio.readdir(dirp)
- if e == 0 then
- if not i.d_name:find("^%.") then
- log.stdout(i.d_name)
- end
- end
+ e, i = luxio.readdir(dirp)
+ if e == 0 then
+ if not i.d_name:find("^%.") then
+ log.stdout(i.d_name)
+ end
+ end
until not e
dirp = nil -- Allow GC of DIR handle
elseif cmdline[2] == "restore" then
-- Restoring a repository needs the prefix dirs to be made
local temp_repo, msg = repository.find(conf, cmdline[4])
if not temp_repo then
- log.error("Unable to proceed: " .. msg)
- return "exit", 1
+ log.error("Unable to proceed: " .. msg)
+ return "exit", 1
end
local repo_path = temp_repo:fs_path()
local restore_src = graveyard_base .. cmdline[3]
-- Prepare the path towards the repo...
local ok, msg = util.mkdir_p(util.dirname(repo_path))
if not ok then
- log.error("Unable to proceed: " .. msg)
- return "exit", 1
+ log.error("Unable to proceed: " .. msg)
+ return "exit", 1
end
-- Restore the repository
log.info("Trying to restore", cmdline[3], "as", cmdline[4])
log.ddebug(restore_src, "=>", repo_path)
local e, errno = luxio.rename(restore_src, repo_path)
if e ~= 0 then
- log.error("Restore failed. Could not rename: " .. luxio.strerror(errno))
- return "exit", 1
+ log.error("Restore failed. Could not rename: " .. luxio.strerror(errno))
+ return "exit", 1
end
-- Re-find the repository
local repo, msg = repository.find(conf, cmdline[4])
if not repo then
- log.error("Restore failed. Could not find restored repo: " .. msg)
- return "exit", 1
+ log.error("Restore failed. Could not find restored repo: " .. msg)
+ return "exit", 1
end
elseif cmdline[2] == "purge" then
local match = cmdline[3]
local to_remove = {}
local dirp, err = luxio.opendir(graveyard_base)
if not dirp then
- if err == luxio.ENOTDIR then
- log.error("Graveyard is not present, or empty")
- return "exit", 1
- end
- log.error("Error opening graveyard: " .. luxio.strerror(err))
- return "exit", 1
+ if err == luxio.ENOTDIR then
+ log.error("Graveyard is not present, or empty")
+ return "exit", 1
+ end
+ log.error("Error opening graveyard: " .. luxio.strerror(err))
+ return "exit", 1
end
local e, i
repeat
- e, i = luxio.readdir(dirp)
- if e == 0 then
- if not i.d_name:find("^%.") then
- if not match or (match == i.d_name) then
- to_remove[#to_remove+1] = i.d_name
- end
- end
- end
+ e, i = luxio.readdir(dirp)
+ if e == 0 then
+ if not i.d_name:find("^%.") then
+ if not match or (match == i.d_name) then
+ to_remove[#to_remove+1] = i.d_name
+ end
+ end
+ end
until not e
dirp = nil -- Allow GC of DIR handle
if #to_remove == 0 then
- if match then
- log.error("Unable to find", match, "to remove")
- else
- log.error("Nothing in the graveyard to purge")
- end
- return "exit", 1
+ if match then
+ log.error("Unable to find", match, "to remove")
+ else
+ log.error("Nothing in the graveyard to purge")
+ end
+ return "exit", 1
end
for i = 1, #to_remove do
- log.state("Purging", to_remove[i], "from graveyard...")
- local ok, msg = util.rm_rf(graveyard_base .. to_remove[i])
- if not ok then
- log.error("Unable to remove:", msg)
- end
+ log.state("Purging", to_remove[i], "from graveyard...")
+ local ok, msg = util.rm_rf(graveyard_base .. to_remove[i])
+ if not ok then
+ log.error("Unable to remove:", msg)
+ end
end
end
return "exit", 0
@@ -1203,24 +1203,24 @@ end
local function register_commands(reg)
assert(reg("as", builtin_as_short, builtin_as_helptext,
- builtin_as_validate, builtin_as_prep, builtin_as_run,
- false, false, true))
+ builtin_as_validate, builtin_as_prep, builtin_as_run,
+ false, false, true))
assert(reg("user", builtin_user_short, builtin_user_helptext,
- builtin_user_validate, builtin_user_prep,
- builtin_user_run, false, false, true))
+ builtin_user_validate, builtin_user_prep,
+ builtin_user_run, false, false, true))
assert(reg("group", builtin_group_short, builtin_group_helptext,
- builtin_group_validate, builtin_group_prep,
- builtin_group_run, false, false, true))
+ builtin_group_validate, builtin_group_prep,
+ builtin_group_run, false, false, true))
assert(reg("keyring", builtin_keyring_short, builtin_keyring_helptext,
- builtin_keyring_validate, builtin_keyring_prep,
- builtin_keyring_run, false, false, true))
+ builtin_keyring_validate, builtin_keyring_prep,
+ builtin_keyring_run, false, false, true))
assert(reg("graveyard", builtin_graveyard_short, builtin_graveyard_helptext,
- builtin_graveyard_validate, builtin_graveyard_prep,
- builtin_graveyard_run, false, false, true))
+ builtin_graveyard_validate, builtin_graveyard_prep,
+ builtin_graveyard_run, false, false, true))
end
diff --git a/lib/gitano/auth.lua b/lib/gitano/auth.lua
index 2fd3740..15d1fb3 100644
--- a/lib/gitano/auth.lua
+++ b/lib/gitano/auth.lua
@@ -9,7 +9,7 @@ local luxio = require 'luxio'
local function load_admin_conf(repo_root)
local admin_repo = gall.repository.new((repo_root or "") ..
- "/gitano-admin.git")
+ "/gitano-admin.git")
if not admin_repo then
log.critical(i18n.expand("ERROR_CANNOT_FIND_ADMIN_REPO"))
@@ -86,7 +86,7 @@ local function is_authorized(user, source, cmdline, repo_root,
ip = os.getenv("REMOTE_ADDR") or "unknown ip"
log.syslog.info(
i18n.expand("CLIENT_CONNECTED",
- { ip=ip, user=user, key=keytag, cmdline=cmdline}))
+ { ip=ip, user=user, key=keytag, cmdline=cmdline}))
local cmd = command.get(parsed_cmdline[1])
@@ -99,7 +99,7 @@ local function is_authorized(user, source, cmdline, repo_root,
if cmd.takes_repo and #parsed_cmdline >= 1 then
repo, parsed_cmdline = cmd.detect_repo(admin_conf, parsed_cmdline)
if not repo and not parsed_cmdline then
- return nil
+ return nil
end
end
diff --git a/lib/gitano/command.lua b/lib/gitano/command.lua
index 0fa8be8..9b83c01 100644
--- a/lib/gitano/command.lua
+++ b/lib/gitano/command.lua
@@ -34,14 +34,14 @@ local function default_detect_repo(config, parsed_cmdline)
end
local function register_cmd(cmdname, short, helptext,
- validate_fn, prep_fn, run_fn,
- takes_repo, hidden, is_admin, detect_repo,
- suppress_error_msgs)
+ validate_fn, prep_fn, run_fn,
+ takes_repo, hidden, is_admin, detect_repo,
+ suppress_error_msgs)
--[[
- log.ddebug("Register command", cmdname)
- if takes_repo then
+ log.ddebug("Register command", cmdname)
+ if takes_repo then
log.ddebug(" => Takes a repo")
- end
+ end
--]]
if cmds[cmdname] then
log.warn("Attempt to double-register", cmdname)
@@ -100,11 +100,11 @@ local function builtin_help_validate(config, repo, cmdline)
end
if #cmdline == 2 then
if cmdline[2] == "all" or cmdline[2] == "admin" then
- return true
+ return true
end
if not cmds[cmdline[2]] then
- log.error("Unknown command:", help)
- return false
+ log.error("Unknown command:", help)
+ return false
end
end
return true
@@ -117,10 +117,10 @@ end
local function builtin_help_run(config, repo, cmdline, env)
local function do_want(cmd)
if cmdline[2] == "all" then
- return true
+ return true
end
if cmdline[2] == "admin" then
- return cmd.admin
+ return cmd.admin
end
return not (cmd.hidden or cmd.admin)
end
@@ -133,46 +133,46 @@ local function builtin_help_run(config, repo, cmdline, env)
-- List all commands
local maxcmdn = 0
for i = 1, #cmds do
- local cmd = cmds[cmds[i]]
- local wanted = do_want(cmd)
- if wanted then
- if #cmd.name > maxcmdn then
- maxcmdn = #cmd.name
- end
- end
+ local cmd = cmds[cmds[i]]
+ local wanted = do_want(cmd)
+ if wanted then
+ if #cmd.name > maxcmdn then
+ maxcmdn = #cmd.name
+ end
+ end
end
for i = 1, #cmds do
- local cmd = cmds[cmds[i]]
- local wanted = do_want(cmd)
- if wanted then
- local gap = (" "):rep(maxcmdn - #cmd.name)
- local desc = (cmd.short or "No description")
- if cmd.takes_repo then
- desc = desc .. " (Takes a repo)"
- end
- log.state(gap .. cmd.name, do_sep(cmd), desc)
- end
+ local cmd = cmds[cmds[i]]
+ local wanted = do_want(cmd)
+ if wanted then
+ local gap = (" "):rep(maxcmdn - #cmd.name)
+ local desc = (cmd.short or "No description")
+ if cmd.takes_repo then
+ desc = desc .. " (Takes a repo)"
+ end
+ log.state(gap .. cmd.name, do_sep(cmd), desc)
+ end
end
else
local cmd = cmds[cmdline[2]]
local desc = (cmd.short or "No description")
if cmd.takes_repo then
- desc = desc .. " (Takes a repo)"
+ desc = desc .. " (Takes a repo)"
end
log.state(cmd.name, do_sep(cmd), desc)
if cmd.helptext then
- log.state("")
- for line in (cmd.helptext):gmatch("([^\n]*)\n") do
- log.state("=>", line)
- end
+ log.state("")
+ for line in (cmd.helptext):gmatch("([^\n]*)\n") do
+ log.state("=>", line)
+ end
end
end
return "exit", 0
end
assert(register_cmd("help", builtin_help_short, builtin_help_helptext,
- builtin_help_validate, builtin_help_prep,
- builtin_help_run, false, false))
+ builtin_help_validate, builtin_help_prep,
+ builtin_help_run, false, false))
local function builtin_upload_pack_validate(config, repo, cmdline)
-- git-upload-pack repo
@@ -199,10 +199,10 @@ local function builtin_upload_pack_run(config, repo, cmdline, env)
end
assert(register_cmd("git-upload-pack", nil, nil,
- builtin_upload_pack_validate,
- builtin_upload_pack_prep,
- builtin_upload_pack_run,
- true, true))
+ builtin_upload_pack_validate,
+ builtin_upload_pack_prep,
+ builtin_upload_pack_run,
+ true, true))
local function builtin_receive_pack_validate(config, repo, cmdline)
-- git-receive-pack repo
@@ -236,10 +236,10 @@ local function builtin_receive_pack_run(config, repo, cmdline, env)
end
assert(register_cmd("git-receive-pack", nil, nil,
- builtin_receive_pack_validate,
- builtin_receive_pack_prep,
- builtin_receive_pack_run,
- true, true))
+ builtin_receive_pack_validate,
+ builtin_receive_pack_prep,
+ builtin_receive_pack_run,
+ true, true))
local builtin_create_short = "Create a new repository"
local builtin_create_helptext = [[
@@ -286,7 +286,7 @@ local function builtin_create_run(config, repo, cmdline, env)
local owner = cmdline[3] or env["GITANO_USER"]
log.chat("Setting repository owner to", owner)
ok, msg = repo:conf_set_and_save("project.owner", owner,
- env.GITANO_USER, env.GITANO_ORIG_USER)
+ env.GITANO_USER, env.GITANO_ORIG_USER)
if not ok then
log.error(msg)
return "exit", 1
@@ -297,14 +297,14 @@ local function builtin_create_run(config, repo, cmdline, env)
log.error(msg)
return "exit", 1
end
- log.state("Repository", repo.name,
- "created ok. Remember to configure rules etc.")
+ log.state("Repository", repo.name,
+ "created ok. Remember to configure rules etc.")
return "exit", 0
end
assert(register_cmd("create", builtin_create_short, builtin_create_helptext,
- builtin_create_validate, builtin_create_prep,
- builtin_create_run, true, false))
+ builtin_create_validate, builtin_create_prep,
+ builtin_create_run, true, false))
local builtin_config_short = "View and change configuration for a repository"
local builtin_config_helptext = [[
@@ -348,39 +348,39 @@ local function builtin_config_validate(conf, repo, cmdline)
-- No validation to do yet
elseif cmdline[3] == "set" then
if #cmdline < 5 then
- log.error("config <repo> set: takes a key and a value to set")
- return false
+ log.error("config <repo> set: takes a key and a value to set")
+ return false
end
if #cmdline > 5 then
- local cpy = {}
- for i = #cmdline, 5, -1 do
- table.insert(cpy, 1, cmdline[i])
- cmdline[i] = nil
- end
- cmdline[5] = table.concat(cpy, " ")
+ local cpy = {}
+ for i = #cmdline, 5, -1 do
+ table.insert(cpy, 1, cmdline[i])
+ cmdline[i] = nil
+ end
+ cmdline[5] = table.concat(cpy, " ")
end
if cmdline[4] == "project.owner" then
- -- Verify that the new owner is a valid user
- if not conf.users[cmdline[5]] then
- log.error("Unknown user: " .. cmdline[5])
- return false
- end
+ -- Verify that the new owner is a valid user
+ if not conf.users[cmdline[5]] then
+ log.error("Unknown user: " .. cmdline[5])
+ return false
+ end
end
elseif cmdline[3] == "del" or cmdline[3] == "delete" or
- cmdline[3] == "rm" then
+ cmdline[3] == "rm" then
cmdline[3] = "del"
if #cmdline ~= 4 then
- log.error("config <repo> del: takes a key and nothing more")
- return false
+ log.error("config <repo> del: takes a key and nothing more")
+ return false
end
cmdline.orig_key = cmdline[4]
if cmdline[4]:match("%.%*$") then
- -- Doing a wild removal, expand it now
- local prefix = cmdline[4]:match("^(.+)%.%*$")
- cmdline[4] = nil
- for k in repo.project_config:each(prefix) do
- cmdline[#cmdline+1] = k
- end
+ -- Doing a wild removal, expand it now
+ local prefix = cmdline[4]:match("^(.+)%.%*$")
+ cmdline[4] = nil
+ for k in repo.project_config:each(prefix) do
+ cmdline[#cmdline+1] = k
+ end
end
else
log.error("Unknown subcommand <" .. cmdline[3] .. "> for config.")
@@ -394,12 +394,12 @@ local function builtin_config_prep(conf, repo, cmdline, context)
if cmdline[3] == "show" then
context.operation = "config_show"
for i = 4, #cmdline do
- local cpy = util.deep_copy(context)
- cpy.key = cmdline[i]
- local action, reason = repo:run_lace(cpy)
- if action ~= "allow" then
- return action, reason
- end
+ local cpy = util.deep_copy(context)
+ cpy.key = cmdline[i]
+ local action, reason = repo:run_lace(cpy)
+ if action ~= "allow" then
+ return action, reason
+ end
end
return "allow", "Show not denied"
elseif cmdline[3] == "set" then
@@ -410,12 +410,12 @@ local function builtin_config_prep(conf, repo, cmdline, context)
elseif cmdline[3] == "del" then
context.operation = "config_del"
for i = 4, #cmdline do
- local cpy = util.deep_copy(context)
- cpy.key = cmdline[i]
- local action, reason = repo:run_lace(cpy)
- if action ~= "allow" then
- return action, reason
- end
+ local cpy = util.deep_copy(context)
+ cpy.key = cmdline[i]
+ local action, reason = repo:run_lace(cpy)
+ if action ~= "allow" then
+ return action, reason
+ end
end
return "allow", "Delete not denied"
end
@@ -426,70 +426,70 @@ local function builtin_config_run(conf, repo, cmdline, env)
if cmdline[3] == "show" then
local all_keys = {}
if #cmdline == 3 then
- for k in repo.project_config:each() do
- all_keys[k] = true
- end
+ for k in repo.project_config:each() do
+ all_keys[k] = true
+ end
else
- for i = 4, #cmdline do
- for k in repo.project_config:each(cmdline[i]) do
- all_keys[k] = true
- end
- end
+ for i = 4, #cmdline do
+ for k in repo.project_config:each(cmdline[i]) do
+ all_keys[k] = true
+ end
+ end
end
-- Transform the all_keys set into a sorted list
local slist = {}
for k in pairs(all_keys) do
- slist[#slist+1] = k
+ slist[#slist+1] = k
end
-- TODO: Fix this sort to cope with .i_N keys neatly
table.sort(slist)
for i = 1, #slist do
- local key = slist[i]
- local value = repo.project_config.settings[key]
- local prefix = key:match("^(.+)%.i_[0-9]+$")
- if prefix then
- local neatkey = prefix .. ".*"
- for i = 4, #cmdline do
- if cmdline[i] == neatkey then
- neatkey = key
- break
- end
- end
- end
- log.stdout(key .. ": " .. value)
+ local key = slist[i]
+ local value = repo.project_config.settings[key]
+ local prefix = key:match("^(.+)%.i_[0-9]+$")
+ if prefix then
+ local neatkey = prefix .. ".*"
+ for i = 4, #cmdline do
+ if cmdline[i] == neatkey then
+ neatkey = key
+ break
+ end
+ end
+ end
+ log.stdout(key .. ": " .. value)
end
elseif cmdline[3] == "set" then
local key, value = cmdline[4], cmdline[5]
local vtype, rest = value:match("^([sbi]):(.*)$")
if vtype then
- if vtype == "s" then
- value = rest
- end
- if vtype == "i" then
- value = tonumber(rest)
- end
- if vtype == "b" then
- value = ((rest:lower() == "true") or (rest == "1") or
- (rest:lower() == "on") or (rest:lower() == "yes"))
- end
+ if vtype == "s" then
+ value = rest
+ end
+ if vtype == "i" then
+ value = tonumber(rest)
+ end
+ if vtype == "b" then
+ value = ((rest:lower() == "true") or (rest == "1") or
+ (rest:lower() == "on") or (rest:lower() == "yes"))
+ end
end
repo.project_config.settings[key] = value
local ok, msg = repo:save_admin("Changed project setting: " .. key,
- env.GITANO_USER, env.GITANO_ORIG_USER)
+ env.GITANO_USER, env.GITANO_ORIG_USER)
if not ok then
- log.error(msg)
- return "exit", 2
+ log.error(msg)
+ return "exit", 2
end
elseif cmdline[3] == "del" then
local key = cmdline.orig_key
for i = 4, #cmdline do
- repo.project_config.settings[cmdline[4]] = nil
+ repo.project_config.settings[cmdline[4]] = nil
end
local ok, msg = repo:save_admin("Deleted project setting: " .. key,
- env.GITANO_USER, env.GITANO_ORIG_USER)
+ env.GITANO_USER, env.GITANO_ORIG_USER)
if not ok then
- log.error(msg)
- return "exit", 2
+ log.error(msg)
+ return "exit", 2
end
else
log.error("Unknown sub command slipped through")
@@ -499,9 +499,9 @@ local function builtin_config_run(conf, repo, cmdline, env)
end
assert(register_cmd("config", builtin_config_short,
- builtin_config_helptext,
- builtin_config_validate, builtin_config_prep,
- builtin_config_run, true, false))
+ builtin_config_helptext,
+ builtin_config_validate, builtin_config_prep,
+ builtin_config_run, true, false))
local builtin_destroy_short = "Destroy (delete) a repository"
local builtin_destroy_helptext = [[
@@ -544,24 +544,24 @@ local function builtin_destroy_run(config, repo, cmdline, env)
log.stdout(" ", token)
else
if cmdline[3] ~= token and cmdline[3] ~= '--force' then
- log.error("Confirmation token does not match, refusing to destroy")
- return "exit", 1
+ log.error("Confirmation token does not match, refusing to destroy")
+ return "exit", 1
end
-- Tokens match, ask the repo to destroy itself
local nowstamp = os.date("!%Y-%m-%d.%H:%M:%S.UTC")
local ok, msg = repo:destroy_self(nowstamp .. "." ..
- (repo.name:gsub("[^A-Za-z0-9_%.%-]",
- "_")) ..
- "." .. token .. ".destroyed")
+ (repo.name:gsub("[^A-Za-z0-9_%.%-]",
+ "_")) ..
+ "." .. token .. ".destroyed")
if not ok then
- log.error(msg)
- return "exit", 1
+ log.error(msg)
+ return "exit", 1
end
log.stdout("Should you need to recover the repository you just destroyed")
log.stdout("then you will need to speak with an admin as soon as possible")
log.stdout("")
- log.stdout("When you do, be sure to include the current time (" ..
- nowstamp .. ").")
+ log.stdout("When you do, be sure to include the current time (" ..
+ nowstamp .. ").")
log.stdout("It may also help if you include your token:")
log.stdout(" ", token)
log.stdout("")
@@ -570,10 +570,10 @@ local function builtin_destroy_run(config, repo, cmdline, env)
return "exit", 0
end
-assert(register_cmd("destroy", builtin_destroy_short,
- builtin_destroy_helptext, builtin_destroy_validate,
- builtin_destroy_prep, builtin_destroy_run,
- true, false))
+assert(register_cmd("destroy", builtin_destroy_short,
+ builtin_destroy_helptext, builtin_destroy_validate,
+ builtin_destroy_prep, builtin_destroy_run,
+ true, false))
local builtin_rename_short = "Rename a repository"
local builtin_rename_helptext = [[
@@ -643,8 +643,8 @@ local function builtin_rename_run(config, repo, cmdline, env)
end
assert(register_cmd("rename", builtin_rename_short, builtin_rename_helptext,
- builtin_rename_validate, builtin_rename_prep,
- builtin_rename_run, true, false))
+ builtin_rename_validate, builtin_rename_prep,
+ builtin_rename_run, true, false))
local builtin_ls_short = "List repositories on the server"
local builtin_ls_helptext = [[
@@ -705,10 +705,10 @@ local function builtin_ls_run(config, _, cmdline, env)
local firstpat, verbose, all = 2, false, false
while lsargs[cmdline[firstpat]] do
if lsargs[cmdline[firstpat]] == "verbose" then
- firstpat, verbose = firstpat + 1, true
+ firstpat, verbose = firstpat + 1, true
end
if lsargs[cmdline[firstpat]] == "all" then
- firstpat, all = firstpat + 1, true
+ firstpat, all = firstpat + 1, true
end
end
for i = firstpat, #cmdline do
@@ -716,53 +716,53 @@ local function builtin_ls_run(config, _, cmdline, env)
local escaping, star, used_evil = false, false, false
c, input = input:match("^(.)(.*)$")
while c and c ~= "" do
- if escaping then
- pat = pat .. (builtin_ls_special[c] and "%" or "") .. c
- if c == "/" then
- used_evil = true
- end
- escaping = false
- else
- if c == "*" then
- if star then
- -- **
- pat = pat .. ".*"
- used_evil = true
- star = false
- else
- star = true
- end
- else
- if star then
- -- *
- pat = pat .. "[^/]*"
- star = false
- end
- if c == "?" then
- pat = pat .. "[^/]"
- elseif c == "\\" then
- escaping = true
- else
- pat = pat .. (builtin_ls_special[c] and "%" or "") .. c
- if c == "/" then
- used_evil = true
- end
- end
- end
- end
- c, input = input:match("^(.)(.*)$")
+ if escaping then
+ pat = pat .. (builtin_ls_special[c] and "%" or "") .. c
+ if c == "/" then
+ used_evil = true
+ end
+ escaping = false
+ else
+ if c == "*" then
+ if star then
+ -- **
+ pat = pat .. ".*"
+ used_evil = true
+ star = false
+ else
+ star = true
+ end
+ else
+ if star then
+ -- *
+ pat = pat .. "[^/]*"
+ star = false
+ end
+ if c == "?" then
+ pat = pat .. "[^/]"
+ elseif c == "\\" then
+ escaping = true
+ else
+ pat = pat .. (builtin_ls_special[c] and "%" or "") .. c
+ if c == "/" then
+ used_evil = true
+ end
+ end
+ end
+ end
+ c, input = input:match("^(.)(.*)$")
end
if star then
- -- spare star
- pat = pat .. "[^/]*"
+ -- spare star
+ pat = pat .. "[^/]*"
end
if cmdline[i]:match("/$") then
pat = pat .. ".*"
end
if used_evil then
- pat = "^/" .. pat .. "%.git$"
+ pat = "^/" .. pat .. "%.git$"
else
- pat = "/" .. pat .. "%.git$"
+ pat = "/" .. pat .. "%.git$"
end
log.debug("PAT:", pat)
pats[#pats+1] = pat
@@ -775,31 +775,31 @@ local function builtin_ls_run(config, _, cmdline, env)
local _ctx = cmdline._ctx
local function filter_callback(name)
for i = 1, #pats do
- if ("/" .. name):match(pats[i]) then
- return true
- end
+ if ("/" .. name):match(pats[i]) then
+ return true
+ end
end
end
local function callback(reponame, repo, msg)
if repo then
- local archived = repo:conf_get("project.archived")
- if archived and not all then return end
- local ctx = util.deep_copy(_ctx)
- ctx.operation = "read"
- local action, reason = repo:run_lace(ctx)
- if action == "allow" then
- ctx = util.deep_copy(_ctx)
- ctx.operation = "write"
- action, reason = repo:run_lace(ctx)
- local tail = ""
- if verbose then
- local desc = repo:conf_get("project.description")
- desc = desc:gsub("\n.*", "")
- tail = " " .. repo:conf_get("project.head") .. " " .. desc
- end
- log.stdout((action == "allow" and "RW" or "R ") ..
- (archived and "A" or " "), repo.name .. tail)
- end
+ local archived = repo:conf_get("project.archived")
+ if archived and not all then return end
+ local ctx = util.deep_copy(_ctx)
+ ctx.operation = "read"
+ local action, reason = repo:run_lace(ctx)
+ if action == "allow" then
+ ctx = util.deep_copy(_ctx)
+ ctx.operation = "write"
+ action, reason = repo:run_lace(ctx)
+ local tail = ""
+ if verbose then
+ local desc = repo:conf_get("project.description")
+ desc = desc:gsub("\n.*", "")
+ tail = " " .. repo:conf_get("project.head") .. " " .. desc
+ end
+ log.stdout((action == "allow" and "RW" or "R ") ..
+ (archived and "A" or " "), repo.name .. tail)
+ end
end
end
repository.foreach(config, callback, filter_callback)
@@ -807,8 +807,8 @@ local function builtin_ls_run(config, _, cmdline, env)
end
assert(register_cmd("ls", builtin_ls_short, builtin_ls_helptext,
- builtin_ls_validate, builtin_ls_prep, builtin_ls_run,
- false, false))
+ builtin_ls_validate, builtin_ls_prep, builtin_ls_run,
+ false, false))
local usercmds = require 'gitano.usercommand'
diff --git a/lib/gitano/config.lua b/lib/gitano/config.lua
index 76262f0..a46df21 100644
--- a/lib/gitano/config.lua
+++ b/lib/gitano/config.lua
@@ -24,9 +24,9 @@ local lib_bin_path = "/tmp/DOES_NOT_EXIST"
local share_path = "/tmp/DOES_NOT_EXIST"
local repo_path = "/tmp/DOES_NOT_EXIST"
-local admin_name = {
- realname = "Gitano",
- email = "gitano@gitano-admin.git"
+local admin_name = {
+ realname = "Gitano",
+ email = "gitano@gitano-admin.git"
}
local required_confs = {
@@ -65,7 +65,7 @@ local function parse_admin_config(commit)
local conf, err =
clod.parse(flat_tree["site.conf"].obj.content,
- "gitano-admin:" .. commit.sha .. ":site.conf")
+ "gitano-admin:" .. commit.sha .. ":site.conf")
if not conf then
return nil, err
@@ -75,8 +75,8 @@ local function parse_admin_config(commit)
for k, t in pairs(required_confs) do
if type(conf.settings[k]) ~= t then
- return nil, i18n.expand("ERROR_SITE_CONF_TYPE",
- {sha=commit.sha, key=k, want=t, got=type(conf.settings[k])})
+ return nil, i18n.expand("ERROR_SITE_CONF_TYPE",
+ {sha=commit.sha, key=k, want=t, got=type(conf.settings[k])})
end
end
@@ -94,7 +94,7 @@ local function parse_admin_config(commit)
-- Found a user, fill them out
local user_clod, err = clod.parse(obj.obj.content,
- commit.sha .. ":" .. prefix .. username .. "/user.conf")
+ commit.sha .. ":" .. prefix .. username .. "/user.conf")
if not user_clod then
return nil, err
@@ -111,7 +111,7 @@ local function parse_admin_config(commit)
end
users[username] = setmetatable({ clod = user_clod, keys = {},
- meta = { prefix = prefix }, }, user_mt)
+ meta = { prefix = prefix }, }, user_mt)
end
end
@@ -139,17 +139,17 @@ local function parse_admin_config(commit)
if (keytype ~= "ssh-rsa") and (keytype ~= "ssh-dss") and
(keytype ~= "ecdsa-sha2-nistp256") and
(keytype ~= "ecdsa-sha2-nistp384") and
- (keytype ~= "ecdsa-sha2-nistp521") then
+ (keytype ~= "ecdsa-sha2-nistp521") then
return nil, i18n.expand("ERROR_BAD_KEY_TYPE",
{keytype=keytype, filename=filename})
end
if all_keys[this_key] then
- return nil, i18n.expand(
- "ERROR_DUPLICATE_KEY",
- {keyname=keyname, username=username,
- otherkey=all_keys[this_key].keyname,
- otheruser=all_keys[this_key].username})
+ return nil, i18n.expand(
+ "ERROR_DUPLICATE_KEY",
+ {keyname=keyname, username=username,
+ otherkey=all_keys[this_key].keyname,
+ otheruser=all_keys[this_key].username})
end
all_keys[this_key] = { keyname = keyname, username = username }
users[username].keys[keyname] = {
@@ -166,76 +166,76 @@ local function parse_admin_config(commit)
for filename, obj in pairs(flat_tree) do
local prefix, groupname = filename:match("^(groups/.-)([a-z][a-z0-9_.-]+)%.conf$")
if prefix and groupname then
- if groups[groupname] then
- return nil, i18n.expand("ERROR_DUPLICATE_GROUP", {name=groupname})
- end
- if not is_blob(obj) then
- return nil, i18n.expand("ERROR_GROUP_NOT_BLOB", {path=prefix..groupname})
- end
- local group_clod, err =
- clod.parse(obj.obj.content,
- "gitano-admin:" .. commit.sha .. ":" ..
- prefix .. groupname .. ".conf", true)
-
- if not group_clod then
- return nil, err
- end
- if type(group_clod.settings.description) ~= "string" then
- return nil, i18n.expand("ERROR_GROUP_NO_DESCRIPTION", {name=groupname})
- end
- local group_globals = {
- clod = group_clod,
- settings = group_clod.settings,
- members = {},
- subgroups = {},
- }
- for i, member in ipairs(group_clod:get_list("members")) do
- group_globals.members[i] = member
- group_globals.members[member] = i
- end
- for i, subgroup in ipairs(group_clod:get_list("subgroups")) do
- group_globals.subgroups[i] = subgroup
- group_globals.subgroups[subgroup] = i
- end
- function group_globals.changed_tables()
- group_globals.clod:set_list("members", group_globals.members)
- group_globals.clod:set_list("subgroups", group_globals.subgroups)
- end
- groups[groupname] = group_globals
- groups[groupname].meta = { prefix = prefix }
+ if groups[groupname] then
+ return nil, i18n.expand("ERROR_DUPLICATE_GROUP", {name=groupname})
+ end
+ if not is_blob(obj) then
+ return nil, i18n.expand("ERROR_GROUP_NOT_BLOB", {path=prefix..groupname})
+ end
+ local group_clod, err =
+ clod.parse(obj.obj.content,
+ "gitano-admin:" .. commit.sha .. ":" ..
+ prefix .. groupname .. ".conf", true)
+
+ if not group_clod then
+ return nil, err
+ end
+ if type(group_clod.settings.description) ~= "string" then
+ return nil, i18n.expand("ERROR_GROUP_NO_DESCRIPTION", {name=groupname})
+ end
+ local group_globals = {
+ clod = group_clod,
+ settings = group_clod.settings,
+ members = {},
+ subgroups = {},
+ }
+ for i, member in ipairs(group_clod:get_list("members")) do
+ group_globals.members[i] = member
+ group_globals.members[member] = i
+ end
+ for i, subgroup in ipairs(group_clod:get_list("subgroups")) do
+ group_globals.subgroups[i] = subgroup
+ group_globals.subgroups[subgroup] = i
+ end
+ function group_globals.changed_tables()
+ group_globals.clod:set_list("members", group_globals.members)
+ group_globals.clod:set_list("subgroups", group_globals.subgroups)
+ end
+ groups[groupname] = group_globals
+ groups[groupname].meta = { prefix = prefix }
end
- end
+ end
-- Attempt a clean flattening of each group to ensure no loops
for gname, gtab in pairs(groups) do
local all_members = {}
local all_subgroups = {}
- local function add_group(grname, grtab, path)
- if not grtab then
- log.fatal(i18n.expand("ERROR_GROUP_NOT_FOUND", {name=grname, path=path}))
- return
- end
- if all_subgroups[grname] then
- return nil, i18n.expand("ERROR_GROUP_LOOP", {path=path})
- end
- for _, un in ipairs(grtab.members) do
- if users[un] then
- all_members[un] = path
- end
- end
- all_subgroups[grname] = true
- for _, gn in ipairs(grtab.subgroups) do
- local ok, msg = add_group(gn, groups[gn], path .. "!" .. gn)
- if not ok then
- return nil, msg
- end
- end
- all_subgroups[grname] = false
- return true
+ local function add_group(grname, grtab, path)
+ if not grtab then
+ log.fatal(i18n.expand("ERROR_GROUP_NOT_FOUND", {name=grname, path=path}))
+ return
+ end
+ if all_subgroups[grname] then
+ return nil, i18n.expand("ERROR_GROUP_LOOP", {path=path})
+ end
+ for _, un in ipairs(grtab.members) do
+ if users[un] then
+ all_members[un] = path
+ end
+ end
+ all_subgroups[grname] = true
+ for _, gn in ipairs(grtab.subgroups) do
+ local ok, msg = add_group(gn, groups[gn], path .. "!" .. gn)
+ if not ok then
+ return nil, msg
+ end
+ end
+ all_subgroups[grname] = false
+ return true
end
local ok, msg = add_group(gname, gtab, gname)
if not ok then
- return nil, msg
+ return nil, msg
end
gtab.filtered_members = all_members
end
@@ -245,16 +245,16 @@ local function parse_admin_config(commit)
for filename, obj in pairs(flat_tree) do
local prefix, keyringname = filename:match("^(keyrings/.-)([a-z][a-z0-9_.-]+)%.gpg$")
if prefix and keyringname then
- if keyrings[keyringname] then
- return nil, i18n.expand("ERROR_DUPLICATE_KEYRING", {name=keyringname})
- end
- if not is_blob(obj) then
- return nil, i18n.expand("ERROR_KEYRING_NOT_BLOB", {path=prefix .. groupname})
- end
- keyrings[keyringname] = {
- meta = { prefix = prefix },
- blob = obj.obj
- }
+ if keyrings[keyringname] then
+ return nil, i18n.expand("ERROR_DUPLICATE_KEYRING", {name=keyringname})
+ end
+ if not is_blob(obj) then
+ return nil, i18n.expand("ERROR_KEYRING_NOT_BLOB", {path=prefix .. groupname})
+ end
+ keyrings[keyringname] = {
+ meta = { prefix = prefix },
+ blob = obj.obj
+ }
end
end
@@ -262,13 +262,13 @@ local function parse_admin_config(commit)
-- and (c) has at least one key and/or a password set
if users["gitano-bypass"] then
for gname, gtab in pairs(groups) do
- if gtab.filtered_members["gitano-bypass"] then
- return nil, i18n.expand("ERROR_BYPASS_USER_IN_GROUP", {group=gname})
- end
+ if gtab.filtered_members["gitano-bypass"] then
+ return nil, i18n.expand("ERROR_BYPASS_USER_IN_GROUP", {group=gname})
+ end
end
local okay = next(users["gitano-bypass"].keys) or users["gitano-bypass"].clod["passwd.hash"]
if not okay then
- return nil, i18n.expand("ERROR_BYPASS_USER_LACKING")
+ return nil, i18n.expand("ERROR_BYPASS_USER_LACKING")
end
else
return nil, i18n.expand("ERROR_NO_BYPASS_USER_FOUND")
@@ -319,7 +319,7 @@ end
local function has_global_hook(conf, hook)
return (conf.content["global-hooks/" .. hook .. ".lua"] ~= nil and
- conf.content["global-hooks/" .. hook .. ".lua"].type == "blob")
+ conf.content["global-hooks/" .. hook .. ".lua"].type == "blob")
end
local function get_default_hook_content(conf, filename)
@@ -332,10 +332,10 @@ local function generate_ssh_config(conf)
local ret = {"","### Gitano Keys ###"}
for u, t in pairs(conf.users) do
for ktag, keytab in pairs(t.keys) do
- log.debug(i18n.expand("DEBUG_ADDING_SSH_KEY", {user=u, key=ktag}))
- ret[#ret+1] =
- (('command="%s/gitano-auth \\"%s\\" \\"%s\\" \\"%s\\"",no-agent-forwarding,no-port-forwarding,no-pty,no-user-rc,no-X11-forwarding %s'):
- format(lib_bin_path, repo_path, u, ktag, keytab.data))
+ log.debug(i18n.expand("DEBUG_ADDING_SSH_KEY", {user=u, key=ktag}))
+ ret[#ret+1] =
+ (('command="%s/gitano-auth \\"%s\\" \\"%s\\" \\"%s\\"",no-agent-forwarding,no-port-forwarding,no-pty,no-user-rc,no-X11-forwarding %s'):
+ format(lib_bin_path, repo_path, u, ktag, keytab.data))
end
end
ret[#ret+1] = "### End Gitano Keys ###"
@@ -350,7 +350,7 @@ local function update_ssh_keys(conf, ssh_path)
local home = luxio.getenv "HOME"
if not home then
- log.fatal(i18n.expand("ERROR_CANNOT_FIND_HOME"))
+ log.fatal(i18n.expand("ERROR_CANNOT_FIND_HOME"))
end
ssh_path = home .. "/.ssh/authorized_keys"
@@ -383,10 +383,10 @@ local function populate_context(conf, ctx, username)
local grps = {}
for grp, gtab in pairs(conf.groups) do
if gtab.filtered_members[username] then
- -- Array for pattern matches
- grps[#grps+1] = grp
- -- Set for exact matches
- grps[grp] = true
+ -- Array for pattern matches
+ grps[#grps+1] = grp
+ -- Set for exact matches
+ grps[grp] = true
end
end
ctx.group = grps
@@ -415,7 +415,7 @@ local function commit_config_changes(conf, desc, author, committer)
-- Shallow copy the tree ready for mods, skipping keyrings, users and groups
for k,v in pairs(conf.content) do
if not (k:match("^users/") or
- k:match("^groups/") or
+ k:match("^groups/") or
k:match("^keyrings/")) then
newtree[k] = v
end
@@ -455,23 +455,23 @@ local function commit_config_changes(conf, desc, author, committer)
end
author = (author and {
- realname = conf.users[author].real_name,
- email = conf.users[author].email_address
- }) or admin_name
+ realname = conf.users[author].real_name,
+ email = conf.users[author].email_address
+ }) or admin_name
committer = (committer and {
- realname = conf.users[committer].real_name,
- email = conf.users[committer].email_address
- }) or author
+ realname = conf.users[committer].real_name,
+ email = conf.users[committer].email_address
+ }) or author
- local commit, msg =
+ local commit, msg =
gall.commit.create(conf.repo.git, {
- author = author,
- committer = committer,
- message = desc or "Updated",
- tree = tree,
- parents = { conf.commit }
- })
+ author = author,
+ committer = committer,
+ message = desc or "Updated",
+ tree = tree,
+ parents = { conf.commit }
+ })
if not commit then
return nil, msg
end
@@ -483,9 +483,9 @@ local function commit_config_changes(conf, desc, author, committer)
end
-- Create/Update the HEAD ref
- local ok, msg = conf.repo.git:update_ref(conf.repo.git.HEAD,
- commit.sha, nil,
- conf.commit.sha)
+ local ok, msg = conf.repo.git:update_ref(conf.repo.git.HEAD,
+ commit.sha, nil,
+ conf.commit.sha)
if not ok then
return nil, msg
end
diff --git a/lib/gitano/copycommand.lua b/lib/gitano/copycommand.lua
index 51dca74..4dfe800 100644
--- a/lib/gitano/copycommand.lua
+++ b/lib/gitano/copycommand.lua
@@ -58,8 +58,8 @@ local function builtin_copy_prep(config, srcrepo, cmdline, context)
-- Check 3, target repository does not already exist
-- We knew this for a while but failing earlier would leak its existence.
if not cmdline.tgtrepo.is_nascent then
- log.error("Repository", cmdline.tgtrepo.name, "already exists")
- return "deny", "Repository already exists"
+ log.error("Repository", cmdline.tgtrepo.name, "already exists")
+ return "deny", "Repository already exists"
end
-- Check 4, target repository can be created
ctx = util.deep_copy(context)
@@ -87,11 +87,11 @@ local function builtin_copy_run(config, repo, cmdline, env)
log.fatal("Cannot continue")
return false
end
-
+
local owner = env["GITANO_USER"]
log.chat("Setting repository owner to", owner)
ok, msg = tgtrepo:conf_set_and_save("project.owner", owner,
- env.GITANO_USER, env.GITANO_ORIG_USER)
+ env.GITANO_USER, env.GITANO_ORIG_USER)
if not ok then
log.error(msg)
return "exit", 1
@@ -102,8 +102,8 @@ local function builtin_copy_run(config, repo, cmdline, env)
log.error(msg)
return "exit", 1
end
- log.state("Repository", tgtrepo.name,
- "copied ok. Remember to configure rules etc.")
+ log.state("Repository", tgtrepo.name,
+ "copied ok. Remember to configure rules etc.")
return "exit", 0
end
diff --git a/lib/gitano/i18n.lua b/lib/gitano/i18n.lua
index 4b5198e..f454a2f 100644
--- a/lib/gitano/i18n.lua
+++ b/lib/gitano/i18n.lua
@@ -48,10 +48,10 @@ local function base_packloader(codex, pack, fulllang)
if chunk then
local ok, tab = pcall(chunk)
if ok and type(tab) == "table" then
- -- Able to load the base pack, so inject it...
- for k, v in pairs(tab) do
- pack:add_token(k, v)
- end
+ -- Able to load the base pack, so inject it...
+ for k, v in pairs(tab) do
+ pack:add_token(k, v)
+ end
end
end
end
@@ -68,10 +68,10 @@ local function plugin_packloader(codex, pack, fulllang, path)
if chunk then
local ok, tab = pcall(chunk)
if ok and type(tab) == "table" then
- -- Able to load the plugin pack, so inject it...
- for k, v in pairs(tab) do
- pack:add_token(k, v)
- end
+ -- Able to load the plugin pack, so inject it...
+ for k, v in pairs(tab) do
+ pack:add_token(k, v)
+ end
end
end
end
@@ -80,7 +80,7 @@ local function set_langpack_path(path)
basepath = path
initialise()
codex:add_loader(function(codex, pack, fulllang)
- return plugin_packloader(codex, pack, fulllang, path)
+ return plugin_packloader(codex, pack, fulllang, path)
end)
end
@@ -100,7 +100,7 @@ end
local function expand(token, vars)
initialise()
return activeencoding:touser(codex:expand(activelang, activesublang,
- token, vars or {}))
+ token, vars or {}))
end
local function decode(s)
diff --git a/lib/gitano/lace.lua b/lib/gitano/lace.lua
index 6b2c66d..5712b5e 100644
--- a/lib/gitano/lace.lua
+++ b/lib/gitano/lace.lua
@@ -24,23 +24,23 @@ local function _loader(ctx, _name)
if not global_name then
-- Project load
if ctx.project and not ctx.project_tree then
- ctx.project_tree = gall.tree.flatten(ctx.project.content.tree.content)
+ ctx.project_tree = gall.tree.flatten(ctx.project.content.tree.content)
end
if ctx.project_tree then
- tree = ctx.project_tree
- sha = ctx.project.sha
+ tree = ctx.project_tree
+ sha = ctx.project.sha
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
+ 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)
+ ctx.global_tree = gall.tree.flatten(ctx.global.content.tree.content)
end
tree = ctx.global_tree
sha = ctx.global.sha
@@ -53,7 +53,7 @@ local function _loader(ctx, _name)
local real_name = sha .. "::" .. blob_name
if not tree[blob_name] or tree[blob_name].type ~= "blob" then
local m = i18n.expand("ERROR_UNABLE_TO_FIND_RULE",
- { name=blob_name, sha=sha, inname=_name })
+ { name=blob_name, sha=sha, inname=_name })
log.ddebug(m)
return lace.error.error(m)
end
@@ -62,20 +62,20 @@ end
local match_types = {
exact = function(want, have)
- return want == have
- end,
+ return want == have
+ end,
prefix = function(want, have)
- return have:sub(1, #want) == want
- end,
+ return have:sub(1, #want) == want
+ end,
suffix = function(want, have)
- return have:sub(-#want) == want
- end,
+ return have:sub(-#want) == want
+ end,
pattern = function(want, have)
- return (have:match(want) ~= nil)
- end,
+ return (have:match(want) ~= nil)
+ end,
pcre = function(want, have)
- return (pcre.match(have, want) ~= nil)
- end
+ return (pcre.match(have, want) ~= nil)
+ end
}
-- Match aliases (auto-inverted)
@@ -113,10 +113,10 @@ local function _do_simple_match(ctx, key, matchtype, value)
else
local ret = false
for k in pairs(kk) do
- ret = ret or check(value, k)
+ ret = ret or check(value, k)
end
if matchtype:sub(1,1) == "!" then
- ret = not ret
+ ret = not ret
end
return ret
end
@@ -181,8 +181,8 @@ local base_compcontext = {
local function cloddly_bless(ctx)
local function indexer(tab, name)
if name:sub(1,7) == "config/" then
- tab[name] = _simple_match
- return _simple_match
+ tab[name] = _simple_match
+ return _simple_match
end
end
setmetatable(ctx._lace.controltype, {__index = indexer})
@@ -198,9 +198,9 @@ local function compile_ruleset(repo, adminsha, globaladminsha)
compcontext.repo = repo
if not repo.is_nascent then
if not adminsha then
- compcontext.project = repo.git:get("refs/gitano/admin")
+ compcontext.project = repo.git:get("refs/gitano/admin")
else
- compcontext.project = repo.git:get(adminsha)
+ compcontext.project = repo.git:get(adminsha)
end
end
if not globaladminsha then
diff --git a/lib/gitano/log.lua b/lib/gitano/log.lua
index e1df00b..7df5e76 100644
--- a/lib/gitano/log.lua
+++ b/lib/gitano/log.lua
@@ -111,7 +111,7 @@ local function set_prefix(new_prefix)
prefix = ""
else
if new_prefix == "true" then
- new_prefix = "Gitano"
+ new_prefix = "Gitano"
end
prefix = "[" .. tostring(new_prefix) .. "] "
end
@@ -121,7 +121,7 @@ local function AT(LVL, ...)
if level >= LVL then
local strs = {...}
for i = 1, #strs do
- strs[i] = tostring(strs[i]) or "?"
+ strs[i] = tostring(strs[i]) or "?"
end
stream:write(prefix .. concat(strs, " ") .. "\n")
end
@@ -187,8 +187,7 @@ local function deepdebug(...)
end
local function set_level(l)
- if type(l) ~= "number" or
- l < ERRS or l > DEEPDEBUG then
+ if type(l) ~= "number" or l < ERRS or l > DEEPDEBUG then
level = WARN
warn("Attempted to set level to", tostring(l), "- defaulted to warnings")
end
@@ -196,16 +195,14 @@ local function set_level(l)
end
local function bump_level(l)
- if type(l) ~= "number" or
- l < ERRS or l > DEEPDEBUG then
+ if type(l) ~= "number" or l < ERRS or l > DEEPDEBUG then
warn("Attempted to bump level to", tostring(l), "- left alone")
end
if level < l then level = l end
end
local function cap_level(l)
- if type(l) ~= "number" or
- l < ERRS or l > DEEPDEBUG then
+ if type(l) ~= "number" or l < ERRS or l > DEEPDEBUG then
warn("Attempted to cap level to", tostring(l), "- left alone")
end
if level > l then level = l end
@@ -217,33 +214,33 @@ end
-- Check for default log level based on environment
do
- local loglevel = luxio.getenv("LC_GITANO_LOG_LEVEL") or
- luxio.getenv("GITANO_LOG_LEVEL")
+ local loglevel = (
+ luxio.getenv("LC_GITANO_LOG_LEVEL") or luxio.getenv("GITANO_LOG_LEVEL"))
if loglevel then
if tonumber(loglevel) then
- set_level(tonumber(loglevel))
+ set_level(tonumber(loglevel))
else
- loglevel = loglevel:lower()
- if (loglevel == "warn" or loglevel == "warning" or
- loglevel == "warnings") then
- level = WARN
- elseif loglevel == "chat" then
- level = CHAT
- elseif loglevel == "info" then
- level = INFO
- elseif loglevel == "debug" then
- level = DEBUG
- elseif (loglevel == "deepdebug" or loglevel == "ddebug" or
- loglevel == "all") then
- level = DEEPDEBUG
- end
+ loglevel = loglevel:lower()
+ if (loglevel == "warn" or loglevel == "warning" or
+ loglevel == "warnings") then
+ level = WARN
+ elseif loglevel == "chat" then
+ level = CHAT
+ elseif loglevel == "info" then
+ level = INFO
+ elseif loglevel == "debug" then
+ level = DEBUG
+ elseif (loglevel == "deepdebug" or loglevel == "ddebug" or
+ loglevel == "all") then
+ level = DEEPDEBUG
+ end
end
if level == nil then
- level = WARN
+ level = WARN
end
end
- local do_debug = luxio.getenv("LC_GITANO_DEBUG") or
+ local do_debug = luxio.getenv("LC_GITANO_DEBUG") or
luxio.getenv("GITANO_DEBUG")
if do_debug and do_debug ~= "" then
level = DEBUG
diff --git a/lib/gitano/plugins.lua b/lib/gitano/plugins.lua
index 57f73c3..a4ba912 100644
--- a/lib/gitano/plugins.lua
+++ b/lib/gitano/plugins.lua
@@ -20,8 +20,8 @@ local function find_plugins(path)
for _, entry in ipairs(path) do
local dirp, err = sio.opendir(entry)
if not dirp then
- log.warning(i18n.expand("WARN_UNABLE_SCAN_PLUGINDIR",
- {dir=entry, reason=err}))
+ log.warning(i18n.expand("WARN_UNABLE_SCAN_PLUGINDIR",
+ {dir=entry, reason=err}))
else
for filename, fileinfo in dirp:iterate() do
local plugin_name = filename:match(plugin_name_pattern)
@@ -45,21 +45,21 @@ local function load_plugins(path)
plugin_name .. ".lua")
local chunk, err = loadfile(filepath)
if not chunk then
- log.warning(i18n.expand("WARN_UNABLE_LOAD_PLUGIN",
- { plugin=plugin_name,
- file=to_load[plugin_name],
- reason=err }))
+ log.warning(i18n.expand("WARN_UNABLE_LOAD_PLUGIN",
+ { plugin=plugin_name,
+ file=to_load[plugin_name],
+ reason=err }))
else
local ok, err = pcall(chunk)
if not ok then
- log.warning(i18n.expand("WARN_UNABLE_RUN_PLUGIN",
- { plugin=plugin_name,
- file=to_load[plugin_name],
- reason=err }))
+ log.warning(i18n.expand("WARN_UNABLE_RUN_PLUGIN",
+ { plugin=plugin_name,
+ file=to_load[plugin_name],
+ reason=err }))
end
end
i18n.add_plugin_path(util.path_join(to_load[plugin_name],
- plugin_name))
+ plugin_name))
end
end
diff --git a/lib/gitano/repocommand.lua b/lib/gitano/repocommand.lua
index af4584a..2163f4d 100644
--- a/lib/gitano/repocommand.lua
+++ b/lib/gitano/repocommand.lua
@@ -29,7 +29,7 @@ usage: count-objects repo [options]
Counts objects in your repository.
-You must have read access to the repository in order
+You must have read access to the repository in order
to run count-objects.
]]
@@ -76,17 +76,17 @@ end
local function register_repocommand(register_cmd)
assert(register_cmd("gc", builtin_gc_short, builtin_gc_helptext,
- builtin_simple_validate, builtin_gc_prep,
- builtin_simple_run, true, false))
+ builtin_simple_validate, builtin_gc_prep,
+ builtin_simple_run, true, false))
assert(register_cmd("count-objects", builtin_count_objects_short,
- builtin_count_objects_helptext, builtin_simple_validate,
- builtin_count_objects_prep, builtin_simple_run,
- true, false))
+ builtin_count_objects_helptext, builtin_simple_validate,
+ builtin_count_objects_prep, builtin_simple_run,
+ true, false))
assert(register_cmd("fsck", builtin_fsck_short, builtin_fsck_helptext,
- builtin_simple_validate, builtin_fsck_prep,
- builtin_simple_run, true, false))
+ builtin_simple_validate, builtin_fsck_prep,
+ builtin_simple_run, true, false))
end
return {
diff --git a/lib/gitano/repository.lua b/lib/gitano/repository.lua
index 879d001..7858a33 100644
--- a/lib/gitano/repository.lua
+++ b/lib/gitano/repository.lua
@@ -26,9 +26,9 @@ project.description ""
project.owner "gitano/nobody"
]]
-local admin_name = {
- realname = "Gitano",
- email = "gitano@gitano-admin.git"
+local admin_name = {
+ realname = "Gitano",
+ email = "gitano@gitano-admin.git"
}
local adminrefname = "refs/gitano/admin"
@@ -42,11 +42,11 @@ function repo_method:load_from_admin_ref(filename)
local entry = flat_tree[filename]
if not entry then
return nil, i18n.expand("ERROR_GENERIC_CONF_NOT_FOUND",
- {sha=admincommit.sha, name=filename})
+ {sha=admincommit.sha, name=filename})
end
if entry.obj.type ~= "blob" then
return nil, i18n.expand("ERROR_GENERIC_CONF_NOT_BLOB",
- {sha=admincommit.sha, name=filename})
+ {sha=admincommit.sha, name=filename})
end
return entry.obj.content, admincommit.sha .. "::" .. filename
end
@@ -72,7 +72,7 @@ end
function repo_method:fs_path()
return ("%s/%s.git"):format(config.repo_path(),
- self.name)
+ self.name)
end
function repo_method:run_checks()
@@ -85,41 +85,41 @@ function repo_method:run_checks()
-- First, the blob for the rules
local rules, msg = gall.object.create(self.git, "blob", base_rules)
if not rules then
- return nil, msg
+ return nil, msg
end
local conf, msg = gall.object.create(self.git, "blob", base_config)
if not conf then
- return nil, msg
+ return nil, msg
end
-- Next the tree containing the blob
- local flat_tree = {
- ["rules/main.lace"] = rules,
- ["project.conf"] = conf,
+ local flat_tree = {
+ ["rules/main.lace"] = rules,
+ ["project.conf"] = conf,
}
local tree, msg = gall.tree.create(self.git, flat_tree)
if not tree then
- return nil, msg
+ return nil, msg
end
-- Now a commit of the blob, using the gitano admin identity
- local commit, msg =
- gall.commit.create(self.git, {
- author = admin_name,
- committer = admin_name,
- message = i18n.expand("INITIAL_ADMIN_TREE"),
- tree = tree
- })
+ local commit, msg =
+ gall.commit.create(self.git, {
+ author = admin_name,
+ committer = admin_name,
+ message = i18n.expand("INITIAL_ADMIN_TREE"),
+ tree = tree
+ })
if not commit then
- return nil, msg
+ return nil, msg
end
-- Finally create/update the gitano/admin ref
local ok, msg = self.git:update_ref(adminrefname, commit.sha)
if not ok then
- return nil, msg
+ return nil, msg
end
end
-- Admin tree exists, validate and load it...
- local ok, tab =
+ local ok, tab =
self:validate_admin_sha(self.git:get_ref(adminrefname))
if not ok then
return nil, tab
@@ -149,7 +149,7 @@ function repo_method:run_checks()
if not ok then
return nil, msg
end
-
+
-- And all is well
return true
end
@@ -187,9 +187,9 @@ function repo_method:check_signature(obj, keyringname)
while w < #b do
_b, err = sfd:write(b, w)
if _b == nil or _b < 1 then
- -- I know we're not handling EINTR/EAGAIN, I don't care
- w = -1
- break
+ -- I know we're not handling EINTR/EAGAIN, I don't care
+ w = -1
+ break
end
w = w + _b
end
@@ -228,9 +228,9 @@ function repo_method:check_local_git_files()
local fh, errmsg = sio.open(self:fs_path() .. "/git-daemon-export-ok", "wc")
if fh then
- fh:close()
+ fh:close()
else
- log.warn(i18n.expand("ERROR_CANNOT_CREATE_EXPORT_FILE", {reason=errmsg}))
+ log.warn(i18n.expand("ERROR_CANNOT_CREATE_EXPORT_FILE", {reason=errmsg}))
end
else
luxio.unlink(self:fs_path() .. "/git-daemon-export-ok")
@@ -242,14 +242,14 @@ function repo_method:check_local_git_files()
fh:write("\n")
fh:close()
local ok, errno = luxio.rename(self:fs_path() .. ("/description.%d.new"):format(luxio.getpid()),
- self:fs_path() .. "/description")
+ self:fs_path() .. "/description")
if ok ~= 0 then
- log.warn(i18n.expand("ERROR_UNABLE_TO_RENAME_INTO_PLACE",
- {what="description", reason=luxio.strerror(errno)}))
+ log.warn(i18n.expand("ERROR_UNABLE_TO_RENAME_INTO_PLACE",
+ {what="description", reason=luxio.strerror(errno)}))
end
else
log.warn(i18n.expand("ERROR_UNABLE_TO_WRITE_FILE",
- {what="description", reason=tostring(err)}))
+ {what="description", reason=tostring(err)}))
end
-- Check that our HEAD is correctly configured
local our_head = self:conf_get "project.head"
@@ -261,7 +261,7 @@ function repo_method:check_local_git_files()
local owner = self.config.users[self:conf_get "project.owner"]
if owner then
self.git:config("gitweb.owner",
- owner.real_name .. " <" .. owner.email_address .. ">")
+ owner.real_name .. " <" .. owner.email_address .. ">")
end
-- Construct a cgitrc in case we're using cgit instead of gitweb
local cgitrc = {}
@@ -273,10 +273,10 @@ function repo_method:check_local_git_files()
"snapshots" } do
local v = self.project_config.settings["cgitrc." .. suffix]
if v then
- if v == "readme" and not v:find(":") then
- v = ":" .. v
- end
- add_cgitrc(suffix, v)
+ if v == "readme" and not v:find(":") then
+ v = ":" .. v
+ end
+ add_cgitrc(suffix, v)
end
end
if owner then
@@ -298,14 +298,14 @@ function repo_method:check_local_git_files()
fh:write(cgitrc)
fh:close()
local ok, errno = luxio.rename(self:fs_path() .. ("/cgitrc.%d.new"):format(luxio.getpid()),
- self:fs_path() .. "/cgitrc")
+ self:fs_path() .. "/cgitrc")
if ok ~= 0 then
- log.warn(i18n.expand("ERROR_UNABLE_TO_RENAME_INTO_PLACE",
- {what="cgitrc", reason=luxio.strerror(errno)}))
+ log.warn(i18n.expand("ERROR_UNABLE_TO_RENAME_INTO_PLACE",
+ {what="cgitrc", reason=luxio.strerror(errno)}))
end
else
log.warn(i18n.expand("ERROR_UNABLE_TO_WRITE_FILE",
- {what="cgitrc", reason=tostring(err)}))
+ {what="cgitrc", reason=tostring(err)}))
end
return true
@@ -316,19 +316,19 @@ function repo_method:check_and_upgrade_hooks()
for _, hook in ipairs {"pre-receive", "update", "post-receive"} do
local hookfile = ("%s/hooks/%s"):format(self:fs_path(), hook)
local hooktarget = ("%s/gitano-%s-hook"):format(config.lib_bin_path(),
- hook)
+ hook)
local ok, linkv = luxio.readlink(hookfile)
local redo = false
if ok > 0 then
- if linkv ~= hooktarget then
- redo = true
- end
+ if linkv ~= hooktarget then
+ redo = true
+ end
else
- redo = true
+ redo = true
end
if redo then
- luxio.unlink(hookfile)
- luxio.symlink(hooktarget, hookfile)
+ luxio.unlink(hookfile)
+ luxio.symlink(hooktarget, hookfile)
end
end
return true
@@ -351,8 +351,8 @@ function repo_method:validate_admin_sha(sha)
local conf_text = tree["project.conf"].obj.content
local conf, err = clod.parse(conf_text,
- self.name .. ":" ..
- sha .. ":project.conf")
+ self.name .. ":" ..
+ sha .. ":project.conf")
if not conf then
return nil, err
end
@@ -365,7 +365,7 @@ function repo_method:validate_admin_sha(sha)
conf.settings["owner"] = nil
end
if conf.settings["description"] and
- not conf.settings["project.description"] then
+ not conf.settings["project.description"] then
conf.settings["project.description"] = conf.settings["description"]
conf.settings["description"] = nil
end
@@ -388,7 +388,7 @@ function repo_method:validate_admin_sha(sha)
-- Generate a Lace for the project at this ref
local lace, msg = lace.compile(self, sha)
- if not lace then
+ if not lace then
return nil, msg
end
-- And store it for use later
@@ -399,24 +399,24 @@ end
function repo_method:populate_context(context)
util.add_splitable(context, "repository", self.name,
- "/", "dirname", "basename")
+ "/", "dirname", "basename")
context["_repo"] = self
if not self.is_nascent then
local lists_to_add = {}
for k, v in self.project_config:each() do
- if k:match("%.i_[0-9]+$") then
- lists_to_add[k:gsub("%.i_[0-9]+$", "")] = true
- else
- local confkey = "config/" .. k:gsub("%.", "/")
- context[confkey] = v
- end
+ if k:match("%.i_[0-9]+$") then
+ lists_to_add[k:gsub("%.i_[0-9]+$", "")] = true
+ else
+ local confkey = "config/" .. k:gsub("%.", "/")
+ context[confkey] = v
+ end
end
for k in pairs(lists_to_add) do
- local confkey = "config/" .. k:gsub("%.", "/")
- local vallist = self.project_config:get_list(k)
- local valset = {}
- for _, v in pairs(vallist) do valset[v] = true end
- context[confkey] = valset
+ local confkey = "config/" .. k:gsub("%.", "/")
+ local vallist = self.project_config:get_list(k)
+ local valset = {}
+ for _, v in pairs(vallist) do valset[v] = true end
+ context[confkey] = valset
end
end
end
@@ -425,7 +425,7 @@ function repo_method:realise()
if not self.is_nascent then
return false, i18n.expand("ERROR_REALISE_NON_NASCENT")
end
-
+
if not util.mkdir_p(util.dirname(self:fs_path())) then
return false, i18n.expand("ERROR_CANNOT_PREP_PATH")
end
@@ -446,7 +446,7 @@ function repo_method:conf_set_and_save(conf, newvalue, author, committer)
local oldvalue = self:conf_get(conf)
self:conf_set(conf, newvalue)
local ok, msg = self:save_admin("Setting " .. conf .. " to " .. newvalue,
- author, committer)
+ author, committer)
if not ok then
self:conf_set(conf, oldvalue)
return nil, msg
@@ -462,7 +462,7 @@ function repo_method:set_head(newhead, author, committer)
local oldhead = self:conf_get "project.head"
self:conf_set("project.head", newhead)
local ok, msg = self:save_admin(i18n.expand("MSG_CHANGING_HEAD"),
- author, committer)
+ author, committer)
if not ok then
self:conf_set("project.head", oldhead)
return nil, msg
@@ -521,7 +521,7 @@ function repo_method:rename_to(somename)
somename = somename:gsub("%.", "")
-- Remove any leading or trailing /
somename = somename:match("^/*(.-)/*$")
-
+
local newpath = self.fs_path({name=somename,config=self.config})
if not util.mkdir_p(util.dirname(newpath)) then
@@ -556,22 +556,22 @@ function repo_method:copy_to(target)
ok, err = luxio.mkdir(temp_path, sio.tomode'0755')
if ok ~= 0 then
log.error(i18n.expand("ERROR_FAILED_TO_COPY",
- {path=self:fs_path(),
- newpath=newpath,
- reason=i18n.expand("ERROR_COPY_IN_PROGRESS")}))
+ {path=self:fs_path(),
+ newpath=newpath,
+ reason=i18n.expand("ERROR_COPY_IN_PROGRESS")}))
return false, i18n.expand("ERROR_COPY_IN_PROGRESS")
end
local from = self:fs_path()
local function filter(parent, name, info)
return parent == from and name == "objects"
- or util.copy_dir_filter_base(parent, name, info)
+ or util.copy_dir_filter_base(parent, name, info)
end
-- copy non-objects parts of the git repository
ok, err = util.copy_dir(from, temp_path, nil, filter)
if not ok then
log.error(i18n.expand("ERROR_FAILED_TO_COPY",
- {path=from, newpath=temp_path, reason=err}))
+ {path=from, newpath=temp_path, reason=err}))
util.rm_rf(temp_path)
return false, i18n.expand("ERROR_FAILED_COPYING_CONTENT")
end
@@ -583,7 +583,7 @@ function repo_method:copy_to(target)
cbs)
if not ok then
log.error(i18n.expand("ERROR_FAILED_HARDLINKING",
- {path=from, newpath=temp_path, reason=err}))
+ {path=from, newpath=temp_path, reason=err}))
util.rm_rf(temp_path)
return ok, i18n.expand("ERROR_FAILED_COPYING_CONTENT")
end
@@ -592,8 +592,8 @@ function repo_method:copy_to(target)
ok, err = luxio.rename(temp_path, newpath)
if ok ~= 0 then
log.error(i18n.expand("ERROR_FAILED_RENAME_REPOSITORY",
- {from=temp_path, to=newpath,
- reason=luxio.strerr(err)}))
+ {from=temp_path, to=newpath,
+ reason=luxio.strerr(err)}))
util.rm_rf(temp_path)
return false, i18n.expand("ERROR_FAILED_COPYING_CONTENT")
end
@@ -615,18 +615,18 @@ function repo_method:update_modified_date(shas)
local function update_based_on(mtime, offset)
mtime = tonumber(mtime)
if mtime > last_mod_mtime then
- last_mod_mtime = mtime
- last_mod_offset = offset
+ last_mod_mtime = mtime
+ last_mod_offset = offset
end
end
local f = io.open(modfile, "r")
if f then
local s = f:read("*l")
if s then
- local cur_mod_time, cur_mod_offset = s:find("^([0-9]+) ([+-][0-9]+)$")
- if cur_mod_time then
- update_based_on(cur_mod_time, cur_mod_offset)
- end
+ local cur_mod_time, cur_mod_offset = s:find("^([0-9]+) ([+-][0-9]+)$")
+ if cur_mod_time then
+ update_based_on(cur_mod_time, cur_mod_offset)
+ end
end
f:close()
end
@@ -635,11 +635,11 @@ function repo_method:update_modified_date(shas)
local obj = self.git:get(sha)
if obj.type == "tag" then
local tagger = obj.content.tagger
- update_based_on(tagger.unixtime, tagger.timezone)
+ update_based_on(tagger.unixtime, tagger.timezone)
elseif obj.type == "commit" then
- local committer, author = obj.content.committer, obj.content.author
- update_based_on(committer.unixtime, committer.timezone)
- update_based_on(author.unixtime, author.timezone)
+ local committer, author = obj.content.committer, obj.content.author
+ update_based_on(committer.unixtime, committer.timezone)
+ update_based_on(author.unixtime, author.timezone)
end
end
end
@@ -670,22 +670,22 @@ function repo_method:save_admin(reason, author, committer)
return nil, msg
end
author = (author and {
- realname = self.config.users[author].real_name,
- email = self.config.users[author].email_address
- }) or admin_name
+ realname = self.config.users[author].real_name,
+ email = self.config.users[author].email_address
+ }) or admin_name
committer = (committer and {
- realname = self.config.users[committer].real_name,
- email = self.config.users[committer].email_address
- }) or author
+ realname = self.config.users[committer].real_name,
+ email = self.config.users[committer].email_address
+ }) or author
-- Now a commit of the blob, using the gitano admin identity
- local commit, msg =
+ local commit, msg =
gall.commit.create(self.git, {
- author = author,
- committer = committer,
- message = reason or i18n.expand("MSG_UPDATED_ADMIN_TREE"),
- tree = tree,
- parents = { curcommit }
- })
+ author = author,
+ committer = committer,
+ message = reason or i18n.expand("MSG_UPDATED_ADMIN_TREE"),
+ tree = tree,
+ parents = { curcommit }
+ })
if not commit then
return nil, msg
end
@@ -696,11 +696,11 @@ function repo_method:save_admin(reason, author, committer)
end
-- Finally create/update the gitano/admin ref
local ok, msg = self.git:update_ref(adminrefname, commit.sha, nil,
- curcommit.sha)
+ curcommit.sha)
if not ok then
return nil, msg
end
-
+
return self:run_checks()
end
@@ -737,30 +737,30 @@ local function check_repodir(dirname, repo)
if not dirp then
if err == luxio.ENOENT then
- repo.is_nascent = true
- return repo
+ repo.is_nascent = true
+ return repo
else
- return nil, luxio.strerror(err)
+ return nil, luxio.strerror(err)
end
else
local needed = {
- branches = true,
- config = true,
- description = true,
- HEAD = true,
- objects = true,
- hooks = true,
- refs = true
+ branches = true,
+ config = true,
+ description = true,
+ HEAD = true,
+ objects = true,
+ hooks = true,
+ refs = true
}
local e, i
repeat
- e, i = luxio.readdir(dirp)
- if e == 0 then
- needed[i.d_name] = nil
- end
+ e, i = luxio.readdir(dirp)
+ if e == 0 then
+ needed[i.d_name] = nil
+ end
until not e
if next(needed) then
- return nil, i18n.expand("ERROR_SOMETHING_MISSING", {what=next(needed)})
+ return nil, i18n.expand("ERROR_SOMETHING_MISSING", {what=next(needed)})
end
end
@@ -803,7 +803,7 @@ local function find_repository(config, reponame)
-- Load a system lace.
local lace, reason = lace.compile(repo)
if not lace then
- return nil, reason
+ return nil, reason
end
-- Stuff in the lace so :run_lace() work
repo.lace = lace
@@ -834,39 +834,39 @@ local function foreach_repository(conf, callback, filterfn)
-- "find" it and call the callback with the name, repo and message
local all_repos = {}
-
+
local function scan_dir(dirname, prefix)
local dirp, err = luxio.opendir(dirname)
if not dirp then
- if err == luxio.ENOTDIR then
- return true
- end
- return nil, luxio.strerror(err)
+ if err == luxio.ENOTDIR then
+ return true
+ end
+ return nil, luxio.strerror(err)
end
local e, i
local recurse = {}
repeat
- e, i = luxio.readdir(dirp)
- if e == 0 then
- if i.d_name:find("%.git$") then
- -- Might be a repo, save for later
- all_repos[#all_repos+1] = (util.path_join(prefix, i.d_name)
- ):gsub("^/", "")
- else
- if i.d_name:find("^[^%.]") then
- recurse[#recurse+1] = i.d_name
- end
- end
- end
+ e, i = luxio.readdir(dirp)
+ if e == 0 then
+ if i.d_name:find("%.git$") then
+ -- Might be a repo, save for later
+ all_repos[#all_repos+1] = (util.path_join(prefix, i.d_name)
+ ):gsub("^/", "")
+ else
+ if i.d_name:find("^[^%.]") then
+ recurse[#recurse+1] = i.d_name
+ end
+ end
+ end
until not e
dirp = nil -- Allow GC of DIR handle
-- Now try and recurse if possible,
for i = 1, #recurse do
- local ok, msg = scan_dir(util.path_join(dirname, recurse[i]),
- util.path_join(prefix, recurse[i]))
- if not ok then
- return ok, msg
- end
+ local ok, msg = scan_dir(util.path_join(dirname, recurse[i]),
+ util.path_join(prefix, recurse[i]))
+ if not ok then
+ return ok, msg
+ end
end
return true
end
@@ -881,11 +881,11 @@ local function foreach_repository(conf, callback, filterfn)
for i = 1, #all_repos do
local want = true
if filterfn and not filterfn(all_repos[i]) then
- want = false
+ want = false
end
if want then
- local ok, msg = find_repository(conf, all_repos[i])
- callback(all_repos[i], ok, msg)
+ local ok, msg = find_repository(conf, all_repos[i])
+ callback(all_repos[i], ok, msg)
end
end
diff --git a/lib/gitano/supple.lua b/lib/gitano/supple.lua
index 147b48f..ff02900 100644
--- a/lib/gitano/supple.lua
+++ b/lib/gitano/supple.lua
@@ -49,7 +49,7 @@ local function get_repo_proxy(repo)
if proxy then
return proxy
end
-
+
proxy = setmetatable({}, proxy_repo_meta)
proxied_repo[proxy] = repo
repo_proxies[repo] = proxy
@@ -72,14 +72,14 @@ local function load_repo_module(fromrepo, prefix, module)
-- Load from the repository's admin reference
content, err = repo:load_from_admin_ref(modfile)
if not content and err:match("^Not found:") then
- content, err = "--nothing\n", "@empty_hook"
+ content, err = "--nothing\n", "@empty_hook"
end
else
-- Load from the config repo
content, err = config.load_file_content(repo.config, modfile)
if not content then
- content, err = config.get_default_hook_content(repo.config,
- modfile)
+ content, err = config.get_default_hook_content(repo.config,
+ modfile)
end
end
return content, err
@@ -149,7 +149,7 @@ local function run_hook(hook, _repo, info, ...)
repo = _repo
log.ddebug(i18n.expand("DEBUG_SUPPLE_HOST_RUN"))
return supple.host.run(supple_runtime_code, "@gitano.supple.runtime",
- hook, proxy, info, ...)
+ hook, proxy, info, ...)
end
return {
diff --git a/lib/gitano/usercommand.lua b/lib/gitano/usercommand.lua
index f9ddf1d..e85e839 100644
--- a/lib/gitano/usercommand.lua
+++ b/lib/gitano/usercommand.lua
@@ -54,7 +54,7 @@ local function builtin_whoami_run(config, repo, cmdline, env)
local longesttag = 0
for tagname in pairs(userdata.keys) do
if #tagname > longesttag then
- longesttag = #tagname
+ longesttag = #tagname
end
end
for tagname, keydata in pairs(userdata.keys) do
@@ -69,26 +69,26 @@ local function builtin_whoami_run(config, repo, cmdline, env)
for grname, gtab in pairs(config.groups) do
log.ddebug(grname, "?")
if gtab.filtered_members[username] then
- if #grname > maxname then
- maxname = #grname
- end
- groups[#groups+1] = grname
- log.ddebug(grname,"=", tostring(#groups))
- if not gtab.members[username] then
- indirect[grname] = gtab.filtered_members[username]
- end
+ if #grname > maxname then
+ maxname = #grname
+ end
+ groups[#groups+1] = grname
+ log.ddebug(grname,"=", tostring(#groups))
+ if not gtab.members[username] then
+ indirect[grname] = gtab.filtered_members[username]
+ end
end
end
if #groups > 0 then
pfx = " In groups:"
table.sort(groups)
for _, group in ipairs(groups) do
- local spaces = (" "):rep(maxname - #group)
- log.ddebug(group, indirect[group] or "DIRECT")
- local via = indirect[group] and (" (via %s)"):format((indirect[group]:match("^[^!]+!([^!]+)")) or "???") or ""
- log.stdout(pfx, spaces .. group .. ":",
- config.groups[group].settings.description .. via)
- pfx = " "
+ local spaces = (" "):rep(maxname - #group)
+ log.ddebug(group, indirect[group] or "DIRECT")
+ local via = indirect[group] and (" (via %s)"):format((indirect[group]:match("^[^!]+!([^!]+)")) or "???") or ""
+ log.stdout(pfx, spaces .. group .. ":",
+ config.groups[group].settings.description .. via)
+ pfx = " "
end
end
return "exit", 0
@@ -121,20 +121,20 @@ local function builtin_sshkey_validate(config, _, cmdline)
end
if cmdline[2] == "list" then
if #cmdline > 2 then
- log.error("sshkey list: No arguments expected")
- return false
+ log.error("sshkey list: No arguments expected")
+ return false
end
elseif cmdline[2] == "add" or cmdline[2] == "del" then
if #cmdline ~= 3 then
- log.error("sshkey", cmdline[2] .. ": Expected tag and no more")
- return false
+ log.error("sshkey", cmdline[2] .. ": Expected tag and no more")
+ return false
end
if not cmdline[3]:match("^[a-z][a-z0-9_-]+$") then
- log.error("sshkey:", cmdline[3], "is not a valid tag name.")
- log.state("Tag names start with a letter and may contain only letters")
- log.state("and numbers, underscores and dashes. Tag names must be at")
- log.state("least two characters long.")
- return false
+ log.error("sshkey:", cmdline[3], "is not a valid tag name.")
+ log.state("Tag names start with a letter and may contain only letters")
+ log.state("and numbers, underscores and dashes. Tag names must be at")
+ log.state("least two characters long.")
+ return false
end
else
log.error("sshkey: Unknown subcommand", cmdline[2])
@@ -154,16 +154,16 @@ local function builtin_sshkey_prep(config, _, cmdline, context)
if cmdline[2] == "add" then
-- Ensure that the given tag doesn't already exist
if utab.keys[cmdline[3]] then
- return "deny", "Key tag " .. cmdline[3] .. " already exists"
+ return "deny", "Key tag " .. cmdline[3] .. " already exists"
end
elseif cmdline[2] == "del" then
-- Ensure that the given tag does exist
if not utab.keys[cmdline[3]] then
- return "deny", "Key tag " .. cmdline[3] .. " does not exist"
+ return "deny", "Key tag " .. cmdline[3] .. " does not exist"
end
-- And that it's not the one we're currently using
if cmdline[3] == context.keytag then
- return "deny", "Key tag " .. cmdline[3] .. " is in use"
+ return "deny", "Key tag " .. cmdline[3] .. " is in use"
end
end
return action, reason
@@ -174,7 +174,7 @@ local function builtin_sshkey_run(conf, _, cmdline, env)
if cmdline[2] == "list" then
if not next(utab.keys) then
log.warn("There are no SSH keys registered for", env.GITANO_USER
- .. ", sorry")
+ .. ", sorry")
else
local pfx = " SSH key:"
for tagname, keydata in pairs(utab.keys) do
@@ -188,14 +188,14 @@ local function builtin_sshkey_run(conf, _, cmdline, env)
local keytype, keydata, keytag = sshkey:match("^([^ ]+) ([^ ]+) ([^ ].*)$")
if not (keytype and keydata and keytag) then
log.error("Unable to parse key,", filename,
- "did not smell like an OpenSSH v2 key")
+ "did not smell like an OpenSSH v2 key")
return "exit", 1
end
if (keytype ~= "ssh-rsa") and (keytype ~= "ssh-dss") and
(keytype ~= "ecdsa-sha2-nistp256") and
(keytype ~= "ecdsa-sha2-nistp384") and
- (keytype ~= "ecdsa-sha2-nistp521") then
+ (keytype ~= "ecdsa-sha2-nistp521") then
log.error("Unknown key type", keytype)
return "exit", 1
end
@@ -260,18 +260,18 @@ local function update_htpasswd(user, passwd)
if passwd ~= '' then
local proc = subprocess.spawn_simple({
- "htpasswd", flags, htpasswd_path, user,
- stdin = passwd,
- stdout = subprocess.PIPE,
- stderr = subprocess.PIPE
+ "htpasswd", flags, htpasswd_path, user,
+ stdin = passwd,
+ stdout = subprocess.PIPE,
+ stderr = subprocess.PIPE
})
_, exit_code = proc:wait()
else
local proc = subprocess.spawn_simple({
- "htpasswd", "-D", htpasswd_path, user,
- stdout = subprocess.PIPE,
- stderr = subprocess.PIPE
+ "htpasswd", "-D", htpasswd_path, user,
+ stdout = subprocess.PIPE,
+ stderr = subprocess.PIPE
})
_, exit_code = proc:wait()
@@ -288,7 +288,7 @@ local function builtin_passwd_run(conf, _, cmdline, env)
if conf.users[user]["passwd.hash"] == nil and password == "" then
log.chat(string.format("Password for %s is not set and no password was"
- .. " provided, no action taken.", user))
+ .. " provided, no action taken.", user))
return "exit", 0
end
@@ -313,7 +313,7 @@ local function builtin_passwd_run(conf, _, cmdline, env)
end
local action = string.format("%s password for %s",
- password ~= '' and "Update" or "Remove", user)
+ password ~= '' and "Update" or "Remove", user)
ok, msg = config.commit(conf, action, user)
@@ -323,21 +323,21 @@ local function builtin_passwd_run(conf, _, cmdline, env)
end
log.chat(string.format("%s password for %s",
- password ~= '' and "Updated" or "Removed", user))
+ password ~= '' and "Updated" or "Removed", user))
return "exit", 0
end
local function register_commands(reg)
assert(reg("whoami", builtin_whoami_short, builtin_whoami_helptext,
- builtin_whoami_validate,
- builtin_whoami_prep, builtin_whoami_run, false, false))
+ builtin_whoami_validate,
+ builtin_whoami_prep, builtin_whoami_run, false, false))
assert(reg("sshkey", builtin_sshkey_short, builtin_sshkey_helptext,
- builtin_sshkey_validate, builtin_sshkey_prep,
- builtin_sshkey_run, false, false))
+ builtin_sshkey_validate, builtin_sshkey_prep,
+ builtin_sshkey_run, false, false))
assert(reg("passwd", builtin_passwd_short, builtin_passwd_helptext,
- builtin_passwd_validate, builtin_passwd_prep,
- builtin_passwd_run, false, false))
+ builtin_passwd_validate, builtin_passwd_prep,
+ builtin_passwd_run, false, false))
end
return {
diff --git a/lib/gitano/util.lua b/lib/gitano/util.lua
index f2dd391..4b0c8c6 100644
--- a/lib/gitano/util.lua
+++ b/lib/gitano/util.lua
@@ -30,14 +30,14 @@ local function run_command(cmd, cmdline, parsed_cmdline, user,
if how ~= "exit" or why ~= 0 then
if not cmd.suppress_error_msgs then
- log.critical(i18n.expand("ERROR_RUNNING_COMMAND",
- {cmd=parsed_cmdline[1], reason=how, code=why}))
- log.critical(i18n.expand("UNABLE_TO_CONTINUE"))
+ log.critical(i18n.expand("ERROR_RUNNING_COMMAND",
+ {cmd=parsed_cmdline[1], reason=how, code=why}))
+ log.critical(i18n.expand("UNABLE_TO_CONTINUE"))
end
return why, cmd.suppress_error_msgs
else
log.syslog.info(i18n.expand("MSG_COMPLETED_SUCCESSFULLY",
- {cmd=cmdline}))
+ {cmd=cmdline}))
return 0, false
end
end
@@ -58,10 +58,10 @@ local function _deep_copy(t, memo)
for k, v in pairs(t) do
kk, vv = k, v
if type(k) == "table" then
- kk = _deep_copy(k, memo)
+ kk = _deep_copy(k, memo)
end
if type(v) == "table" then
- vv = _deep_copy(v, memo)
+ vv = _deep_copy(v, memo)
end
ret[kk] = vv
end
@@ -76,43 +76,43 @@ local function _parse_cmdline(cmdline)
local quoting = false
while #cmdline > 0 do
c, cmdline = cmdline:match("^(.)(.*)$")
- if escaping then
- if c == "n" then
- acc = acc .. "\n"
- elseif c == "t" then
- acc = acc .. "\t"
- else
- acc = acc .. c
- end
- escaping = false
+ if escaping then
+ if c == "n" then
+ acc = acc .. "\n"
+ elseif c == "t" then
+ acc = acc .. "\t"
+ else
+ acc = acc .. c
+ end
+ escaping = false
else
- if c == "'" and quoting == false then
- -- Start single quotes
- quoting = c
- elseif c == '"' and quoting == false then
- -- Start double quotes
- quoting = c
- elseif c == "'" and quoting == c then
- -- End single quotes
- quoting = false
- elseif c == '"' and quoting == c then
- -- End double quotes
- quoting = false
- elseif c == "\\" then
- -- A backslash, entering escaping mode
- escaping = true
- elseif quoting then
- -- Within quotes, so accumulate
- acc = acc .. c
- elseif c == " " then
- -- A space and not quoting, so clear the accumulator
- if acc ~= "" then
- r[#r+1] = acc
- end
- acc = ""
- else
- acc = acc .. c
- end
+ if c == "'" and quoting == false then
+ -- Start single quotes
+ quoting = c
+ elseif c == '"' and quoting == false then
+ -- Start double quotes
+ quoting = c
+ elseif c == "'" and quoting == c then
+ -- End single quotes
+ quoting = false
+ elseif c == '"' and quoting == c then
+ -- End double quotes
+ quoting = false
+ elseif c == "\\" then
+ -- A backslash, entering escaping mode
+ escaping = true
+ elseif quoting then
+ -- Within quotes, so accumulate
+ acc = acc .. c
+ elseif c == " " then
+ -- A space and not quoting, so clear the accumulator
+ if acc ~= "" then
+ r[#r+1] = acc
+ end
+ acc = ""
+ else
+ acc = acc .. c
+ end
end
end
if acc ~= "" then
@@ -162,7 +162,7 @@ local function basename(path, ext)
if ext then
local pat = patesc(ext) .. "$"
if ret:find(pat) then
- ret = ret:sub(1, -(#ext+1))
+ ret = ret:sub(1, -(#ext+1))
end
end
return ret
@@ -180,14 +180,14 @@ local function mkdir_p(path, mode)
if path:find("/") then
local ok, msg = mkdir_p(dirname(path))
if not ok then
- return ok, msg
+ return ok, msg
end
end
local r, err = luxio.mkdir(path, mode)
if r < 0 then
if err == luxio.EEXIST then
- return true
+ return true
end
return nil, "mkdir(" .. path .. "): " .. luxio.strerror(err)
end
@@ -204,18 +204,18 @@ local function rm_rf(path)
repeat
e, i = luxio.readdir(dirp)
if e == 0 then
- if i.d_name ~= "." and i.d_name ~= ".." then
- local elem = path .. "/" .. i.d_name
- ret, err = luxio.unlink(elem)
- if ret ~= 0 and err == luxio.EISDIR then
- ret, err = rm_rf(elem)
- if not ret then
- return ret, err
- end
- elseif ret ~= 0 then
- return false, luxio.strerror(err)
- end
- end
+ if i.d_name ~= "." and i.d_name ~= ".." then
+ local elem = path .. "/" .. i.d_name
+ ret, err = luxio.unlink(elem)
+ if ret ~= 0 and err == luxio.EISDIR then
+ ret, err = rm_rf(elem)
+ if not ret then
+ return ret, err
+ end
+ elseif ret ~= 0 then
+ return false, luxio.strerror(err)
+ end
+ end
end
until not e
@@ -259,14 +259,14 @@ local function copy_file(from, to, buffer_size)
return false, emsg
end
if bytes then
- ok, write_count, emsg = _write_all(tofile, bytes)
- if not ok then
- fromfile:close()
- tofile:close()
- return false, emsg
- end
+ ok, write_count, emsg = _write_all(tofile, bytes)
+ if not ok then
+ fromfile:close()
+ tofile:close()
+ return false, emsg
+ end
else
- write_count = 0
+ write_count = 0
end
until write_count == 0
fromfile:close()
@@ -287,11 +287,11 @@ local function copy_symlink(from, to)
local link_target, ret, err
ret, link_target = luxio.readlink(from)
if ret == -1 then
- return false, luxio.strerror(link_target)
+ return false, luxio.strerror(link_target)
end
ret, err = luxio.symlink(link_target, to)
if ret ~= 0 then
- return false, luxio.strerror(err)
+ return false, luxio.strerror(err)
end
return true
end
@@ -327,24 +327,24 @@ local function copy_dir(from, to, copy_cbs, filter_cb)
-- Stat and translate mode to type if type unknown
local stat, err = sio.lstat(filefrom)
if not stat then
- log.critical(i18n.expand("ERROR_STAT_FILE_FAILED",
- {file=filefrom, reason=err}))
- return false, err
+ log.critical(i18n.expand("ERROR_STAT_FILE_FAILED",
+ {file=filefrom, reason=err}))
+ return false, err
end
fileinfo.d_type = ({
- [luxio.S_IFBLK] = luxio.DT_BLK,
- [luxio.S_IFCHR] = luxio.DT_CHR,
- [luxio.S_IFDIR] = luxio.DT_DIR,
- [luxio.S_IFIFO] = luxio.DT_FIFO,
- [luxio.S_IFLNK] = luxio.DT_LNK,
- [luxio.S_IFREG] = luxio.DT_REG,
- [luxio.S_IFSOCK] = luxio.DT_SOCK,
- })[luxio.bit.band(stat.mode, luxio.S_IFMT)]
+ [luxio.S_IFBLK] = luxio.DT_BLK,
+ [luxio.S_IFCHR] = luxio.DT_CHR,
+ [luxio.S_IFDIR] = luxio.DT_DIR,
+ [luxio.S_IFIFO] = luxio.DT_FIFO,
+ [luxio.S_IFLNK] = luxio.DT_LNK,
+ [luxio.S_IFREG] = luxio.DT_REG,
+ [luxio.S_IFSOCK] = luxio.DT_SOCK,
+ })[luxio.bit.band(stat.mode, luxio.S_IFMT)]
end
local fileto = path_join(to, filename)
local copycb = copy_cbs[fileinfo.d_type]
if not copycb then
- return false, i18n.expand("ERROR_NO_CB")
+ return false, i18n.expand("ERROR_NO_CB")
end
if filter_cb(from, filename, fileinfo) then
log.ddebug(i18n.expand("MSG_SKIPPING_FILE", {file=filename}))
@@ -352,29 +352,29 @@ local function copy_dir(from, to, copy_cbs, filter_cb)
log.ddebug(i18n.expand("MSG_COPYING_FILE", {from=filefrom, to=fileto}))
ret, err = copycb(filefrom, fileto)
if not ret then
- log.critical(i18n.expand("ERROR_COPY_FILE_FAILED",
- {from=filefrom, to=fileto, reason=err}))
+ log.critical(i18n.expand("ERROR_COPY_FILE_FAILED",
+ {from=filefrom, to=fileto, reason=err}))
return false, err
end
elseif fileinfo.d_type == luxio.DT_LNK then
log.ddebug(i18n.expand("MSG_COPYING_SYMLINK", {from=filefrom, to=fileto}))
ret, err = copycb(filefrom, fileto)
if not ret then
- log.critical(i18n.expand("ERROR_COPY_SYMLINK_FAILED",
- {from=filefrom, to=fileto, reason=err}))
+ log.critical(i18n.expand("ERROR_COPY_SYMLINK_FAILED",
+ {from=filefrom, to=fileto, reason=err}))
return false, err
end
elseif fileinfo.d_type == luxio.DT_DIR then
log.ddebug(i18n.expand("MSG_COPYING_DIR", {from=filefrom, to=fileto}))
ret, err = copycb(filefrom, fileto, copy_cbs, filter_cb)
if not ret then
- log.critical(i18n.expand("ERROR_COPY_DIR_FAILED",
- {from=filefrom, to=fileto, reason=err}))
+ log.critical(i18n.expand("ERROR_COPY_DIR_FAILED",
+ {from=filefrom, to=fileto, reason=err}))
return ret, err
end
else
return false, i18n.expand("ERROR_UNSUPPORTED_TYPE",
- {type=tostring(fileinfo.d_type)})
+ {type=tostring(fileinfo.d_type)})
end
end
return true
@@ -388,9 +388,9 @@ copy_dir_copy_callbacks = {
local function html_escape(s)
return (s:gsub("&", "&amp;"):
- gsub("<", "&lt;"):
- gsub(">", "&gt;"):
- gsub('"', "&quot;"))
+ gsub("<", "&lt;"):
+ gsub(">", "&gt;"):
+ gsub('"', "&quot;"))
end
local tagname_pattern = "^[a-z0-9_%-/]*[a-z0-9_%-]*$"
@@ -414,31 +414,31 @@ local function prep_expansion(str)
while #str > 0 do
c, str = str:match("^(.)(.*)$")
if seen == false then
- if c == "$" then
- seen = c
- else
- acc = acc .. c
- end
+ if c == "$" then
+ seen = c
+ else
+ acc = acc .. c
+ end
elseif seen == "$" then
- if c == "{" then
- seen = c
- if acc ~= "" then
- ret[#ret+1] = acc
- acc = ""
- end
- else
- acc = acc .. c
- seen = false
- end
+ if c == "{" then
+ seen = c
+ if acc ~= "" then
+ ret[#ret+1] = acc
+ acc = ""
+ end
+ else
+ acc = acc .. c
+ seen = false
+ end
elseif seen == "{" then
- if c == "}" then
- seen = false
- assert(acc:match(tagname_pattern), i18n.expand("ERROR_EXPECTED_TAG_NAME"))
- ret[#ret+1] = { acc }
- acc = ""
- else
- acc = acc .. c
- end
+ if c == "}" then
+ seen = false
+ assert(acc:match(tagname_pattern), i18n.expand("ERROR_EXPECTED_TAG_NAME"))
+ ret[#ret+1] = { acc }
+ acc = ""
+ else
+ acc = acc .. c
+ end
end
end
if seen == "$" then
@@ -467,26 +467,26 @@ local function process_expansion(tags, expn, tagsactive)
for i = 1, #expn do
local elem = expn[i]
if type(elem) == "string" then
- r[#r+1] = elem
+ r[#r+1] = elem
else
- elem = elem[1]
- if tagsactive[elem] then
- return do_deny(tags, i18n.expand("ERROR_LOOP_IN_EXPN"))
- end
- local tag = tags[elem]
- if type(tag) == "function" then
- tags[elem] = tag(tags)
- tag = tags[elem]
- end
- if type(tag) == "string" then
- tagsactive[elem] = true
- tag = process_expansion(tags, tag, tagsactive)
- tagsactive[elem] = nil
- else
- -- Can't implicitly expand lists etc.
- tag = ""
- end
- r[#r+1] = tag
+ elem = elem[1]
+ if tagsactive[elem] then
+ return do_deny(tags, i18n.expand("ERROR_LOOP_IN_EXPN"))
+ end
+ local tag = tags[elem]
+ if type(tag) == "function" then
+ tags[elem] = tag(tags)
+ tag = tags[elem]
+ end
+ if type(tag) == "string" then
+ tagsactive[elem] = true
+ tag = process_expansion(tags, tag, tagsactive)
+ tagsactive[elem] = nil
+ else
+ -- Can't implicitly expand lists etc.
+ tag = ""
+ end
+ r[#r+1] = tag
end
end
return tconcat(r)
@@ -502,7 +502,7 @@ local function set(t)
end
local function add_splitable(context, key, value, splitter,
- prefix_name, suffix_name)
+ prefix_name, suffix_name)
if not value or value == "" then
return
end
@@ -511,7 +511,7 @@ local function add_splitable(context, key, value, splitter,
end
_(key, value)
local prefix, suffix = value:match("^(.*%" .. splitter .. ")" ..
- "([^%" .. splitter .. "]+)$")
+ "([^%" .. splitter .. "]+)$")
if prefix then
_(key .. "/" .. prefix_name, prefix:sub(1, -2))
@@ -532,14 +532,14 @@ local function tempfile(repo)
local repopath = repo:fs_path()
local temppattern = path_join(
repopath, ("gitanotmp.%d.%d.XXXXXX"):format(tempfilecounter,
- luxio.getpid()))
+ luxio.getpid()))
tempfilecounter = tempfilecounter + 1
if luxio.mkstemp then
return luxio.mkstemp(temppattern)
end
-- No mkstemp so let's hope that the %d.%d is enough...
local fd = luxio.open(temppattern, luxio.O_RDWR + luxio.O_CREAT,
- tonumber("700", 8))
+ tonumber("700", 8))
return fd, temppattern
end