Skip to content

Commit

Permalink
chore(gpg_secretstore): fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
lrsksr committed Mar 11, 2024
1 parent b4c259d commit 77a8238
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
18 changes: 12 additions & 6 deletions plugins/module_utils/gpg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,16 @@ def get_recipients_from_encrypted_file(self, slug) -> List[str]:
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
Expand Down Expand Up @@ -232,7 +236,9 @@ def __get_recipients_from_pass_file(self, password_slug: str) -> List[str]:
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(
Expand Down
17 changes: 11 additions & 6 deletions plugins/modules/gpg_secretstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
returned: changed
warning:
description: Human-readable warnings that accrued during the task
type: str[]
type: list
returned: failed or successful but with warnings
"""

Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 77a8238

Please sign in to comment.