Class: Strongspace::Command::Keys
- Inherits:
-
Base
show all
- Defined in:
- lib/strongspace/commands/keys.rb
Instance Attribute Summary
Attributes inherited from Base
#args
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #strongspace
#base_command, #command, included
Methods included from Helpers
#ask, #backup_space?, #bin_folder, #command_name, #computername, #confirm, #confirm_command, #create_pid_file, #credentials_file, #credentials_folder, #delete_pid_file, #display, #error, #format_date, #gui_ssh_key, home_directory, #home_directory, #kill_via_pidfile, #launchd_agents_folder, #logs_folder, #pid_file_path, #pid_from_pid_file, #pids_folder, #plugins_folder, #process_running?, #redisplay, running_on_a_mac?, #running_on_a_mac?, #running_on_windows?, running_on_windows?, #shell, #space_exist?, support_directory, #support_directory
Instance Method Details
43
44
45
46
47
48
49
50
|
# File 'lib/strongspace/commands/keys.rb', line 43
def add
keyfile = args.first || find_key
key = File.read(keyfile)
display "Uploading ssh public key #{keyfile}"
strongspace.add_key(key)
end
|
57
58
59
60
|
# File 'lib/strongspace/commands/keys.rb', line 57
def clear
strongspace.remove_all_keys
display "All keys removed."
end
|
18
19
20
21
|
# File 'lib/strongspace/commands/keys.rb', line 18
def generate
`ssh-keygen`
return ($? == 0)
end
|
#generate_for_gui ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/strongspace/commands/keys.rb', line 23
def generate_for_gui
return unless running_on_a_mac?
FileUtils.mkdir "#{credentials_folder}" unless File.exist? "#{credentials_folder}"
File.open("#{credentials_folder}/known_hosts", "w") do |f|
f.write "*.strongspace.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEArXBYAoHZWVzLfHNMlgteAbq20AaCVcE1qALqVjYZerIpa3rBjNlv2i/2O8ul3OmSfcQwQGPTnABLqz9cozAbxF01eDfqUiSABUDT6m1/lY1a0V7RGS46Y/KJMVbOb4mVpxDZOVwBQh/DYTu7R55vFc93lXpE+tZboqnuq+LvJIZDqzoGTHIUprRs3sNY8Xegnz+m68P+tV6iLkXMRk8Gh8/IIavN4mXYhWPVbCv6Gqo2XhiYVMrCqLZFKLG0W6uwWY/xOhUjWxKDZMlqhyU/YUsMB5BZc9/x0t+Sc82OL+Eh3IB5EUmmCWnhm/LKxjMIn2UNe48BQqwaU/gozVtVPQ==\n"
end
if !File.exist? "#{credentials_folder}/#{computername}.rsa"
`/usr/bin/ssh-keygen -f \"#{credentials_folder}/#{computername}.rsa\" -b 2048 -C \" Strongspace App - #{computername}\" -q -N ""` unless File.exist? "#{credentials_folder}/#{computername}.rsa"
args[0] = "#{credentials_folder}/#{computername}.rsa.pub"
begin
add
rescue RestClient::Conflict => e end
end
end
|
#list ⇒ Object
Also known as:
index
3
4
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/strongspace/commands/keys.rb', line 3
def list
long = args.any? { |a| a == '--long' }
keys = strongspace.keys
if keys.empty?
display "No keys for #{strongspace.username}"
else
display "=== #{keys.size} key#{'s' if keys.size > 1} for #{strongspace.username}"
keys.each do |key|
display long ? key["key"].strip : format_key_for_display(key["key"]) + " key-id: #{key["id"]}"
end
end
keys
end
|
52
53
54
55
|
# File 'lib/strongspace/commands/keys.rb', line 52
def remove
strongspace.remove_key(args.first)
display "Key #{args.first} removed."
end
|
#valid_key_gui? ⇒ Boolean
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/strongspace/commands/keys.rb', line 62
def valid_key_gui?
return unless running_on_a_mac? and File.exist? "#{support_directory}/ssh"
ret = `ssh -o PreferredAuthentications=publickey -i "#{support_directory}/ssh/#{computername}.rsa" #{strongspace.username}@#{strongspace.username}.strongspace.com 2>&1`
if ret.include? "Strongspace"
display "Valid key installed"
return true
end
display "No valid key installed"
return false
end
|