diff options
author | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2014-03-13 18:03:39 +0100 |
---|---|---|
committer | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2014-03-14 11:53:41 +0100 |
commit | 3a48eae79eafe1d3641b0aa4271b83b348a95ee6 (patch) | |
tree | 398d32db7a41036c088e44bcad387692f294f74f /lib/gitlab_keys.rb | |
parent | bde689a8d326db46a79444143e35abfd6a47c419 (diff) | |
download | gitlab-shell-3a48eae79eafe1d3641b0aa4271b83b348a95ee6.tar.gz |
Add gitlab-keys batch-add-keys
This command is intended to be called by the GitLab Rails code when
restoring an application backup.
Diffstat (limited to 'lib/gitlab_keys.rb')
-rw-r--r-- | lib/gitlab_keys.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/gitlab_keys.rb b/lib/gitlab_keys.rb index 26d781f..cade09e 100644 --- a/lib/gitlab_keys.rb +++ b/lib/gitlab_keys.rb @@ -16,6 +16,7 @@ class GitlabKeys def exec case @command when 'add-key'; add_key + when 'batch-add-keys'; batch_add_keys when 'rm-key'; rm_key when 'clear'; clear else @@ -34,6 +35,23 @@ class GitlabKeys true end + def batch_add_keys + open(auth_file, 'a') do |file| + stdin.each_line do |input| + tokens = input.strip.split("\t") + abort("#{$0}: invalid input #{input.inspect}") unless tokens.count == 2 + key_id, public_key = tokens + $logger.info "Adding key #{key_id} => #{public_key.inspect}" + file.puts(key_line(key_id, public_key)) + end + end + true + end + + def stdin + $stdin + end + def key_line(key_id, public_key) auth_line = "command=\"#{ROOT_PATH}/bin/gitlab-shell #{key_id}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty #{public_key}" end |