mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
chore: Run pre-commit on selinux state file
This commit is contained in:
parent
3e491c3416
commit
b990868ca7
1 changed files with 28 additions and 28 deletions
|
@ -88,7 +88,7 @@ def mode(name):
|
|||
ret = {"name": name, "result": False, "comment": "", "changes": {}}
|
||||
tmode = _refine_mode(name)
|
||||
if tmode == "unknown":
|
||||
ret["comment"] = "{} is not an accepted mode".format(name)
|
||||
ret["comment"] = f"{name} is not an accepted mode"
|
||||
return ret
|
||||
# Either the current mode in memory or a non-matching config value
|
||||
# will trigger setenforce
|
||||
|
@ -100,11 +100,11 @@ def mode(name):
|
|||
|
||||
if mode == tmode:
|
||||
ret["result"] = True
|
||||
ret["comment"] = "SELinux is already in {} mode".format(tmode)
|
||||
ret["comment"] = f"SELinux is already in {tmode} mode"
|
||||
return ret
|
||||
# The mode needs to change...
|
||||
if __opts__["test"]:
|
||||
ret["comment"] = "SELinux mode is set to be changed to {}".format(tmode)
|
||||
ret["comment"] = f"SELinux mode is set to be changed to {tmode}"
|
||||
ret["result"] = None
|
||||
ret["changes"] = {"old": mode, "new": tmode}
|
||||
return ret
|
||||
|
@ -114,10 +114,10 @@ def mode(name):
|
|||
tmode == "Disabled" and __salt__["selinux.getconfig"]() == tmode
|
||||
):
|
||||
ret["result"] = True
|
||||
ret["comment"] = "SELinux has been set to {} mode".format(tmode)
|
||||
ret["comment"] = f"SELinux has been set to {tmode} mode"
|
||||
ret["changes"] = {"old": oldmode, "new": mode}
|
||||
return ret
|
||||
ret["comment"] = "Failed to set SELinux to {} mode".format(tmode)
|
||||
ret["comment"] = f"Failed to set SELinux to {tmode} mode"
|
||||
return ret
|
||||
|
||||
|
||||
|
@ -138,12 +138,12 @@ def boolean(name, value, persist=False):
|
|||
ret = {"name": name, "result": True, "comment": "", "changes": {}}
|
||||
bools = __salt__["selinux.list_sebool"]()
|
||||
if name not in bools:
|
||||
ret["comment"] = "Boolean {} is not available".format(name)
|
||||
ret["comment"] = f"Boolean {name} is not available"
|
||||
ret["result"] = False
|
||||
return ret
|
||||
rvalue = _refine_value(value)
|
||||
if rvalue is None:
|
||||
ret["comment"] = "{} is not a valid value for the boolean".format(value)
|
||||
ret["comment"] = f"{value} is not a valid value for the boolean"
|
||||
ret["result"] = False
|
||||
return ret
|
||||
state = bools[name]["State"] == rvalue
|
||||
|
@ -158,19 +158,19 @@ def boolean(name, value, persist=False):
|
|||
return ret
|
||||
if __opts__["test"]:
|
||||
ret["result"] = None
|
||||
ret["comment"] = "Boolean {} is set to be changed to {}".format(name, rvalue)
|
||||
ret["comment"] = f"Boolean {name} is set to be changed to {rvalue}"
|
||||
return ret
|
||||
|
||||
ret["result"] = __salt__["selinux.setsebool"](name, rvalue, persist)
|
||||
if ret["result"]:
|
||||
ret["comment"] = "Boolean {} has been set to {}".format(name, rvalue)
|
||||
ret["comment"] = f"Boolean {name} has been set to {rvalue}"
|
||||
ret["changes"].update({"State": {"old": bools[name]["State"], "new": rvalue}})
|
||||
if persist and not default:
|
||||
ret["changes"].update(
|
||||
{"Default": {"old": bools[name]["Default"], "new": rvalue}}
|
||||
)
|
||||
return ret
|
||||
ret["comment"] = "Failed to set the boolean {} to {}".format(name, rvalue)
|
||||
ret["comment"] = f"Failed to set the boolean {name} to {rvalue}"
|
||||
return ret
|
||||
|
||||
|
||||
|
@ -213,7 +213,7 @@ def module(name, module_state="Enabled", version="any", **opts):
|
|||
return module_remove(name)
|
||||
modules = __salt__["selinux.list_semod"]()
|
||||
if name not in modules:
|
||||
ret["comment"] = "Module {} is not available".format(name)
|
||||
ret["comment"] = f"Module {name} is not available"
|
||||
ret["result"] = False
|
||||
return ret
|
||||
rmodule_state = _refine_module_state(module_state)
|
||||
|
@ -235,7 +235,7 @@ def module(name, module_state="Enabled", version="any", **opts):
|
|||
return ret
|
||||
current_module_state = _refine_module_state(modules[name]["Enabled"])
|
||||
if rmodule_state == current_module_state:
|
||||
ret["comment"] = "Module {} is in the desired state".format(name)
|
||||
ret["comment"] = f"Module {name} is in the desired state"
|
||||
return ret
|
||||
if __opts__["test"]:
|
||||
ret["result"] = None
|
||||
|
@ -245,10 +245,10 @@ def module(name, module_state="Enabled", version="any", **opts):
|
|||
return ret
|
||||
|
||||
if __salt__["selinux.setsemod"](name, rmodule_state):
|
||||
ret["comment"] = "Module {} has been set to {}".format(name, module_state)
|
||||
ret["comment"] = f"Module {name} has been set to {module_state}"
|
||||
return ret
|
||||
ret["result"] = False
|
||||
ret["comment"] = "Failed to set the Module {} to {}".format(name, module_state)
|
||||
ret["comment"] = f"Failed to set the Module {name} to {module_state}"
|
||||
return ret
|
||||
|
||||
|
||||
|
@ -263,10 +263,10 @@ def module_install(name):
|
|||
"""
|
||||
ret = {"name": name, "result": True, "comment": "", "changes": {}}
|
||||
if __salt__["selinux.install_semod"](name):
|
||||
ret["comment"] = "Module {} has been installed".format(name)
|
||||
ret["comment"] = f"Module {name} has been installed"
|
||||
return ret
|
||||
ret["result"] = False
|
||||
ret["comment"] = "Failed to install module {}".format(name)
|
||||
ret["comment"] = f"Failed to install module {name}"
|
||||
return ret
|
||||
|
||||
|
||||
|
@ -282,14 +282,14 @@ def module_remove(name):
|
|||
ret = {"name": name, "result": True, "comment": "", "changes": {}}
|
||||
modules = __salt__["selinux.list_semod"]()
|
||||
if name not in modules:
|
||||
ret["comment"] = "Module {} is not available".format(name)
|
||||
ret["comment"] = f"Module {name} is not available"
|
||||
ret["result"] = False
|
||||
return ret
|
||||
if __salt__["selinux.remove_semod"](name):
|
||||
ret["comment"] = "Module {} has been removed".format(name)
|
||||
ret["comment"] = f"Module {name} has been removed"
|
||||
return ret
|
||||
ret["result"] = False
|
||||
ret["comment"] = "Failed to remove module {}".format(name)
|
||||
ret["comment"] = f"Failed to remove module {name}"
|
||||
return ret
|
||||
|
||||
|
||||
|
@ -343,7 +343,7 @@ def fcontext_policy_present(
|
|||
sel_level=sel_level,
|
||||
)
|
||||
if add_ret["retcode"] != 0:
|
||||
ret.update({"comment": "Error adding new rule: {}".format(add_ret)})
|
||||
ret.update({"comment": f"Error adding new rule: {add_ret}"})
|
||||
else:
|
||||
ret.update({"result": True})
|
||||
else:
|
||||
|
@ -354,7 +354,7 @@ def fcontext_policy_present(
|
|||
ret.update(
|
||||
{
|
||||
"result": True,
|
||||
"comment": 'SELinux policy for "{}" already present '.format(name)
|
||||
"comment": f'SELinux policy for "{name}" already present '
|
||||
+ 'with specified filetype "{}" and sel_type "{}".'.format(
|
||||
filetype_str, sel_type
|
||||
),
|
||||
|
@ -375,7 +375,7 @@ def fcontext_policy_present(
|
|||
sel_level=sel_level,
|
||||
)
|
||||
if change_ret["retcode"] != 0:
|
||||
ret.update({"comment": "Error adding new rule: {}".format(change_ret)})
|
||||
ret.update({"comment": f"Error adding new rule: {change_ret}"})
|
||||
else:
|
||||
ret.update({"result": True})
|
||||
if ret["result"] and (new_state or old_state):
|
||||
|
@ -423,7 +423,7 @@ def fcontext_policy_absent(
|
|||
ret.update(
|
||||
{
|
||||
"result": True,
|
||||
"comment": 'SELinux policy for "{}" already absent '.format(name)
|
||||
"comment": f'SELinux policy for "{name}" already absent '
|
||||
+ 'with specified filetype "{}" and sel_type "{}".'.format(
|
||||
filetype, sel_type
|
||||
),
|
||||
|
@ -444,7 +444,7 @@ def fcontext_policy_absent(
|
|||
sel_level=sel_level,
|
||||
)
|
||||
if remove_ret["retcode"] != 0:
|
||||
ret.update({"comment": "Error removing policy: {}".format(remove_ret)})
|
||||
ret.update({"comment": f"Error removing policy: {remove_ret}"})
|
||||
else:
|
||||
ret.update({"result": True})
|
||||
return ret
|
||||
|
@ -516,7 +516,7 @@ def port_policy_present(name, sel_type, protocol=None, port=None, sel_range=None
|
|||
ret.update(
|
||||
{
|
||||
"result": True,
|
||||
"comment": 'SELinux policy for "{}" already present '.format(name)
|
||||
"comment": f'SELinux policy for "{name}" already present '
|
||||
+ 'with specified sel_type "{}", protocol "{}" and port "{}".'.format(
|
||||
sel_type, protocol, port
|
||||
),
|
||||
|
@ -534,7 +534,7 @@ def port_policy_present(name, sel_type, protocol=None, port=None, sel_range=None
|
|||
sel_range=sel_range,
|
||||
)
|
||||
if add_ret["retcode"] != 0:
|
||||
ret.update({"comment": "Error adding new policy: {}".format(add_ret)})
|
||||
ret.update({"comment": f"Error adding new policy: {add_ret}"})
|
||||
else:
|
||||
ret.update({"result": True})
|
||||
new_state = __salt__["selinux.port_get_policy"](
|
||||
|
@ -577,7 +577,7 @@ def port_policy_absent(name, sel_type=None, protocol=None, port=None):
|
|||
ret.update(
|
||||
{
|
||||
"result": True,
|
||||
"comment": 'SELinux policy for "{}" already absent '.format(name)
|
||||
"comment": f'SELinux policy for "{name}" already absent '
|
||||
+ 'with specified sel_type "{}", protocol "{}" and port "{}".'.format(
|
||||
sel_type, protocol, port
|
||||
),
|
||||
|
@ -593,7 +593,7 @@ def port_policy_absent(name, sel_type=None, protocol=None, port=None):
|
|||
port=port,
|
||||
)
|
||||
if delete_ret["retcode"] != 0:
|
||||
ret.update({"comment": "Error deleting policy: {}".format(delete_ret)})
|
||||
ret.update({"comment": f"Error deleting policy: {delete_ret}"})
|
||||
else:
|
||||
ret.update({"result": True})
|
||||
new_state = __salt__["selinux.port_get_policy"](
|
||||
|
|
Loading…
Add table
Reference in a new issue