Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
evgenyz committed Feb 6, 2024
1 parent 380644e commit cdf6107
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 78 deletions.
4 changes: 2 additions & 2 deletions docs/manual/developer/05_tools_and_utilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ $ python utils/generate_profile.py -i benchmark.xlsx list
To generate a rule for a specific control:
```
$ python utils/generate_profile.py -i benchmark.xlsx generate --product-type ocp -c 1.1.2
$ python utils/generate_profile.py -i benchmark.xlsx generate -c 1.1.2
documentation_complete: false
title: |-
Ensure that the API server pod specification file ownership is set to root:root
Expand Down Expand Up @@ -575,7 +575,7 @@ template: PLACEHOLDER
To generate an entire section:
```
$ python utils/generate_profile.py -i benchmark.xlsx generate --product-type ocp -s 1
$ python utils/generate_profile.py -i benchmark.xlsx generate -s 1
```
The `PLACEHOLDER` values must be filled in later, ideally when the rules are
Expand Down
71 changes: 0 additions & 71 deletions tests/unit/ssg-module/test_rule_dir_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,74 +115,3 @@ def test_two_plus_remediation():
assert not rds.two_plus_remediation(one_rule, 'bash')
assert not rds.two_plus_remediation(empty_rule, 'bash')
assert not rds.two_plus_remediation(empty_rule, 'anaconda')


def test_prodtypes_oval():
bad_rule = {
"id": "bad_rule",
"products": ["rhel8"],
"ovals": {
"rhel7.xml": {
"products": ["rhel7"]
}
}
}
good_rule = {
"id": "good_rule",
"products": ["rhel7"],
"ovals": {
"rhel7.xml": {
"products": ["rhel7"]
}
}
}
empty_rule = {
"id": "empty_rule"
}
no_oval_rule = {
"id": "empty_rule",
"products": ["rhel7"]
}

assert rds.prodtypes_oval(bad_rule)
assert not rds.prodtypes_oval(good_rule)
assert not rds.prodtypes_oval(empty_rule)
assert not rds.prodtypes_oval(no_oval_rule)


def test_prodtypes_remediation():
bad_rule = {
"id": "bad_rule",
"products": ["rhel8"],
"remediations": {
"bash": {
"rhel7.sh": {
"products": ["rhel7"]
}
}
}
}
good_rule = {
"id": "good_rule",
"products": ["rhel7"],
"remediations": {
"bash": {
"rhel7.sh": {
"products": ["rhel7"]
}
}
}
}
empty_rule = {
"id": "empty_rule"
}
no_remediation_rule = {
"id": "empty_rule",
"products": ["rhel7"]
}

assert rds.prodtypes_remediation(bad_rule, 'bash')
assert not rds.prodtypes_remediation(good_rule, 'bash')
assert not rds.prodtypes_remediation(empty_rule, 'bash')
assert not rds.prodtypes_remediation(no_remediation_rule, 'bash')
assert not rds.prodtypes_remediation(no_remediation_rule, 'ansible')
7 changes: 2 additions & 5 deletions utils/generate_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ def setup_argument_parser() -> argparse.ArgumentParser:
list_parser = subparsers.add_parser('list', help='List controls within a benchmark')
list_parser.set_defaults(func=list_controls)
generate_parser = subparsers.add_parser('generate', help='Generate a control from benchmark')
generate_parser.add_argument('-p', '--product-type', required=True,
help='Product name to generate in output')
generate_parser.add_argument('-c', '--control', help='Control ID to generate')
generate_parser.add_argument('-s', '--section',
help='Section ID to generate, including containing controls')
Expand Down Expand Up @@ -203,9 +201,8 @@ def _generate(self, node: pycompliance.Node) -> dict:

class RuleGenerator(Generator):

def __init__(self, benchmark: pycompliance.Benchmark, product_type: str):
def __init__(self, benchmark: pycompliance.Benchmark):
super().__init__(benchmark)
self.product_type = product_type

def generate(self, control: pycompliance.Control):
if not isinstance(control, pycompliance.Control):
Expand Down Expand Up @@ -274,7 +271,7 @@ def generate_control(args):
control = b.find(args.control)
section = b.find(args.section)
if control:
r = RuleGenerator(b, args.product_type)
r = RuleGenerator(b)
r.generate(control)
elif section:
r = SectionGenerator(b)
Expand Down

0 comments on commit cdf6107

Please sign in to comment.