aboutsummaryrefslogtreecommitdiff
path: root/lib/leap_cli/commands/node.rb
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2013-02-08 23:42:07 -0800
committerelijah <elijah@riseup.net>2013-02-08 23:42:07 -0800
commitb8c25277760e209bff866b70e1b1cc996ed2b806 (patch)
tree4e4da32560980f58304d69297683272256a38804 /lib/leap_cli/commands/node.rb
parentea02733096ae1460df7cf24af3aeec9fc594e4d8 (diff)
downloadleap_cli-b8c25277760e209bff866b70e1b1cc996ed2b806.tar.gz
leap_cli-b8c25277760e209bff866b70e1b1cc996ed2b806.tar.bz2
improve `leap node add` by auto creating cert and validating ip_address
Diffstat (limited to 'lib/leap_cli/commands/node.rb')
-rw-r--r--lib/leap_cli/commands/node.rb22
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/leap_cli/commands/node.rb b/lib/leap_cli/commands/node.rb
index da29a02..bb02fa9 100644
--- a/lib/leap_cli/commands/node.rb
+++ b/lib/leap_cli/commands/node.rb
@@ -1,5 +1,6 @@
require 'net/ssh/known_hosts'
require 'tempfile'
+require 'ipaddr'
module LeapCli; module Commands
@@ -23,17 +24,22 @@ module LeapCli; module Commands
name = args.first
assert! name, 'No <node-name> specified.'
assert! name =~ /^[0-9a-z-]+$/, "illegal characters used in node name '#{name}'"
- assert_files_missing! [:node_config, node.name]
+ assert_files_missing! [:node_config, name]
# create and seed new node
- node = Config::Object.new
+ node = Config::Node.new(manager)
if options[:local]
node['ip_address'] = pick_next_vagrant_ip_address
end
seed_node_data(node, args[1..-1])
+ validate_ip_address(node)
# write the file
write_file! [:node_config, name], node.dump_json + "\n"
+ node['name'] = name
+ if file_exists? :ca_cert, :ca_key
+ generate_cert_for_node(manager.reload_node(node))
+ end
end
end
@@ -199,4 +205,16 @@ module LeapCli; module Commands
end
end
+ def validate_ip_address(node)
+ IPAddr.new(node['ip_address'])
+ rescue ArgumentError
+ bail! do
+ if node['ip_address']
+ log :invalid, "ip_address #{node['ip_address'].inspect}"
+ else
+ log :missing, "ip_address"
+ end
+ end
+ end
+
end; end \ No newline at end of file