/usr/lib/python2.7/dist-packages/Bcfg2/Server/Lint/GroupPatterns.py is in bcfg2-server 1.4.0~pre2+git141-g6d40dace6358-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 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 36 37 38 39 40 41 42 43 44 | """ ``bcfg2-lint`` plugin for :ref:`GroupPatterns
<server-plugins-grouping-grouppatterns>` """
import sys
from Bcfg2.Server.Lint import ServerPlugin
from Bcfg2.Server.Plugins.GroupPatterns import PatternMap, \
PatternInitializationError
class GroupPatterns(ServerPlugin):
""" ``bcfg2-lint`` plugin to check all given :ref:`GroupPatterns
<server-plugins-grouping-grouppatterns>` patterns for validity.
This is simply done by trying to create a
:class:`Bcfg2.Server.Plugins.GroupPatterns.PatternMap` object for
each pattern, and catching exceptions and presenting them as
``bcfg2-lint`` errors."""
__serverplugin__ = 'GroupPatterns'
def Run(self):
cfg = self.core.plugins['GroupPatterns'].config
for entry in cfg.xdata.xpath('//GroupPattern'):
groups = [g.text for g in entry.findall('Group')]
self.check(entry, groups, ptype='NamePattern')
self.check(entry, groups, ptype='NameRange')
@classmethod
def Errors(cls):
return {"pattern-fails-to-initialize": "error"}
def check(self, entry, groups, ptype="NamePattern"):
""" Check a single pattern for validity """
for el in entry.findall(ptype):
pat = el.text
try:
if ptype == "NamePattern":
PatternMap(pat, None, groups)
else:
PatternMap(None, pat, groups)
except PatternInitializationError:
err = sys.exc_info()[1]
self.LintError("pattern-fails-to-initialize",
"Failed to initialize %s %s for %s: %s" %
(ptype, pat, entry.get('pattern'), err))
|