From b8c25277760e209bff866b70e1b1cc996ed2b806 Mon Sep 17 00:00:00 2001 From: elijah Date: Fri, 8 Feb 2013 23:42:07 -0800 Subject: improve `leap node add` by auto creating cert and validating ip_address --- lib/leap_cli/commands/node.rb | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'lib/leap_cli/commands') 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 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 -- cgit v1.2.3