mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-02-04 07:51:50 +00:00
modules [jk]*: use f-strings (#10970)
* modules [jk]*: use f-strings * add changelog frag * Apply suggestions from code review * typing insanity
This commit is contained in:
parent
8120e9347e
commit
4a6a449fbd
46 changed files with 363 additions and 408 deletions
|
|
@ -306,19 +306,19 @@ def main():
|
|||
if user_rep is not None:
|
||||
uid = user_rep.get('id')
|
||||
else:
|
||||
module.fail_json(msg='Could not fetch user for username %s:' % target_username)
|
||||
module.fail_json(msg=f'Could not fetch user for username {target_username}:')
|
||||
else:
|
||||
if uid is None and target_username is None:
|
||||
user_rep = kc.get_service_account_user_by_client_id(client_id=service_account_user_client_id, realm=realm)
|
||||
if user_rep is not None:
|
||||
uid = user_rep['id']
|
||||
else:
|
||||
module.fail_json(msg='Could not fetch service-account-user for client_id %s:' % target_username)
|
||||
module.fail_json(msg=f'Could not fetch service-account-user for client_id {target_username}:')
|
||||
|
||||
if cid is None and client_id is not None:
|
||||
cid = kc.get_client_id(client_id=client_id, realm=realm)
|
||||
if cid is None:
|
||||
module.fail_json(msg='Could not fetch client %s:' % client_id)
|
||||
module.fail_json(msg=f'Could not fetch client {client_id}:')
|
||||
if roles is None:
|
||||
module.exit_json(msg="Nothing to do (no roles specified).")
|
||||
else:
|
||||
|
|
@ -334,7 +334,7 @@ def main():
|
|||
if role_id is not None:
|
||||
role['id'] = role_id
|
||||
else:
|
||||
module.fail_json(msg='Could not fetch role %s for client_id %s or realm %s' % (role.get('name'), client_id, realm))
|
||||
module.fail_json(msg=f"Could not fetch role {role.get('name')} for client_id {client_id} or realm {realm}")
|
||||
# Fetch missing role_name
|
||||
else:
|
||||
if cid is None:
|
||||
|
|
@ -342,7 +342,7 @@ def main():
|
|||
else:
|
||||
role['name'] = kc.get_client_user_rolemapping_by_id(uid=uid, cid=cid, rid=role.get('id'), realm=realm)['name']
|
||||
if role.get('name') is None:
|
||||
module.fail_json(msg='Could not fetch role %s for client_id %s or realm %s' % (role.get('id'), client_id, realm))
|
||||
module.fail_json(msg=f"Could not fetch role {role.get('id')} for client_id {client_id} or realm {realm}")
|
||||
|
||||
# Get effective role mappings
|
||||
if cid is None:
|
||||
|
|
@ -383,7 +383,7 @@ def main():
|
|||
if module.check_mode:
|
||||
module.exit_json(**result)
|
||||
kc.add_user_rolemapping(uid=uid, cid=cid, role_rep=update_roles, realm=realm)
|
||||
result['msg'] = 'Roles %s assigned to userId %s.' % (update_roles, uid)
|
||||
result['msg'] = f'Roles {update_roles} assigned to userId {uid}.'
|
||||
if cid is None:
|
||||
assigned_roles_after = kc.get_realm_user_composite_rolemappings(uid=uid, realm=realm)
|
||||
else:
|
||||
|
|
@ -398,7 +398,7 @@ def main():
|
|||
if module.check_mode:
|
||||
module.exit_json(**result)
|
||||
kc.delete_user_rolemapping(uid=uid, cid=cid, role_rep=update_roles, realm=realm)
|
||||
result['msg'] = 'Roles %s removed from userId %s.' % (update_roles, uid)
|
||||
result['msg'] = f'Roles {update_roles} removed from userId {uid}.'
|
||||
if cid is None:
|
||||
assigned_roles_after = kc.get_realm_user_composite_rolemappings(uid=uid, realm=realm)
|
||||
else:
|
||||
|
|
@ -408,7 +408,7 @@ def main():
|
|||
# Do nothing
|
||||
else:
|
||||
result['changed'] = False
|
||||
result['msg'] = 'Nothing to do, roles %s are correctly mapped to user for username %s.' % (roles, target_username)
|
||||
result['msg'] = f'Nothing to do, roles {roles} are correctly mapped to user for username {target_username}.'
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue