1
# Copyright 2016 Canonical Limited.
3
# This file is part of charm-helpers.
5
# charm-helpers is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU Lesser General Public License version 3 as
7
# published by the Free Software Foundation.
9
# charm-helpers is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU Lesser General Public License for more details.
14
# You should have received a copy of the GNU Lesser General Public License
15
# along with charm-helpers. If not, see <http://www.gnu.org/licenses/>.
18
class BaseAudit(object): # NO-QA
19
"""Base class for hardening checks.
21
The lifecycle of a hardening check is to first check to see if the system
22
is in compliance for the specified check. If it is not in compliance, the
23
check method will return a value which will be supplied to the.
25
def __init__(self, *args, **kwargs):
26
self.unless = kwargs.get('unless', None)
27
super(BaseAudit, self).__init__()
29
def ensure_compliance(self):
30
"""Checks to see if the current hardening check is in compliance or
33
If the check that is performed is not in compliance, then an exception
38
def _take_action(self):
39
"""Determines whether to perform the action or not.
41
Checks whether or not an action should be taken. This is determined by
42
the truthy value for the unless parameter. If unless is a callback
43
method, it will be invoked with no parameters in order to determine
44
whether or not the action should be taken. Otherwise, the truthy value
45
of the unless attribute will determine if the action should be
48
# Do the action if there isn't an unless override.
49
if self.unless is None:
52
# Invoke the callback if there is one.
53
if hasattr(self.unless, '__call__'):
54
results = self.unless()