Commit ecae936d344b7d29f1898f81ac283d444c086f0d

Authored by Dmitriy Zaporozhets
2 parents 66a484c9 090ed21e

Merge branch 'batch_key_import' into 'master'

Batch Key Import
CHANGELOG
... ... @@ -21,7 +21,7 @@ v 6.7.0
21 21 - Reuse the GitLab LDAP connection within each request
22 22 - Changed markdown new line behaviour to conform to markdown standards
23 23 - Fix global search
24   -
  24 + - Faster authorized_keys rebuilding in `rake gitlab:shell:setup` (requires gitlab-shell 1.8.5)
25 25  
26 26 v 6.6.2
27 27 - Fix 500 error on branch/tag create or remove via UI
... ...
lib/gitlab/backend/shell.rb
... ... @@ -2,6 +2,12 @@ module Gitlab
2 2 class Shell
3 3 class AccessDenied < StandardError; end
4 4  
  5 + class KeyAdder < Struct.new(:io)
  6 + def add_key(id, key)
  7 + io.puts("#{id}\t#{key.strip}")
  8 + end
  9 + end
  10 +
5 11 # Init new repository
6 12 #
7 13 # name - project path with namespace
... ... @@ -130,6 +136,16 @@ module Gitlab
130 136 system "#{gitlab_shell_path}/bin/gitlab-keys", "add-key", key_id, key_content
131 137 end
132 138  
  139 + # Batch-add keys to authorized_keys
  140 + #
  141 + # Ex.
  142 + # batch_add_keys { |adder| adder.add_key("key-42", "sha-rsa ...") }
  143 + def batch_add_keys(&block)
  144 + IO.popen(%W(#{gitlab_shell_path}/bin/gitlab-keys batch-add-keys), 'w') do |io|
  145 + block.call(KeyAdder.new(io))
  146 + end
  147 + end
  148 +
133 149 # Remove ssh key from gitlab shell
134 150 #
135 151 # Ex.
... ...
lib/tasks/gitlab/check.rake
... ... @@ -727,7 +727,7 @@ namespace :gitlab do
727 727 end
728 728  
729 729 def check_gitlab_shell
730   - required_version = Gitlab::VersionInfo.new(1, 8, 4)
  730 + required_version = Gitlab::VersionInfo.new(1, 8, 5)
731 731 current_version = Gitlab::VersionInfo.parse(gitlab_shell_version)
732 732  
733 733 print "GitLab Shell version >= #{required_version} ? ... "
... ...
lib/tasks/gitlab/shell.rake
... ... @@ -34,14 +34,18 @@ namespace :gitlab do
34 34  
35 35 Gitlab::Shell.new.remove_all_keys
36 36  
37   - Key.find_each(batch_size: 1000) do |key|
38   - if Gitlab::Shell.new.add_key(key.shell_id, key.key)
  37 + Gitlab::Shell.new.batch_add_keys do |adder|
  38 + Key.find_each(batch_size: 1000) do |key|
  39 + adder.add_key(key.shell_id, key.key)
39 40 print '.'
40   - else
41   - print 'F'
42 41 end
43 42 end
44 43  
  44 + unless $?.success?
  45 + puts "Failed to add keys...".red
  46 + exit 1
  47 + end
  48 +
45 49 rescue Gitlab::TaskAbortedByUserError
46 50 puts "Quitting...".red
47 51 exit 1
... ...