Puppet Function: format_chain

Defined in:
lib/puppet/parser/functions/format_chain.rb
Function type:
Ruby 3.x API

Overview

format_chain()Any

format_chain( name )

Given an chain name, generates the partial iptables rule to faciliate appending a rule to given chain.

Examples:

# returns '-A INPUT'
format_chain('INPUT')

# returns '-A LOGNDUMP'
format_chain('LOGNDUMP')

# throws ParseError
format_chain('SOME CHAIN')

Returns:

  • (Any)


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
# File 'lib/puppet/parser/functions/format_chain.rb', line 2

newfunction(:format_chain, :type => :rvalue,:doc => <<-EOS
format_chain( name )

Given an chain name, generates the partial iptables rule to faciliate appending
a rule to given chain.

Examples:

# returns '-A INPUT'
format_chain('INPUT')

# returns '-A LOGNDUMP'
format_chain('LOGNDUMP')

# throws ParseError
format_chain('SOME CHAIN')
EOS
) do |args|
  raise Puppet::ParseError, "no chain specified" if args == nil

  chain = 'INPUT'
  chain = args[0] unless args[0] == nil

  # Do some validation here
  if chain =~ /\s/
    raise Puppet::ParseError, \
      "chain name cannot contain whitespace - \"#{chain}\""
  end

  return "-A #{chain}"
end