aboutsummaryrefslogtreecommitdiff
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
parentea02733096ae1460df7cf24af3aeec9fc594e4d8 (diff)
downloadleap_cli-b8c25277760e209bff866b70e1b1cc996ed2b806.tar.gz
leap_cli-b8c25277760e209bff866b70e1b1cc996ed2b806.tar.bz2
improve `leap node add` by auto creating cert and validating ip_address
-rw-r--r--lib/leap_cli/commands/node.rb22
-rw-r--r--lib/leap_cli/config/manager.rb4
2 files changed, 24 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
diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb
index 5a82526..79a5c0e 100644
--- a/lib/leap_cli/config/manager.rb
+++ b/lib/leap_cli/config/manager.rb
@@ -158,6 +158,10 @@ module LeapCli
nodes.each_node &block
end
+ def reload_node(node)
+ @nodes[node.name] = apply_inheritance(node)
+ end
+
private
def load_all_json(pattern, object_class)