diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-06-17 15:44:40 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-06-17 15:44:40 +0100 |
commit | 9ed736a0822c7e61a27fe585a22fba601bbb7791 (patch) | |
tree | aa926faa16e30642d2af6bd45c6374a2db0bb6a2 | |
parent | d313a881e5185c1ddf03faa25582ea7e1345f1c6 (diff) | |
download | gitano-9ed736a0822c7e61a27fe585a22fba601bbb7791.tar.gz |
CONFIG: Move ssh authorized_keys generation into gitano.config for reuse
-rw-r--r-- | bin/gitano-update-ssh | 28 | ||||
-rw-r--r-- | lib/gitano/config.lua | 46 |
2 files changed, 45 insertions, 29 deletions
diff --git a/bin/gitano-update-ssh b/bin/gitano-update-ssh index 5c928cf..ed96bab 100644 --- a/bin/gitano-update-ssh +++ b/bin/gitano-update-ssh @@ -40,32 +40,6 @@ if not config then gitano.log.fatal("Cannot continue") end -local ssh_config = gitano.config.genssh(config) - -local home = luxio.getenv "HOME" - -if not home then - gitano.log.fatal("Unable to find HOME") -end - -local ssh_path = home .. "/.ssh/authorized_keys" - -local create_path = ssh_path .. ".new" - -local cfh, err = sio.open(create_path, "cew") - -if not cfh or cfh == -1 then - gitano.log.fatal("Unable to create " .. create_path) -end - -cfh:write(ssh_config) -cfh:close() - -local ret, errno = luxio.rename(create_path, ssh_path) -if ret ~= 0 then - gitano.log.fatal("Unable to overwrite " .. ssh_path) -end - -gitano.log.chat "SSH authorised key file updated" +gitano.config.writessh(config) return 0 diff --git a/lib/gitano/config.lua b/lib/gitano/config.lua index b784595..fa30e64 100644 --- a/lib/gitano/config.lua +++ b/lib/gitano/config.lua @@ -12,6 +12,7 @@ local sb = require 'gitano.sandbox' local git = require 'gitano.git' local log = require 'gitano.log' local lace = require 'gitano.lace' +local sio = require 'luxio.simple' local pcall = pcall local pairs = pairs @@ -263,6 +264,36 @@ local function generate_ssh_config(conf) return tconcat(ret, "\n") end +local function update_ssh_keys(conf) + local ssh_config = generate_ssh_config(conf) + + local home = luxio.getenv "HOME" + + if not home then + log.fatal("Unable to find HOME") + end + + local ssh_path = home .. "/.ssh/authorized_keys" + + local create_path = ssh_path .. ".new" + + local cfh, err = sio.open(create_path, "cew") + + if not cfh or cfh == -1 then + gitano.log.fatal("Unable to create " .. create_path) + end + + cfh:write(ssh_config) + cfh:close() + + local ret, errno = luxio.rename(create_path, ssh_path) + if ret ~= 0 then + log.fatal("Unable to overwrite " .. ssh_path) + end + + log.chat "SSH authorised key file updated" +end + local function populate_context(conf, ctx, username) if ctx.user and not username then username = ctx.user @@ -369,19 +400,30 @@ local function commit_config_changes(conf, desc, username) if not commit then return nil, msg end - -- Finally create/update the HEAD ref + + -- Verify we can parse the updated configuration repository + local newconf, msg = parse_admin_config(commit) + if not newconf then + return nil, msg + end + + -- Create/Update the HEAD ref 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 - + + -- Okay, updated, so apply the new config... (SSH keys really) + update_ssh_keys(newconf) + return true, commit end return { genssh = generate_ssh_config, + writessh = update_ssh_keys, parse = parse_admin_config, populate_context = populate_context, commit = commit_config_changes, |