~junaidali/charms/trusty/plumgrid-gateway/oil_bug

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/hardening/audits/__init__.py

  • Committer: bbaqar at plumgrid
  • Date: 2016-05-18 09:55:23 UTC
  • mfrom: (27.1.4 plumgrid-gateway)
  • Revision ID: bbaqar@plumgrid.com-20160518095523-fnxwexqpi8jkkb3b
Merge - Charmhelpers sync and improved pg-restart

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2016 Canonical Limited.
2
 
#
3
 
# This file is part of charm-helpers.
4
 
#
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.
8
 
#
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.
13
 
#
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/>.
16
 
 
17
 
 
18
 
class BaseAudit(object):  # NO-QA
19
 
    """Base class for hardening checks.
20
 
 
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.
24
 
    """
25
 
    def __init__(self, *args, **kwargs):
26
 
        self.unless = kwargs.get('unless', None)
27
 
        super(BaseAudit, self).__init__()
28
 
 
29
 
    def ensure_compliance(self):
30
 
        """Checks to see if the current hardening check is in compliance or
31
 
        not.
32
 
 
33
 
        If the check that is performed is not in compliance, then an exception
34
 
        should be raised.
35
 
        """
36
 
        pass
37
 
 
38
 
    def _take_action(self):
39
 
        """Determines whether to perform the action or not.
40
 
 
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
46
 
        performed.
47
 
        """
48
 
        # Do the action if there isn't an unless override.
49
 
        if self.unless is None:
50
 
            return True
51
 
 
52
 
        # Invoke the callback if there is one.
53
 
        if hasattr(self.unless, '__call__'):
54
 
            results = self.unless()
55
 
            if results:
56
 
                return False
57
 
            else:
58
 
                return True
59
 
 
60
 
        if self.unless:
61
 
            return False
62
 
        else:
63
 
            return True