summaryrefslogtreecommitdiff
path: root/lib/gitlab_keys.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab_keys.rb')
-rw-r--r--lib/gitlab_keys.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/gitlab_keys.rb b/lib/gitlab_keys.rb
index 2ea5117..bc00867 100644
--- a/lib/gitlab_keys.rb
+++ b/lib/gitlab_keys.rb
@@ -36,12 +36,17 @@ class GitlabKeys
def rm_key
$logger.info "Removing key #{@key_id}"
Tempfile.open('authorized_keys') do |temp|
- cmd = "sed '/shell #{@key_id}\"/d' #{auth_file} > #{temp.path} && mv #{temp.path} #{auth_file}"
- system(cmd)
+ open(auth_file, 'r+') do |current|
+ current.each do |line|
+ temp.puts(line) unless line.include?("/bin/gitlab-shell #{@key_id}\"")
+ end
+ end
+ temp.close
+ FileUtils.cp(temp.path, auth_file)
end
end
def clear
- system("echo '# Managed by gitlab-shell' > #{auth_file}")
+ open(auth_file, 'w') { |file| file.puts '# Managed by gitlab-shell' }
end
end