summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2014-12-20 00:34:57 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2014-12-20 00:34:57 -0500
commit86371934d0c6869a2b65bd68e203b24dccab908e (patch)
tree383b4c1261d0d6c17e60cc94ec5a396b13e762ab
parent324e5028926dcac8a2fe794955cc092332e3828c (diff)
rethink how ssh-list-authorized-keys groups work
-rwxr-xr-xbin/ssh-list-authorized-keys17
1 files changed, 11 insertions, 6 deletions
diff --git a/bin/ssh-list-authorized-keys b/bin/ssh-list-authorized-keys
index fc329f2..bb153e1 100755
--- a/bin/ssh-list-authorized-keys
+++ b/bin/ssh-list-authorized-keys
@@ -1,18 +1,23 @@
#!/usr/bin/env ruby
# Usage: ssh-list-authorized-keys [username]
-cfg_groups = [ "hackers", "bots" ]
+cfg_groups = [ "repo", "git" ]
######################################################################
+require 'set'
require 'yaml'
-users = Dir.glob("users/*.yml").map{|f|YAML::load(open(f))}
+all_users = Dir.glob("users/*.yml").map{|f|YAML::load(open(f))}
+users = Set.new
-if ARGV[0]
- users = users.find_all{|u|u["username"] == ARGV[0]}
-else
- users = users.find_all{|u|u["groups"] and not (u["groups"] & cfg_groups).empty?}
+groupnames = ARGV & cfg_groups
+usernames = ARGV & all_users.map{|u|u["username"]}
+
+unless groupnames.empty?
+ groupnames.push("hackers")
end
+users = all_users.find_all{|u| usernames.include?(u["username"]) or not ((u["groups"]||[]) & groupnames).empty?}
+
users.each do |user|
if user["ssh_keys"]
user["ssh_keys"].each do |addr,key|