diff options
Diffstat (limited to 'lib/leap_cli')
-rw-r--r-- | lib/leap_cli/commands/test.rb | 10 | ||||
-rw-r--r-- | lib/leap_cli/config/object_list.rb | 46 | ||||
-rw-r--r-- | lib/leap_cli/path.rb | 4 |
3 files changed, 40 insertions, 20 deletions
diff --git a/lib/leap_cli/commands/test.rb b/lib/leap_cli/commands/test.rb index dd505b6..e895a5e 100644 --- a/lib/leap_cli/commands/test.rb +++ b/lib/leap_cli/commands/test.rb @@ -24,8 +24,14 @@ module LeapCli; module Commands def generate_test_client_openvpn_config template = read_file! Path.find_file(:test_client_openvpn_template) - config = Util.erb_eval(template, binding) - write_file! :test_client_openvpn_config, config + + ['production', 'testing', 'local'].each do |tag| + vpn_nodes = manager.nodes[:tags => tag][:services => 'openvpn'] + if vpn_nodes.any? + config = Util.erb_eval(template, binding) + write_file! ('test_openvpn_'+tag).to_sym, config + end + end end end; end diff --git a/lib/leap_cli/config/object_list.rb b/lib/leap_cli/config/object_list.rb index 0fa60f1..9001834 100644 --- a/lib/leap_cli/config/object_list.rb +++ b/lib/leap_cli/config/object_list.rb @@ -12,30 +12,42 @@ module LeapCli end # - # if the key is a hash, we treat it as a condition and filter all the configs using the condition + # If the key is a string, the Config::Object it references is returned. # - # for example: + # If the key is a hash, we treat it as a condition and filter all the Config::Objects using the condition. + # A new ObjectList is returned. # - # nodes[:public_dns => true] + # Examples: # - # will return a ConfigList with node configs that have public_dns set to true + # nodes['vpn1'] + # node named 'vpn1' + # + # nodes[:public_dns => true] + # all nodes with public dns + # + # nodes[:services => 'openvpn', :services => 'tor'] + # nodes with openvpn OR tor service + # + # nodes[:services => 'openvpn'][:tags => 'production'] + # nodes with openvpn AND are production # def [](key) if key.is_a? Hash results = Config::ObjectList.new - field, match_value = key.to_a.first - field = field.is_a?(Symbol) ? field.to_s : field - match_value = match_value.is_a?(Symbol) ? match_value.to_s : match_value - each do |name, config| - value = config[field] - if !value.nil? - if value.is_a? Array - if value.include?(match_value) - results[name] = config - end - else - if value == match_value - results[name] = config + key.each do |field, match_value| + field = field.is_a?(Symbol) ? field.to_s : field + match_value = match_value.is_a?(Symbol) ? match_value.to_s : match_value + each do |name, config| + value = config[field] + if !value.nil? + if value.is_a? Array + if value.include?(match_value) + results[name] = config + end + else + if value == match_value + results[name] = config + end end end end diff --git a/lib/leap_cli/path.rb b/lib/leap_cli/path.rb index bfd3c9a..7628628 100644 --- a/lib/leap_cli/path.rb +++ b/lib/leap_cli/path.rb @@ -51,7 +51,9 @@ module LeapCli; module Path # testing files :test_client_key => 'test/cert/client.key', :test_client_cert => 'test/cert/client.crt', - :test_client_openvpn_config => 'test/openvpn/client.ovpn', + :test_openvpn_production => 'test/openvpn/production.ovpn', + :test_openvpn_testing => 'test/openvpn/testing.ovpn', + :test_openvpn_local => 'test/openvpn/local.ovpn', :test_client_openvpn_template => 'test/openvpn/client.ovpn.erb' } |