-
Notifications
You must be signed in to change notification settings - Fork 56
Adjusted key_setup() to fix my issue #110 #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,11 +274,18 @@ def key_setup(self): | |
# check if keys exist in KEY_PATH else create | ||
assert "KEY_NAME" in os.environ, f"missing KEY_NAME env variable" | ||
key_path = os.getenv("KEY_PATH", "") | ||
|
||
if not os.path.exists(key_path): | ||
os.makedirs(key_path) | ||
|
||
if key_path: | ||
key_path = f"{key_path}/{os.environ['KEY_NAME']}.key" | ||
key_path = f"{key_path}/{os.environ['KEY_NAME']}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing the .key postfix is probably a good idea in the long run, but is a breaking change for anyone defining the KEY_NAME without .key. |
||
else: | ||
key_path = f"{os.environ['KEY_NAME']}" | ||
|
||
if not os.path.exists(key_path): | ||
with open(key_path, "w") as file: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once the directory exists, there is is no need to make an empty file. |
||
file.write("") | ||
try: | ||
with open(key_path + ".key", "r") as k: | ||
self._privkey = jwk.JWK.from_json(k.readline()) | ||
|
@@ -429,9 +436,9 @@ async def send_email( | |
|
||
message = MessageSchema( | ||
subject=f"{subject}", | ||
recipients=recipients | ||
if isinstance(recipients, list) | ||
else [recipients], # List of recipients, as many as you can pass | ||
recipients=( | ||
recipients if isinstance(recipients, list) else [recipients] | ||
), # List of recipients, as many as you can pass | ||
body=body, | ||
subtype="html", | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of adding a check here for the path, but raising an exception instead of creating the path.
The reason behind this is that with the ephemeral workers like docker / kubernetes, we would have a different private key each a new instance started instead of forcing the developer to ensure that a persistent volume is used to store the private key. For additional context, when a private key changes any existing and unexpired tokens will not work with a newly refreshed private key.