Skip to content

Commit

Permalink
apply suggestions provided by Codeclimate
Browse files Browse the repository at this point in the history
extract setting of test scenario variables to a separate function
split long strings to multiple lines
  • Loading branch information
vojtapolasek committed Aug 8, 2024
1 parent 444811a commit 052061c
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions shared/templates/sshd_lineinfile/template.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
from ssg.utils import parse_template_boolean_value


def set_variables_for_test_scenarios(data):
if data["datatype"] == "int":
if not data.get("value"):
data["wrong_value"] = 123456
data["correct_value"] = 0
else:
data["wrong_value"] = str(int(data["value"]) + 1)
data["correct_value"] = str(data["value"])
elif data["datatype"] == "string":
if not data.get("value"):
data["wrong_value"] = "wrong_value"
data["correct_value"] = "correct_value"
else:
data["wrong_value"] = "wrong_value"
data["correct_value"] = str(data["value"])

return data

def preprocess(data, lang):
if data.get("value") is not None and data.get("xccdf_variable") is not None:
errmsg = "The template definition of {0} specifies both value and xccdf_variable. This is forbidden.".format(data["_rule_id"])
errmsg = ("The template definition of {0} specifies both value and xccdf_variable."
"This is forbidden.".format(data["_rule_id"]))
raise ValueError(errmsg)
if data["datatype"] not in ["string", "int"]:
errmsg = "The template instance of the rule {0} contains invalid datatype. It must be either 'string' or 'int'".format(data["_rule_id"])
errmsg = ("The template instance of the rule {0} contains invalid datatype."
"It must be either 'string' or 'int'".format(data["_rule_id"]))
raise ValueError(errmsg)
data["missing_parameter_pass"] = parse_template_boolean_value(
data, parameter="missing_parameter_pass", default_value=False)
Expand All @@ -18,7 +38,6 @@ def preprocess(data, lang):
else:
data["config_basename"] = "00-complianceascode-hardening.conf"

# set variables used in test scenarios
if data["datatype"] == "int":
if not data.get("value"):
data["wrong_value"] = 123456
Expand All @@ -34,4 +53,5 @@ def preprocess(data, lang):
data["wrong_value"] = "wrong_value"
data["correct_value"] = str(data["value"])

return data
return set_variables_for_test_scenarios(data)

0 comments on commit 052061c

Please sign in to comment.