Commit 779fa4a7 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Use batch_add_keys in `rake gitlab:shell:setup`

parent 17a9ecf8
...@@ -21,7 +21,7 @@ v 6.7.0 ...@@ -21,7 +21,7 @@ v 6.7.0
- Reuse the GitLab LDAP connection within each request - Reuse the GitLab LDAP connection within each request
- Changed markdown new line behaviour to conform to markdown standards - Changed markdown new line behaviour to conform to markdown standards
- Fix global search - Fix global search
- Faster authorized_keys rebuilding in `rake gitlab:shell:setup` (requires gitlab-shell 1.8.4)
v 6.6.2 v 6.6.2
- Fix 500 error on branch/tag create or remove via UI - Fix 500 error on branch/tag create or remove via UI
......
...@@ -2,6 +2,12 @@ module Gitlab ...@@ -2,6 +2,12 @@ module Gitlab
class Shell class Shell
class AccessDenied < StandardError; end class AccessDenied < StandardError; end
class KeyAdder < Struct.new(:io)
def add_key(id, key)
io.puts("#{id}\t#{key.strip}")
end
end
# Init new repository # Init new repository
# #
# name - project path with namespace # name - project path with namespace
...@@ -130,6 +136,16 @@ module Gitlab ...@@ -130,6 +136,16 @@ module Gitlab
system "#{gitlab_shell_path}/bin/gitlab-keys", "add-key", key_id, key_content system "#{gitlab_shell_path}/bin/gitlab-keys", "add-key", key_id, key_content
end end
# Batch-add keys to authorized_keys
#
# Ex.
# batch_add_keys { |adder| adder.add_key("key-42", "sha-rsa ...") }
def batch_add_keys(&block)
IO.popen(%W(#{gitlab_shell_path}/bin/gitlab-keys batch-add-keys), 'w') do |io|
block.call(KeyAdder.new(io))
end
end
# Remove ssh key from gitlab shell # Remove ssh key from gitlab shell
# #
# Ex. # Ex.
......
...@@ -34,14 +34,18 @@ namespace :gitlab do ...@@ -34,14 +34,18 @@ namespace :gitlab do
Gitlab::Shell.new.remove_all_keys Gitlab::Shell.new.remove_all_keys
Key.find_each(batch_size: 1000) do |key| Gitlab::Shell.new.batch_add_keys do |adder|
if Gitlab::Shell.new.add_key(key.shell_id, key.key) Key.find_each(batch_size: 1000) do |key|
adder.add_key(key.shell_id, key.key)
print '.' print '.'
else
print 'F'
end end
end end
unless $?.success?
puts "Failed to add keys...".red
exit 1
end
rescue Gitlab::TaskAbortedByUserError rescue Gitlab::TaskAbortedByUserError
puts "Quitting...".red puts "Quitting...".red
exit 1 exit 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment