-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathssh_key_adder.rb
More file actions
30 lines (27 loc) · 791 Bytes
/
Copy pathssh_key_adder.rb
File metadata and controls
30 lines (27 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/ruby
ENV_KEY = "AUTHORIZED_GH_USERS"
begin
`gem install github-auth --no-rdoc --no-ri`
`mkdir $USER_HOME/.ssh`
`touch $USER_HOME/.ssh/authorized_keys`
puts ENV[ENV_KEY]
ENV[ENV_KEY].split(",").map(&:strip).each do |username|
output = `gh-auth add --users=#{username}`
if output.include?("Adding 0 key")
puts <<-EOS
The user '#{username}' either does not exist on GitHub or does not have
any SSH keys uploaded!
EOS
exit 1
end
puts "Authorized SSH key(s) for #{username}..."
end
rescue Exception => e
puts e
puts <<-EOS
You need to specify an #{ENV_KEY} environment variables as a
comma-separated list of GitHub users whose SSH keys should be authorized to
connect to this machine!
EOS
exit 1
end