Skip to content

Commit

Permalink
Apply flynt
Browse files Browse the repository at this point in the history
  • Loading branch information
tremble committed Oct 13, 2023
1 parent 2f3d4f5 commit 4a96c82
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
26 changes: 10 additions & 16 deletions plugins/modules/ec2_metadata_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,17 +524,15 @@ def _fetch(self, url):
response, info = fetch_url(self.module, encoded_url, headers=headers, force=True)

if info.get("status") in (401, 403):
self.module.fail_json(msg="Failed to retrieve metadata from AWS: {0}".format(info["msg"]), response=info)
self.module.fail_json(msg=f"Failed to retrieve metadata from AWS: {info['msg']}", response=info)
elif info.get("status") not in (200, 404):
time.sleep(3)
# request went bad, retry once then raise
self.module.warn("Retrying query to metadata service. First attempt failed: {0}".format(info["msg"]))
self.module.warn(f"Retrying query to metadata service. First attempt failed: {info['msg']}")
response, info = fetch_url(self.module, encoded_url, headers=headers, force=True)
if info.get("status") not in (200, 404):
# fail out now
self.module.fail_json(
msg="Failed to retrieve metadata from AWS: {0}".format(info["msg"]), response=info
)
self.module.fail_json(msg=f"Failed to retrieve metadata from AWS: {info['msg']}", response=info)
if response and info["status"] < 400:
data = response.read()
if "user-data" in encoded_url:
Expand Down Expand Up @@ -585,15 +583,15 @@ def fetch(self, uri, recurse=True):
content = self._fetch(new_uri)
if field == "security-groups" or field == "security-group-ids":
sg_fields = ",".join(content.split("\n"))
self._data["%s" % (new_uri)] = sg_fields
self._data[f"{new_uri}"] = sg_fields
else:
try:
json_dict = json.loads(content)
self._data["%s" % (new_uri)] = content
self._data[f"{new_uri}"] = content
for key, value in json_dict.items():
self._data["%s:%s" % (new_uri, key.lower())] = value
self._data[f"{new_uri}:{key.lower()}"] = value
except (json_decode_error, AttributeError):
self._data["%s" % (new_uri)] = content # not a stringified JSON string
self._data[f"{new_uri}"] = content # not a stringified JSON string

def fix_invalid_varnames(self, data):
"""Change ':'' and '-' to '_' to ensure valid template variable names"""
Expand All @@ -612,19 +610,15 @@ def fetch_session_token(self, uri_token):
response, info = fetch_url(self.module, uri_token, method="PUT", headers=headers, force=True)

if info.get("status") == 403:
self.module.fail_json(
msg="Failed to retrieve metadata token from AWS: {0}".format(info["msg"]), response=info
)
self.module.fail_json(msg=f"Failed to retrieve metadata token from AWS: {info['msg']}", response=info)
elif info.get("status") not in (200, 404):
time.sleep(3)
# request went bad, retry once then raise
self.module.warn("Retrying query to metadata service. First attempt failed: {0}".format(info["msg"]))
self.module.warn(f"Retrying query to metadata service. First attempt failed: {info['msg']}")
response, info = fetch_url(self.module, uri_token, method="PUT", headers=headers, force=True)
if info.get("status") not in (200, 404):
# fail out now
self.module.fail_json(
msg="Failed to retrieve metadata token from AWS: {0}".format(info["msg"]), response=info
)
self.module.fail_json(msg=f"Failed to retrieve metadata token from AWS: {info['msg']}", response=info)
if response:
token_data = response.read()
else:
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/s3_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,9 +1381,9 @@ def s3_object_do_copy(module, connection, connection_v4, s3_vars):
changed |= updated
number_keys_updated += 1 if updated else 0

msg = "object(s) from buckets '{0}' and '{1}' are the same.".format(src_bucket, s3_vars["bucket"])
msg = f"object(s) from buckets '{src_bucket}' and '{s3_vars['bucket']}' are the same."
if number_keys_updated:
msg = "{0} copied into bucket '{1}'".format(number_keys_updated, s3_vars["bucket"])
msg = f"{number_keys_updated} copied into bucket '{s3_vars['bucket']}'"
module.exit_json(changed=changed, msg=msg)
else:
# copy single object from source bucket into destination bucket
Expand Down

0 comments on commit 4a96c82

Please sign in to comment.