Skip to content

Instantly share code, notes, and snippets.

@oranenj
Created February 1, 2017 23:16
Show Gist options
  • Save oranenj/6fabc2eb8894604d9137e64d6a98f392 to your computer and use it in GitHub Desktop.
Save oranenj/6fabc2eb8894604d9137e64d6a98f392 to your computer and use it in GitHub Desktop.
the below works fine with:
selinux_port {'tcp_1234-1234':
seltype => 'zope_port_t',
}
debug says:
Debug: Puppet::Type::Selinux_port: title patterns called
Debug: Puppet::Type::Selinux_port: Got tcp
Debug: Puppet::Type::Selinux_port: Got 1234
Debug: Puppet::Type::Selinux_port: Got 1234
Debug: Puppet::Type::Selinux_port: title patterns called
Debug: Puppet::Type::Selinux_port: Got tcp
Debug: Puppet::Type::Selinux_port: Got 1234
Debug: Puppet::Type::Selinux_port: Got 1234
Debug: Puppet::Type::Selinux_port: title patterns called
Debug: Puppet::Type::Selinux_port: Got tcp
Debug: Puppet::Type::Selinux_port: Got 1234
Debug: Puppet::Type::Selinux_port: Got 1234
#but if title is 'tczp_...'
Notice: Compiled catalog for kurenai.local in environment production in 0.21 seconds
Debug: Puppet::Type::Selinux_port: title patterns called
Puppet::Type.newtype(:selinux_port) do
@doc = 'Manage SELinux port definitions. You should use selinux::port instead of this directly.'
def self.title_patterns
foo = lambda {|x| debug("Got ", x); x}
debug("title patterns called")
return [[/(udp|tcp)_(\d+)-(\d+)/, [[:protocol, foo], [:low_port, foo], [:high_port, foo]]]]
end
ensurable
newparam(:low_port) do
desc 'The low end of the port range to manage'
end
newparam(:high_port) do
desc 'The high end of the port range to manage'
end
newparam(:protocol) do
desc 'The protocol of the SELinux port definition'
newvalues(:tcp, :udp)
end
newproperty(:seltype) do
desc 'The SELinux type of the SELinux port definition'
end
newproperty(:source) do
desc 'Source of the port configuration - either policy or local'
newvalues(:policy, :local)
validate do |_value|
raise ArgumentError, ':source is a read-only property'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment