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()) recipient_subkeys = self.__gpg.get_recipients(f.read())
for recipient_subkey in recipient_subkeys: for recipient_subkey in recipient_subkeys:
found_keys = self.__gpg.list_keys(keys=recipient_subkey) found_keys = self.__gpg.list_keys(keys=recipient_subkey)
if found_keys and found_keys.fingerprints and len(found_keys.fingerprints) > 0: if (
recipients.append( found_keys
found_keys.fingerprints[0] and found_keys.fingerprints
) and len(found_keys.fingerprints) > 0
):
recipients.append(found_keys.fingerprints[0])
else: 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 return recipients
except FileNotFoundError: except FileNotFoundError:
raise FileNotFoundError raise FileNotFoundError
@ -232,7 +236,9 @@ class SecretStore:
while base_path.as_posix() != "/": while base_path.as_posix() != "/":
if os.path.isfile(base_path / self.pass_gpg_id_file): if os.path.isfile(base_path / self.pass_gpg_id_file):
break 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 base_path = base_path.parent
else: else:
raise FileNotFoundError( raise FileNotFoundError(

View file

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