Add interactive prompt for managing keys
This commit is contained in:
parent
38b661aa06
commit
101d4e5cd4
51
prompt.rb
Normal file
51
prompt.rb
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
require_relative 'collab'
|
||||||
|
require 'tty-prompt'
|
||||||
|
|
||||||
|
$prompt = TTY::Prompt.new
|
||||||
|
|
||||||
|
|
||||||
|
def init
|
||||||
|
choices = %w(Keys Users Quit)
|
||||||
|
case $prompt.select("What do you want to do?", choices)
|
||||||
|
when "Users"
|
||||||
|
users
|
||||||
|
when "Keys"
|
||||||
|
keys
|
||||||
|
when "Quit"
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def keys
|
||||||
|
choices = $users
|
||||||
|
user = $prompt.select("Pick a user", choices)
|
||||||
|
keys_user(user)
|
||||||
|
end
|
||||||
|
|
||||||
|
def keys_user(user)
|
||||||
|
choices = {'List keys' => :list ,'Add key' => :add, 'Remove key' => :remove, 'Reset authorized_keys' => :reset}
|
||||||
|
case $prompt.select("What do you want to do for user #{user}?", choices)
|
||||||
|
when :list
|
||||||
|
get_ssh_pubkeys(user).each{|k| puts k.pretty}
|
||||||
|
keys_user user
|
||||||
|
when :add
|
||||||
|
key = $prompt.ask("Please enter a valid public SSH key", echo: false)
|
||||||
|
add_ssh_pubkey(user,key)
|
||||||
|
when :remove
|
||||||
|
keys = get_ssh_pubkeys(user)#.map{|k| puts k.pretty}
|
||||||
|
key = $prompt.select("Select the key to delete", keys)
|
||||||
|
unless $prompt.no?("Are you sure you want to delete this key?")
|
||||||
|
remove_ssh_pubkey(user,key)
|
||||||
|
end
|
||||||
|
when :reset
|
||||||
|
unless $prompt.no?("Are you sure you want to reset the keys for this user?")
|
||||||
|
unless $prompt.no?("Really sure?")
|
||||||
|
reset_pubkeys(user)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
while true
|
||||||
|
init
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user