From 54fe4bcb36959866a12509ce7d45a97c60722c11 Mon Sep 17 00:00:00 2001 From: elijah Date: Wed, 14 Nov 2012 14:27:35 -0800 Subject: added requirements checking - will bail out if a configuration option is missing --- Rakefile | 27 +++++++++++++++++++++++++++ lib/leap_cli.rb | 1 + lib/leap_cli/commands/pre.rb | 8 ++++++++ lib/leap_cli/requirements.rb | 11 +++++++++++ 4 files changed, 47 insertions(+) create mode 100644 lib/leap_cli/requirements.rb diff --git a/Rakefile b/Rakefile index b41e16b..373053d 100644 --- a/Rakefile +++ b/Rakefile @@ -80,6 +80,33 @@ Rake::TestTask.new do |t| end task :default => :test +## +## CODE GENERATION +## + +desc "Updates the list of required configuration options for this version of LEAP CLI" +task 'update-requirements' do + Dir.chdir($base_dir) do + required_configs = `find -name '*.rb' | xargs grep -R 'assert_config!'`.split("\n").collect{|line| + if line =~ /def/ + nil + else + line.sub(/.*assert_config! ["'](.*?)["'].*/,'"\1"') + end + }.compact + File.open("#{$base_dir}/lib/leap_cli/requirements.rb", 'w') do |f| + f.puts "# run 'rake update-requirements' to generate this file." + f.puts "module LeapCli" + f.puts " REQUIREMENTS = [" + f.puts " " + required_configs.join(",\n ") + f.puts " ]" + f.puts "end" + end + puts "updated #{$base_dir}/lib/leap_cli/requirements.rb" + #puts `cat '#{$base_dir}/lib/leap_cli/requirements.rb'` + end +end + ## ## DOCUMENTATION ## diff --git a/lib/leap_cli.rb b/lib/leap_cli.rb index 5ed5033..cc9ec69 100644 --- a/lib/leap_cli.rb +++ b/lib/leap_cli.rb @@ -1,6 +1,7 @@ module LeapCli; end require 'leap_cli/version.rb' +require 'leap_cli/requirements.rb' require 'core_ext/hash' require 'core_ext/boolean' require 'core_ext/nil' diff --git a/lib/leap_cli/commands/pre.rb b/lib/leap_cli/commands/pre.rb index a15a628..b1df5cd 100644 --- a/lib/leap_cli/commands/pre.rb +++ b/lib/leap_cli/commands/pre.rb @@ -40,6 +40,14 @@ module LeapCli else bail!("Could not find the root directory. Change current working directory or try --root") end + + # + # check requirements + # + REQUIREMENTS.each do |key| + assert_config! key + end + end end diff --git a/lib/leap_cli/requirements.rb b/lib/leap_cli/requirements.rb new file mode 100644 index 0000000..ad4fb21 --- /dev/null +++ b/lib/leap_cli/requirements.rb @@ -0,0 +1,11 @@ +# run 'rake update-requirements' to generate this file. +module LeapCli + REQUIREMENTS = [ + "provider.ca.name", + "provider.ca.bit_size", + "provider.ca.life_span", + "provider.ca.server_certificates.bit_size", + "provider.ca.server_certificates.life_span", + "provider.vagrant.network" + ] +end -- cgit v1.2.3