summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Martin <david.martin@feedhenry.com>2014-09-16 17:20:24 +0100
committerDavid Martin <david.martin@feedhenry.com>2014-10-15 10:21:05 +0100
commit89d8af466ba283b31d7800fe604defa0ce189902 (patch)
treefefe901225ff8b59f6d6ecc60d7ae6678456afc5 /lib
parent7e74d0547255a9cf60f00b9d9133aa8b2c546507 (diff)
downloadgitlab-shell-89d8af466ba283b31d7800fe604defa0ce189902.tar.gz
Added list-keys command and spec
Removed puts and tidied up regex Address the hound Address the hound, again Use single quotes Add back travis.yml file Remove travis.yml, only keep on fh-master Use single quotes Use single quotes
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab_keys.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/gitlab_keys.rb b/lib/gitlab_keys.rb
index 3bdf6c6..100e164 100644
--- a/lib/gitlab_keys.rb
+++ b/lib/gitlab_keys.rb
@@ -19,6 +19,7 @@ class GitlabKeys
when 'add-key'; add_key
when 'batch-add-keys'; batch_add_keys
when 'rm-key'; rm_key
+ when 'list-keys'; puts list_keys
when 'clear'; clear
else
$logger.warn "Attempt to execute invalid gitlab-keys command #{@command.inspect}."
@@ -38,6 +39,19 @@ class GitlabKeys
true
end
+ def list_keys
+ $logger.info 'Listing all keys'
+ keys = ''
+ File.readlines(auth_file).each do |line|
+ # key_id & public_key
+ # command=".../bin/gitlab-shell key-741" ... ssh-rsa AAAAB3NzaDAxx2E\n
+ # ^^^^^^^ ^^^^^^^^^^^^^^^
+ matches = /^command=\".+?\s+(.+?)\".+?ssh-rsa\s(.+)\s*.*\n*$/.match(line)
+ keys << "#{matches[1]} #{matches[2]}\n" unless matches.nil?
+ end
+ keys
+ end
+
def batch_add_keys
lock do
open(auth_file, 'a') do |file|