-
Notifications
You must be signed in to change notification settings - Fork 11
/
mcc-add-key
executable file
·42 lines (37 loc) · 1.16 KB
/
mcc-add-key
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
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env ruby
$:.unshift File.expand_path('../../lib/', __FILE__)
require 'optparse'
require 'mcc/keystore'
@options = Hash.new
opts = OptionParser.new do |opts|
opts.banner = "Usage: mcc-add-key -n NAME -p PUBKEY"
opts.separator "Add a public SSH key to the minicloud keystore"
opts.separator ""
opts.separator "Options:"
opts.on("-n", "--name KEYNAME", "Name assigned to the public key") do |k|
@options[:keyname] = k
end
opts.on("-p", "--public-key PUBKEY", "The full public key string") do |k|
@options[:pub] = k
end
opts.on("-h", "--help", "This help screen") do
print opts
exit
end
opts.separator ""
opts.separator "Example:"
opts.separator ""
opts.separator "$ mcc-add-key --name my-key --public-key \"ssh-rsa AAAAB3NzaC1yc2.....aQ== me@exmaple.com\""
end
# Parse and check the required arguments
begin
opts.parse!
raise OptionParser::MissingArgument if @options[:keyname].nil?
raise OptionParser::MissingArgument if @options[:pub].nil?
rescue OptionParser::InvalidOption, OptionParser::MissingArgument
puts $!.to_s
puts ""
puts opts
exit 1
end
key = MCC::Keystore.new.add_key(@options[:keyname], @options[:pub])