File: create_package_removed.py

package info (click to toggle)
scap-security-guide 0.1.39-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 31,836 kB
  • sloc: xml: 129,736; python: 7,462; sh: 3,796; makefile: 27
file content (55 lines) | stat: -rw-r--r-- 1,777 bytes parent folder | download
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
45
46
47
48
49
50
51
52
53
54
55
#
# create_package_removed.py
#   automatically generate checks for removed packages

from template_common import FilesGenerator, UnknownTargetError


class PackageRemovedGenerator(FilesGenerator):
    def generate(self, target, package_info):
        pkgname = package_info[0]
        if not pkgname:
            raise RuntimeError(
                "ERROR: input violation: the package name must be defined")

        if target == "oval":
            self.file_from_template(
                "./template_OVAL_package_removed",
                {"%PKGNAME%": pkgname},
                "./oval/package_{0}_removed.xml", pkgname
            )

        elif target == "bash":
            self.file_from_template(
                "./template_BASH_package_removed",
                {"%PKGNAME%": pkgname},
                "./bash/package_{0}_removed.sh", pkgname
            )

        elif target == "ansible":
            self.file_from_template(
                "./template_ANSIBLE_package_removed",
                {"%PKGNAME%": pkgname},
                "./ansible/package_{0}_removed.yml", pkgname
            )

        elif target == "anaconda":
            self.file_from_template(
                "./template_ANACONDA_package_removed",
                {"%PKGNAME%": pkgname},
                "./anaconda/package_{0}_removed.anaconda", pkgname
            )

        elif target == "puppet":
            self.file_from_template(
                "./template_PUPPET_package_removed",
                {"%PKGNAME%": pkgname},
                "./puppet/package_{0}_removed.pp", pkgname
            )

        else:
            raise UnknownTargetError(target)

    def csv_format(self):
        return("CSV should contains lines of the format: " +
               "PACKAGE_NAME")