summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2016-08-04 17:31:28 +0000
committerRobert Speicher <robert@gitlab.com>2016-08-04 17:31:28 +0000
commit7837894a8a740f8ed9a4884fa7faee566eb9b6c2 (patch)
tree8b1d13b00763926c58802e10a595b68017193d52
parent933526140fa77d91eebb73469e567280c75d11dd (diff)
parent1ea542c0cf25a296786975035f629c0c8bc23e3b (diff)
downloadgitlab-shell-7837894a8a740f8ed9a4884fa7faee566eb9b6c2.tar.gz
Merge branch 'small-fixes' into 'master'
Small improvements - refactor GitlabKey away - fix Redis check output See merge request !81
-rwxr-xr-xbin/authorized_keys2
-rwxr-xr-xbin/check8
-rw-r--r--lib/gitlab_keys.rb26
3 files changed, 19 insertions, 17 deletions
diff --git a/bin/authorized_keys b/bin/authorized_keys
index 6aab4a5..ca01646 100755
--- a/bin/authorized_keys
+++ b/bin/authorized_keys
@@ -21,5 +21,5 @@ authorized_key = GitlabNet.new.authorized_key(key)
if authorized_key.nil?
puts "# No key was found for #{key}"
else
- puts GitlabKey.new.key_line("key-#{authorized_key['id']}", authorized_key["key"])
+ puts GitlabKeys.key_line("key-#{authorized_key['id']}", authorized_key["key"])
end
diff --git a/bin/check b/bin/check
index d34a2d0..9585416 100755
--- a/bin/check
+++ b/bin/check
@@ -32,4 +32,10 @@ end
puts "\n"
print "Send ping to redis server: "
-abort unless GitlabNet.new.redis_client.ping
+if GitlabNet.new.redis_client.ping
+ print 'OK'
+else
+ abort 'FAILED'
+end
+
+puts "\n"
diff --git a/lib/gitlab_keys.rb b/lib/gitlab_keys.rb
index c719e8d..dc654fd 100644
--- a/lib/gitlab_keys.rb
+++ b/lib/gitlab_keys.rb
@@ -6,12 +6,19 @@ require_relative 'gitlab_logger'
class GitlabKeys
attr_accessor :auth_file, :key
+ def self.command(key_id)
+ "#{ROOT_PATH}/bin/gitlab-shell #{key_id}"
+ end
+
+ def self.key_line(key_id, public_key)
+ "command=\"#{command(key_id)}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty #{public_key}"
+ end
+
def initialize
@command = ARGV.shift
@key_id = ARGV.shift
@key = ARGV.shift
@auth_file = GitlabConfig.new.auth_file
- @gitlab_key = GitlabKey.new
end
def exec
@@ -34,7 +41,7 @@ class GitlabKeys
def add_key
lock do
$logger.info "Adding key #{@key_id} => #{@key.inspect}"
- auth_line = @gitlab_key.key_line(@key_id, @key)
+ auth_line = self.class.key_line(@key_id, @key)
open_auth_file('a') { |file| file.puts(auth_line) }
end
true
@@ -61,7 +68,7 @@ class GitlabKeys
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(@gitlab_key.key_line(key_id, public_key))
+ file.puts(self.class.key_line(key_id, public_key))
end
end
end
@@ -77,7 +84,7 @@ class GitlabKeys
$logger.info "Removing key #{@key_id}"
open_auth_file('r+') do |f|
while line = f.gets do
- next unless line.start_with?("command=\"#{@gitlab_key.command(@key_id)}\"")
+ next unless line.start_with?("command=\"#{self.class.command(@key_id)}\"")
f.seek(-line.length, IO::SEEK_CUR)
# Overwrite the line with #'s. Because the 'line' variable contains
# a terminating '\n', we write line.length - 1 '#' characters.
@@ -128,14 +135,3 @@ class GitlabKeys
end
end
end
-
-
-class GitlabKey
- def command(key_id)
- "#{ROOT_PATH}/bin/gitlab-shell #{key_id}"
- end
-
- def key_line(key_id, public_key)
- "command=\"#{command(key_id)}\",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty #{public_key}"
- end
-end