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 21c6d78 commit 4a6811f
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions shared/templates/sshd_lineinfile/template.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
from ssg.utils import parse_template_boolean_value


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"])
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"])
raise ValueError(errmsg)
data["missing_parameter_pass"] = parse_template_boolean_value(
data, parameter="missing_parameter_pass", default_value=False)

is_default_value = parse_template_boolean_value(
data, parameter="is_default_value", default_value=False)
if is_default_value:
data["config_basename"] = "01-complianceascode-reinforce-os-defaults.conf"
else:
data["config_basename"] = "00-complianceascode-hardening.conf"

# set variables used in test scenarios
def set_variables_for_test_scenarios(data):
if data["datatype"] == "int":
if not data.get("value"):
data["wrong_value"] = 123456
Expand All @@ -35,3 +18,25 @@ def preprocess(data, lang):
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"]))
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"]))
raise ValueError(errmsg)
data["missing_parameter_pass"] = parse_template_boolean_value(
data, parameter="missing_parameter_pass", default_value=False)

is_default_value = parse_template_boolean_value(
data, parameter="is_default_value", default_value=False)
if is_default_value:
data["config_basename"] = "01-complianceascode-reinforce-os-defaults.conf"
else:
data["config_basename"] = "00-complianceascode-hardening.conf"

return set_variables_for_test_scenarios(data)

0 comments on commit 4a6811f

Please sign in to comment.