chore(gpg_secretstore): fix lints

This commit is contained in:
Lars Kaiser 2024-02-29 17:26:40 +01:00
parent b4c259dd1d
commit 77a823859f
No known key found for this signature in database
GPG key ID: BB97304A16BC5DCF
2 changed files with 23 additions and 12 deletions

View file

@ -163,12 +163,16 @@ class SecretStore:
recipient_subkeys = self.__gpg.get_recipients(f.read())
for recipient_subkey in recipient_subkeys:
found_keys = self.__gpg.list_keys(keys=recipient_subkey)
if found_keys and found_keys.fingerprints and len(found_keys.fingerprints) > 0:
recipients.append(
found_keys.fingerprints[0]
)
if (
found_keys
and found_keys.fingerprints
and len(found_keys.fingerprints) > 0
):
recipients.append(found_keys.fingerprints[0])
else:
raise GPGException(f"Can not find primary key in keyring for encryption subkey {recipient_subkey}")
raise GPGException(
f"Can not find primary key in keyring for encryption subkey {recipient_subkey}"
)
return recipients
except FileNotFoundError:
raise FileNotFoundError
@ -232,7 +236,9 @@ class SecretStore:
while base_path.as_posix() != "/":
if os.path.isfile(base_path / self.pass_gpg_id_file):
break
print(f"debug: no {self.pass_gpg_id_file} file found on {base_path}, traversing up")
# This is not the proper way to do it, but the proper way is extremely complicated
# because we are in module_utils and not a module
# print(f"debug: no {self.pass_gpg_id_file} file found on {base_path}, traversing up")
base_path = base_path.parent
else:
raise FileNotFoundError(

View file

@ -179,7 +179,7 @@ message:
returned: changed
warning:
description: Human-readable warnings that accrued during the task
type: str[]
type: list
returned: failed or successful but with warnings
"""
@ -364,7 +364,12 @@ def main():
errors.append(missing_required_lib(lib))
traceback.append(str(exception))
if errors:
module.fail_json(warning=',\n'.join(warnings), errors=errors, traceback="\n".join(traceback), msg=',\n'.join(warnings))
module.fail_json(
warning=",\n".join(warnings),
errors=errors,
traceback="\n".join(traceback),
msg=",\n".join(warnings),
)
store = SecretStore(
password_store_path=module.params["password_store_path"],
@ -419,9 +424,9 @@ def main():
)
result["changed"] = False
else:
result[
"message"
] = "Secret rotation requested: rotating, if possible."
result["message"] = (
"Secret rotation requested: rotating, if possible."
)
result["secret"] = secretGenerator.getSecretData()
result["action"] = "update"
result["changed"] = True
@ -495,7 +500,7 @@ def main():
if result["warning"]:
for warn_msg in result["warning"]:
module.warn(warn_msg)
module.warn(warn_msg)
result["diff"]["before"] = "\n".join(result["diff"]["before"]) + "\n"
result["diff"]["after"] = "\n".join(result["diff"]["after"]) + "\n"