1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-26 13:42:49 +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

@ -191,61 +191,61 @@ from ansible_collections.community.general.plugins.module_utils.cmd_runner impor
class IPAKeytab:
def __init__(self, module, **kwargs):
self.module = module
self.password = kwargs['password']
self.principal = kwargs['principal']
self.state = kwargs['state']
self.kdestroy_all = kwargs['kdestroy_all']
self.cache_name = kwargs['cache_name']
self.start_time = kwargs['start_time']
self.renewable = kwargs['renewable']
self.forwardable = kwargs['forwardable']
self.proxiable = kwargs['proxiable']
self.address_restricted = kwargs['address_restricted']
self.canonicalization = kwargs['canonicalization']
self.enterprise = kwargs['enterprise']
self.renewal = kwargs['renewal']
self.validate = kwargs['validate']
self.keytab = kwargs['keytab']
self.keytab_path = kwargs['keytab_path']
self.password = kwargs["password"]
self.principal = kwargs["principal"]
self.state = kwargs["state"]
self.kdestroy_all = kwargs["kdestroy_all"]
self.cache_name = kwargs["cache_name"]
self.start_time = kwargs["start_time"]
self.renewable = kwargs["renewable"]
self.forwardable = kwargs["forwardable"]
self.proxiable = kwargs["proxiable"]
self.address_restricted = kwargs["address_restricted"]
self.canonicalization = kwargs["canonicalization"]
self.enterprise = kwargs["enterprise"]
self.renewal = kwargs["renewal"]
self.validate = kwargs["validate"]
self.keytab = kwargs["keytab"]
self.keytab_path = kwargs["keytab_path"]
self.kinit = CmdRunner(
module,
command='kinit',
command="kinit",
arg_formats=dict(
lifetime=cmd_runner_fmt.as_opt_val('-l'),
start_time=cmd_runner_fmt.as_opt_val('-s'),
renewable=cmd_runner_fmt.as_opt_val('-r'),
forwardable=cmd_runner_fmt.as_bool('-f', '-F', ignore_none=True),
proxiable=cmd_runner_fmt.as_bool('-p', '-P', ignore_none=True),
address_restricted=cmd_runner_fmt.as_bool('-a', '-A', ignore_none=True),
anonymous=cmd_runner_fmt.as_bool('-n'),
canonicalization=cmd_runner_fmt.as_bool('-C'),
enterprise=cmd_runner_fmt.as_bool('-E'),
renewal=cmd_runner_fmt.as_bool('-R'),
validate=cmd_runner_fmt.as_bool('-v'),
keytab=cmd_runner_fmt.as_bool('-k'),
keytab_path=cmd_runner_fmt.as_func(lambda v: ['-t', v] if v else ['-i']),
cache_name=cmd_runner_fmt.as_opt_val('-c'),
lifetime=cmd_runner_fmt.as_opt_val("-l"),
start_time=cmd_runner_fmt.as_opt_val("-s"),
renewable=cmd_runner_fmt.as_opt_val("-r"),
forwardable=cmd_runner_fmt.as_bool("-f", "-F", ignore_none=True),
proxiable=cmd_runner_fmt.as_bool("-p", "-P", ignore_none=True),
address_restricted=cmd_runner_fmt.as_bool("-a", "-A", ignore_none=True),
anonymous=cmd_runner_fmt.as_bool("-n"),
canonicalization=cmd_runner_fmt.as_bool("-C"),
enterprise=cmd_runner_fmt.as_bool("-E"),
renewal=cmd_runner_fmt.as_bool("-R"),
validate=cmd_runner_fmt.as_bool("-v"),
keytab=cmd_runner_fmt.as_bool("-k"),
keytab_path=cmd_runner_fmt.as_func(lambda v: ["-t", v] if v else ["-i"]),
cache_name=cmd_runner_fmt.as_opt_val("-c"),
principal=cmd_runner_fmt.as_list(),
)
),
)
self.kdestroy = CmdRunner(
module,
command='kdestroy',
command="kdestroy",
arg_formats=dict(
kdestroy_all=cmd_runner_fmt.as_bool('-A'),
cache_name=cmd_runner_fmt.as_opt_val('-c'),
principal=cmd_runner_fmt.as_opt_val('-p'),
)
kdestroy_all=cmd_runner_fmt.as_bool("-A"),
cache_name=cmd_runner_fmt.as_opt_val("-c"),
principal=cmd_runner_fmt.as_opt_val("-p"),
),
)
self.klist = CmdRunner(
module,
command='klist',
command="klist",
arg_formats=dict(
show_list=cmd_runner_fmt.as_bool('-l'),
)
show_list=cmd_runner_fmt.as_bool("-l"),
),
)
def exec_kinit(self):
@ -261,10 +261,7 @@ class IPAKeytab:
def exec_kdestroy(self):
params = dict(self.module.params)
with self.kdestroy(
"kdestroy_all cache_name principal",
check_rc=True
) as ctx:
with self.kdestroy("kdestroy_all cache_name principal", check_rc=True) as ctx:
rc, out, err = ctx.run(**params)
return out
@ -272,10 +269,7 @@ class IPAKeytab:
# Use chech_rc = False because
# If no tickets present, klist command will always return rc = 1
params = dict(show_list=show_list)
with self.klist(
"show_list",
check_rc=False
) as ctx:
with self.klist("show_list", check_rc=False) as ctx:
rc, out, err = ctx.run(**params)
return rc, out, err
@ -300,71 +294,70 @@ class IPAKeytab:
def main():
arg_spec = dict(
principal=dict(type='str'),
password=dict(type='str', no_log=True),
state=dict(default='present', choices=['present', 'absent']),
kdestroy_all=dict(type='bool'),
cache_name=dict(type='str', fallback=(env_fallback, ['KRB5CCNAME'])),
lifetime=dict(type='str'),
start_time=dict(type='str'),
renewable=dict(type='str'),
forwardable=dict(type='bool'),
proxiable=dict(type='bool'),
address_restricted=dict(type='bool'),
anonymous=dict(type='bool'),
canonicalization=dict(type='bool'),
enterprise=dict(type='bool'),
renewal=dict(type='bool'),
validate=dict(type='bool'),
keytab=dict(type='bool'),
keytab_path=dict(type='path'),
principal=dict(type="str"),
password=dict(type="str", no_log=True),
state=dict(default="present", choices=["present", "absent"]),
kdestroy_all=dict(type="bool"),
cache_name=dict(type="str", fallback=(env_fallback, ["KRB5CCNAME"])),
lifetime=dict(type="str"),
start_time=dict(type="str"),
renewable=dict(type="str"),
forwardable=dict(type="bool"),
proxiable=dict(type="bool"),
address_restricted=dict(type="bool"),
anonymous=dict(type="bool"),
canonicalization=dict(type="bool"),
enterprise=dict(type="bool"),
renewal=dict(type="bool"),
validate=dict(type="bool"),
keytab=dict(type="bool"),
keytab_path=dict(type="path"),
)
module = AnsibleModule(
argument_spec=arg_spec,
supports_check_mode=True,
required_by={
'keytab_path': 'keytab'
},
required_by={"keytab_path": "keytab"},
required_if=[
('state', 'present', ('password', 'keytab_path'), True),
("state", "present", ("password", "keytab_path"), True),
],
)
state = module.params['state']
kdestroy_all = module.params['kdestroy_all']
state = module.params["state"]
kdestroy_all = module.params["kdestroy_all"]
keytab = IPAKeytab(module,
state=state,
kdestroy_all=kdestroy_all,
principal=module.params['principal'],
password=module.params['password'],
cache_name=module.params['cache_name'],
lifetime=module.params['lifetime'],
start_time=module.params['start_time'],
renewable=module.params['renewable'],
forwardable=module.params['forwardable'],
proxiable=module.params['proxiable'],
address_restricted=module.params['address_restricted'],
anonymous=module.params['anonymous'],
canonicalization=module.params['canonicalization'],
enterprise=module.params['enterprise'],
renewal=module.params['renewal'],
validate=module.params['validate'],
keytab=module.params['keytab'],
keytab_path=module.params['keytab_path'],
)
keytab = IPAKeytab(
module,
state=state,
kdestroy_all=kdestroy_all,
principal=module.params["principal"],
password=module.params["password"],
cache_name=module.params["cache_name"],
lifetime=module.params["lifetime"],
start_time=module.params["start_time"],
renewable=module.params["renewable"],
forwardable=module.params["forwardable"],
proxiable=module.params["proxiable"],
address_restricted=module.params["address_restricted"],
anonymous=module.params["anonymous"],
canonicalization=module.params["canonicalization"],
enterprise=module.params["enterprise"],
renewal=module.params["renewal"],
validate=module.params["validate"],
keytab=module.params["keytab"],
keytab_path=module.params["keytab_path"],
)
if module.params['keytab_path'] is not None and module.params['keytab'] is not True:
if module.params["keytab_path"] is not None and module.params["keytab"] is not True:
module.fail_json(msg="If keytab_path is specified then keytab parameter must be True")
changed = False
if state == 'present':
if state == "present":
if not keytab.check_ticket_present():
changed = True
if not module.check_mode:
keytab.exec_kinit()
if state == 'absent':
if state == "absent":
if kdestroy_all:
changed = True
if not module.check_mode:
@ -377,5 +370,5 @@ def main():
module.exit_json(changed=changed)
if __name__ == '__main__':
if __name__ == "__main__":
main()