Skip to content

Commit

Permalink
Bulk migration to Python 3.6 f-strings (ansible-collections#1810)
Browse files Browse the repository at this point in the history
Bulk migration to Python 3.6 f-strings

SUMMARY
We've dropped support for Python <3.6, bulk migrate to fstrings and perform some general string cleanup
A combination of

black --preview
flynt
some manual cleanup

ISSUE TYPE

Feature Pull Request

COMPONENT NAME
plugins/
tests/
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections@de33821
  • Loading branch information
tremble authored and alinabuzachis committed Oct 6, 2023
1 parent c036f89 commit a07a40d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions plugins/modules/iam_managed_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def get_or_create_policy_version(policy, policy_document):
"Document"
]
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Couldn't get policy version {0}".format(v["VersionId"]))
module.fail_json_aws(e, msg=f"Couldn't get policy version {v['VersionId']}")

if module.check_mode and compare_policies(document, json.loads(to_native(policy_document))):
return v, True
Expand Down Expand Up @@ -249,23 +249,23 @@ def detach_all_entities(policy, **kwargs):
try:
entities = client.list_entities_for_policy(PolicyArn=policy["Arn"], **kwargs)
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Couldn't detach list entities for policy {0}".format(policy["PolicyName"]))
module.fail_json_aws(e, msg=f"Couldn't detach list entities for policy {policy['PolicyName']}")

for g in entities["PolicyGroups"]:
try:
client.detach_group_policy(PolicyArn=policy["Arn"], GroupName=g["GroupName"])
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Couldn't detach group policy {0}".format(g["GroupName"]))
module.fail_json_aws(e, msg=f"Couldn't detach group policy {g['GroupName']}")
for u in entities["PolicyUsers"]:
try:
client.detach_user_policy(PolicyArn=policy["Arn"], UserName=u["UserName"])
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Couldn't detach user policy {0}".format(u["UserName"]))
module.fail_json_aws(e, msg=f"Couldn't detach user policy {u['UserName']}")
for r in entities["PolicyRoles"]:
try:
client.detach_role_policy(PolicyArn=policy["Arn"], RoleName=r["RoleName"])
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Couldn't detach role policy {0}".format(r["RoleName"]))
module.fail_json_aws(e, msg=f"Couldn't detach role policy {r['RoleName']}")
if entities["IsTruncated"]:
detach_all_entities(policy, marker=entities["Marker"])

Expand All @@ -289,7 +289,7 @@ def create_or_update_policy(existing_policy):
try:
rvalue = client.create_policy(PolicyName=name, Path="/", PolicyDocument=policy, Description=description)
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Couldn't create policy {0}".format(name))
module.fail_json_aws(e, msg=f"Couldn't create policy {name}")

module.exit_json(changed=True, policy=camel_dict_to_snake_dict(rvalue["Policy"]))
else:
Expand Down Expand Up @@ -327,12 +327,12 @@ def delete_policy(existing_policy):
try:
client.delete_policy_version(PolicyArn=existing_policy["Arn"], VersionId=v["VersionId"])
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Couldn't delete policy version {0}".format(v["VersionId"]))
module.fail_json_aws(e, msg=f"Couldn't delete policy version {v['VersionId']}")
# Delete policy
try:
client.delete_policy(PolicyArn=existing_policy["Arn"])
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Couldn't delete policy {0}".format(existing_policy["PolicyName"]))
module.fail_json_aws(e, msg=f"Couldn't delete policy {existing_policy['PolicyName']}")

# This is the one case where we will return the old policy
module.exit_json(changed=True, policy=camel_dict_to_snake_dict(existing_policy))
Expand Down

0 comments on commit a07a40d

Please sign in to comment.