1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-30 07:28:52 +00:00

Reformat everything.

This commit is contained in:
Felix Fontein 2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View file

@ -114,6 +114,7 @@ import traceback
SELINUX_IMP_ERR = None
try:
import selinux
HAVE_SELINUX = True
except ImportError:
SELINUX_IMP_ERR = traceback.format_exc()
@ -122,6 +123,7 @@ except ImportError:
SEOBJECT_IMP_ERR = None
try:
import seobject
HAVE_SEOBJECT = True
except ImportError:
SEOBJECT_IMP_ERR = traceback.format_exc()
@ -135,7 +137,7 @@ def get_runtime_status(ignore_selinux_state=False):
def semanage_port_get_ports(seport, setype, proto, local):
""" Get the list of ports that have the specified type definition.
"""Get the list of ports that have the specified type definition.
:param community.general.seport: Instance of seobject.portRecords
@ -156,7 +158,7 @@ def semanage_port_get_ports(seport, setype, proto, local):
def semanage_port_get_type(seport, port, proto):
""" Get the SELinux type of the specified port.
"""Get the SELinux type of the specified port.
:param community.general.seport: Instance of seobject.portRecords
@ -170,7 +172,7 @@ def semanage_port_get_type(seport, port, proto):
:return: Tuple containing the SELinux type and MLS/MCS level, or None if not found.
"""
if isinstance(port, str):
ports = port.split('-', 1)
ports = port.split("-", 1)
if len(ports) == 1:
ports.extend(ports)
else:
@ -182,8 +184,8 @@ def semanage_port_get_type(seport, port, proto):
return records.get(key)
def semanage_port_add(module, ports, proto, setype, do_reload, serange='s0', sestore='', local=False):
""" Add SELinux port type definition to the policy.
def semanage_port_add(module, ports, proto, setype, do_reload, serange="s0", sestore="", local=False):
"""Add SELinux port type definition to the policy.
:type module: AnsibleModule
:param module: Ansible module
@ -233,8 +235,8 @@ def semanage_port_add(module, ports, proto, setype, do_reload, serange='s0', ses
return change
def semanage_port_del(module, ports, proto, setype, do_reload, sestore='', local=False):
""" Delete SELinux port type definition from the policy.
def semanage_port_del(module, ports, proto, setype, do_reload, sestore="", local=False):
"""Delete SELinux port type definition from the policy.
:type module: AnsibleModule
:param module: Ansible module
@ -277,13 +279,13 @@ def semanage_port_del(module, ports, proto, setype, do_reload, sestore='', local
def main():
module = AnsibleModule(
argument_spec=dict(
ignore_selinux_state=dict(type='bool', default=False),
ports=dict(type='list', elements='str', required=True),
proto=dict(type='str', required=True, choices=['tcp', 'udp']),
setype=dict(type='str', required=True),
state=dict(type='str', default='present', choices=['absent', 'present']),
reload=dict(type='bool', default=True),
local=dict(type='bool', default=False)
ignore_selinux_state=dict(type="bool", default=False),
ports=dict(type="list", elements="str", required=True),
proto=dict(type="str", required=True, choices=["tcp", "udp"]),
setype=dict(type="str", required=True),
state=dict(type="str", default="present", choices=["absent", "present"]),
reload=dict(type="bool", default=True),
local=dict(type="bool", default=False),
),
supports_check_mode=True,
)
@ -294,34 +296,34 @@ def main():
if not HAVE_SEOBJECT:
module.fail_json(msg=missing_required_lib("policycoreutils-python"), exception=SEOBJECT_IMP_ERR)
ignore_selinux_state = module.params['ignore_selinux_state']
ignore_selinux_state = module.params["ignore_selinux_state"]
if not get_runtime_status(ignore_selinux_state):
module.fail_json(msg="SELinux is disabled on this host.")
ports = module.params['ports']
proto = module.params['proto']
setype = module.params['setype']
state = module.params['state']
do_reload = module.params['reload']
local = module.params['local']
ports = module.params["ports"]
proto = module.params["proto"]
setype = module.params["setype"]
state = module.params["state"]
do_reload = module.params["reload"]
local = module.params["local"]
result = {
'ports': ports,
'proto': proto,
'setype': setype,
'state': state,
"ports": ports,
"proto": proto,
"setype": setype,
"state": state,
}
if state == 'present':
result['changed'] = semanage_port_add(module, ports, proto, setype, do_reload, local=local)
elif state == 'absent':
result['changed'] = semanage_port_del(module, ports, proto, setype, do_reload, local=local)
if state == "present":
result["changed"] = semanage_port_add(module, ports, proto, setype, do_reload, local=local)
elif state == "absent":
result["changed"] = semanage_port_del(module, ports, proto, setype, do_reload, local=local)
else:
module.fail_json(msg=f'Invalid value of argument "state": {state}')
module.exit_json(**result)
if __name__ == '__main__':
if __name__ == "__main__":
main()