summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG2
-rw-r--r--lib/gitlab/backend/shell.rb16
-rw-r--r--lib/tasks/gitlab/check.rake2
-rw-r--r--lib/tasks/gitlab/shell.rake12
4 files changed, 26 insertions, 6 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 50cfc95ef33..785a4bb6713 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -21,7 +21,7 @@ v 6.7.0
- Reuse the GitLab LDAP connection within each request
- Changed markdown new line behaviour to conform to markdown standards
- Fix global search
-
+ - Faster authorized_keys rebuilding in `rake gitlab:shell:setup` (requires gitlab-shell 1.8.5)
v 6.6.2
- Fix 500 error on branch/tag create or remove via UI
diff --git a/lib/gitlab/backend/shell.rb b/lib/gitlab/backend/shell.rb
index 7121c8e40d2..b93800e235f 100644
--- a/lib/gitlab/backend/shell.rb
+++ b/lib/gitlab/backend/shell.rb
@@ -2,6 +2,12 @@ module Gitlab
class Shell
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
#
# name - project path with namespace
@@ -130,6 +136,16 @@ module Gitlab
system "#{gitlab_shell_path}/bin/gitlab-keys", "add-key", key_id, key_content
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
#
# Ex.
diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake
index 2b158fe14ee..c2e6cd1be78 100644
--- a/lib/tasks/gitlab/check.rake
+++ b/lib/tasks/gitlab/check.rake
@@ -727,7 +727,7 @@ namespace :gitlab do
end
def check_gitlab_shell
- required_version = Gitlab::VersionInfo.new(1, 8, 4)
+ required_version = Gitlab::VersionInfo.new(1, 8, 5)
current_version = Gitlab::VersionInfo.parse(gitlab_shell_version)
print "GitLab Shell version >= #{required_version} ? ... "
diff --git a/lib/tasks/gitlab/shell.rake b/lib/tasks/gitlab/shell.rake
index 0d7a390bc92..08de0f2dd5d 100644
--- a/lib/tasks/gitlab/shell.rake
+++ b/lib/tasks/gitlab/shell.rake
@@ -34,14 +34,18 @@ namespace :gitlab do
Gitlab::Shell.new.remove_all_keys
- Key.find_each(batch_size: 1000) do |key|
- if Gitlab::Shell.new.add_key(key.shell_id, key.key)
+ Gitlab::Shell.new.batch_add_keys do |adder|
+ Key.find_each(batch_size: 1000) do |key|
+ adder.add_key(key.shell_id, key.key)
print '.'
- else
- print 'F'
end
end
+ unless $?.success?
+ puts "Failed to add keys...".red
+ exit 1
+ end
+
rescue Gitlab::TaskAbortedByUserError
puts "Quitting...".red
exit 1