66class GitlabKeys
77 attr_accessor :auth_file , :key
88
9+ def self . command ( key_id )
10+ "#{ ROOT_PATH } /bin/gitlab-shell #{ key_id } "
11+ end
12+
13+ def self . key_line ( key_id , public_key )
14+ "command=\" #{ command ( key_id ) } \" ,no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty #{ public_key } "
15+ end
16+
917 def initialize
1018 @command = ARGV . shift
1119 @key_id = ARGV . shift
1220 @key = ARGV . shift
1321 @auth_file = GitlabConfig . new . auth_file
14- @gitlab_key = GitlabKey . new
1522 end
1623
1724 def exec
@@ -34,7 +41,7 @@ def exec
3441 def add_key
3542 lock do
3643 $logger. info "Adding key #{ @key_id } => #{ @key . inspect } "
37- auth_line = @gitlab_key . key_line ( @key_id , @key )
44+ auth_line = self . class . key_line ( @key_id , @key )
3845 open_auth_file ( 'a' ) { |file | file . puts ( auth_line ) }
3946 end
4047 true
@@ -61,7 +68,7 @@ def batch_add_keys
6168 abort ( "#{ $0} : invalid input #{ input . inspect } " ) unless tokens . count == 2
6269 key_id , public_key = tokens
6370 $logger. info "Adding key #{ key_id } => #{ public_key . inspect } "
64- file . puts ( @gitlab_key . key_line ( key_id , public_key ) )
71+ file . puts ( self . class . key_line ( key_id , public_key ) )
6572 end
6673 end
6774 end
@@ -77,7 +84,7 @@ def rm_key
7784 $logger. info "Removing key #{ @key_id } "
7885 open_auth_file ( 'r+' ) do |f |
7986 while line = f . gets do
80- next unless line . start_with? ( "command=\" #{ @gitlab_key . command ( @key_id ) } \" " )
87+ next unless line . start_with? ( "command=\" #{ self . class . command ( @key_id ) } \" " )
8188 f . seek ( -line . length , IO ::SEEK_CUR )
8289 # Overwrite the line with #'s. Because the 'line' variable contains
8390 # a terminating '\n', we write line.length - 1 '#' characters.
@@ -128,14 +135,3 @@ def open_auth_file(mode)
128135 end
129136 end
130137end
131-
132-
133- class GitlabKey
134- def command ( key_id )
135- "#{ ROOT_PATH } /bin/gitlab-shell #{ key_id } "
136- end
137-
138- def key_line ( key_id , public_key )
139- "command=\" #{ command ( key_id ) } \" ,no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty #{ public_key } "
140- end
141- end
0 commit comments