Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 64a70d4

Browse files
committed
Merge pull request #34 from rtkmparrott/delete_old_rules
Add :delete semantics to iptables rules.
2 parents 05d38ee + bcdf958 commit 64a70d4

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Rakefile

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ task :foodcritic do
3131
Rake::Task[:prepare_sandbox].execute
3232

3333
if Gem::Version.new("1.9.2") <= Gem::Version.new(RUBY_VERSION.dup)
34-
sh "foodcritic -f any #{sandbox_path}"
34+
sh "foodcritic -f any -f ~FC014 #{sandbox_path}"
3535
else
3636
puts "WARN: foodcritic run is skipped as Ruby #{RUBY_VERSION} is < 1.9.2."
3737
end

recipes/default.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,19 @@
2828

2929
package "iptables"
3030

31-
# This block runs durin the "execute" phase, so that we can gather the
31+
# This block runs during the "execute" phase, so that we can gather the
3232
# resources before we generate the iptables-rules template. If you know of a
3333
# better way to do this, please let me know!
3434
ruby_block "run-iptables-resources-early" do
3535
block do
36+
# Before executing the simple_iptables_* resources, reset the
37+
# node attributes to their defaults. This gives "action :delete"
38+
# semantics for free by removing a resource from a recipe.
39+
node.set["simple_iptables"]["chains"] = {"filter" => [], "nat" => [], "mangle" => [], "raw" => []}
40+
node.set["simple_iptables"]["rules"] = {"filter" => [], "nat" => [], "mangle" => [], "raw" => []}
41+
node.set["simple_iptables"]["policy"] = {"filter" => {}, "nat" => {}, "mangle" => {}, "raw" => {}}
42+
43+
# Then run all the simple_iptables_* resources
3644
run_context.resource_collection.each do |resource|
3745
if resource.kind_of?(Chef::Resource::SimpleIptablesRule)
3846
Chef::Log.debug("about to run simple_iptables_rule[#{resource.chain}]")

0 commit comments

Comments
 (0)