aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2014-03-24 10:32:56 -0700
committerelijah <elijah@riseup.net>2014-03-24 10:32:56 -0700
commitf305ca4688f92377b4b51af6e8674df02c18e3e2 (patch)
tree21cfe45b63bc6cd303cfb1873b3556b4c3535317 /lib
parent2b6f4b85a3089eacb19f7b6c165419c6620aeb45 (diff)
downloadleap_cli-f305ca4688f92377b4b51af6e8674df02c18e3e2.tar.gz
leap_cli-f305ca4688f92377b4b51af6e8674df02c18e3e2.tar.bz2
better checking of valid node names
Diffstat (limited to 'lib')
-rw-r--r--lib/leap_cli/commands/node.rb17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/leap_cli/commands/node.rb b/lib/leap_cli/commands/node.rb
index a4c0d1a..5f5c4b8 100644
--- a/lib/leap_cli/commands/node.rb
+++ b/lib/leap_cli/commands/node.rb
@@ -22,12 +22,7 @@ module LeapCli; module Commands
add.action do |global_options,options,args|
# argument sanity checks
name = args.first
- assert! name, 'No <node-name> specified.'
- if options[:local]
- assert! name =~ /^[0-9a-z]+$/, "illegal characters used in node name '#{name}' (note: Vagrant does not allow hyphens or underscores)"
- else
- assert! name =~ /^[0-9a-z-]+$/, "illegal characters used in node name '#{name}' (note: Linux does not allow underscores)"
- end
+ assert_valid_node_name!(name, options[:local])
assert_files_missing! [:node_config, name]
# create and seed new node
@@ -92,6 +87,7 @@ module LeapCli; module Commands
mv.action do |global_options,options,args|
node = get_node_from_args(args)
new_name = args.last
+ assert_valid_node_name!(new_name, node.vagrant?)
ensure_dir [:node_files_dir, new_name]
Leap::Platform.node_files.each do |path|
rename_file! [path, node.name], [path, new_name]
@@ -276,4 +272,13 @@ module LeapCli; module Commands
end
end
+ def assert_valid_node_name!(name, local=false)
+ assert! name, 'No <node-name> specified.'
+ if local
+ assert! name =~ /^[0-9a-z]+$/, "illegal characters used in node name '#{name}' (note: Vagrant does not allow hyphens or underscores)"
+ else
+ assert! name =~ /^[0-9a-z-]+$/, "illegal characters used in node name '#{name}' (note: Linux does not allow underscores)"
+ end
+ end
+
end; end \ No newline at end of file