summaryrefslogtreecommitdiff
path: root/lib/gitlab_keys.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab_keys.rb')
-rw-r--r--lib/gitlab_keys.rb18
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