~launchpad-pqm/launchpad/devel

12850.4.1 by j.c.sackett
Added audit-security.py script.
1
#! /usr/bin/python -S
2
3
# Copyright 2011 Canonical Ltd.  This software is licensed under the
4
# GNU Affero General Public License version 3 (see the file LICENSE).
5
6
"""Check that everything is alright in security.cfg
7
8
Usage hint:
9
10
% utilities/audit-security.py
11
"""
12850.4.2 by j.c.sackett
Functional auditing script; finds duplicate settings.
12
__metatype__ = type
12850.4.1 by j.c.sackett
Added audit-security.py script.
13
14
import os
12907.2.1 by j.c.sackett
Broke out the auditor into its own file so it can be tested well, as it's going to get more complicated.
15
12907.2.7 by j.c.sackett
Settings auditor.
16
import _pythonpath
17
from lp.scripts.utilities.settingsauditor import SettingsAuditor
12907.2.1 by j.c.sackett
Broke out the auditor into its own file so it can be tested well, as it's going to get more complicated.
18
12850.4.6 by j.c.sackett
Renamed audit-security to audit-security-settings, since that's more accurate.
19
12850.4.2 by j.c.sackett
Functional auditing script; finds duplicate settings.
20
BRANCH_ROOT = os.path.split(
21
    os.path.dirname(os.path.abspath(__file__)))[0]
22
SECURITY_PATH = os.path.join(
23
    BRANCH_ROOT, 'database', 'schema', 'security.cfg')
24
12907.2.9 by j.c.sackett
Lint fixes.
25
12907.2.7 by j.c.sackett
Settings auditor.
26
def main():
27
    data = file(SECURITY_PATH).read()
28
    auditor = SettingsAuditor(data)
29
    settings = auditor.audit()
30
    file(SECURITY_PATH, 'w').write(settings)
12907.2.1 by j.c.sackett
Broke out the auditor into its own file so it can be tested well, as it's going to get more complicated.
31
    print auditor.error_data
12850.4.2 by j.c.sackett
Functional auditing script; finds duplicate settings.
32
33
if __name__ == '__main__':
12907.2.1 by j.c.sackett
Broke out the auditor into its own file so it can be tested well, as it's going to get more complicated.
34
    main()