Passed
Push — master ( 5a8923...360867 )
by Marek
03:05
created

create_audit_rules_path_syscall   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A AuditRulesPathSyscallGenerator.generate() 0 17 2
A AuditRulesPathSyscallGenerator.csv_format() 0 3 1
1
#!/usr/bin/python2
2
3
#
4
# create_audit_rules_path_syscall_detailed.py
5
#        generate template-based checks for changes to a path via syscalls 
6
7
8
from template_common import FilesGenerator, UnknownTargetError
9
10
import re
11
12
class AuditRulesPathSyscallGenerator(FilesGenerator):
13
    def generate(self, target, args):
14
        path,syscall = args[0:2]
15
        pathid = re.sub('[-\./]', '_', path)
16
        # remove root slash made into '_'
17
        pathid = pathid[1:]
18
        if target == "oval":
19
            self.file_from_template(
20
                "./template_OVAL_audit_rules_path_syscall",
21
                {
22
                    "PATH":	path,
23
                    "PATHID":	pathid,
24
                    "SYSCALL":	syscall
25
                },
26
                "./oval/audit_rules_{0}_{1}.xml", pathid, syscall
27
            )
28
        else:
29
            raise UnknownTargetError(target)
30
31
    def csv_format(self):
32
        return("CSV should contains lines of the format: " +
33
               "PATH,SYSCALL")
34