Puppet Function: format_action
- Defined in:
- lib/puppet/parser/functions/format_action.rb
- Function type:
- Ruby 3.x API
Overview
Given an action, ie. ACCEPT/REJECT or a chain name, returns the partial iptables rule to facilitate taking the appropriate action.
Examples:
# returns "-j ACCEPT'
format_action('ACCEPT')
# returns '-j LOG'
format_action('LOG')
# Parse Error
format_action(nil)
format_action('')
format_action('SOME CHAIN')
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/puppet/parser/functions/format_action.rb', line 2 newfunction(:format_action, :type => :rvalue,:doc => <<-EOS Given an action, ie. ACCEPT/REJECT or a chain name, returns the partial iptables rule to facilitate taking the appropriate action. Examples: # returns "-j ACCEPT' format_action('ACCEPT') # returns '-j LOG' format_action('LOG') # Parse Error format_action(nil) format_action('') format_action('SOME CHAIN') EOS ) do |args| action = 'ACCEPT' action = args[0] unless args[0] == nil if action == nil or action == :undef raise Puppet::ParseError, \ "action not specified" end # do some basic validation of the action if action =~ /\s/ raise Puppet::ParseError, \ "action cannot contain whitepace - \"#{action}\"" end return "-j #{action}" end |