File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change 1
1
import datetime
2
2
3
+ import structlog
3
4
from flask import render_template
4
5
from sqlalchemy import and_ , or_ , func
5
6
16
17
# Number of days before an API key expires
17
18
API_KEY_EXPIRES_SOON_DAYS = 7
18
19
20
+ log = structlog .get_logger (__name__ )
21
+
19
22
20
23
def generate_user_api_key (role ):
21
24
event = "regenerated" if role .has_api_key else "generated"
@@ -78,13 +81,15 @@ def _send_api_key_expiration_notification(
78
81
)
79
82
80
83
for role in query :
84
+ expires_at = role .api_key_expires_at
81
85
params = {
82
86
"role" : role ,
83
- "expires_at" : role . api_key_expires_at ,
87
+ "expires_at" : expires_at ,
84
88
"settings_url" : ui_url ("settings" ),
85
89
}
86
90
plain = render_template (plain_template , ** params )
87
91
html = render_template (html_template , ** params )
92
+ log .info (f"Sending API key expiration notification: { role } at { expires_at } " )
88
93
email_role (role , subject , html = html , plain = plain )
89
94
90
95
query .update ({Role .api_key_expiration_notification_sent : days })
Original file line number Diff line number Diff line change 21
21
OP_PRUNE_ENTITY ,
22
22
)
23
23
from aleph .logic .alerts import check_alerts
24
+ from aleph .logic .api_keys import send_api_key_expiration_notifications
24
25
from aleph .logic .collections import reingest_collection , reindex_collection
25
26
from aleph .logic .collections import compute_collections , refresh_collection
26
27
from aleph .logic .notifications import generate_digest , delete_old_notifications
@@ -91,6 +92,7 @@ def periodic(self):
91
92
update_roles ()
92
93
check_alerts ()
93
94
generate_digest ()
95
+ send_api_key_expiration_notifications ()
94
96
delete_expired_exports ()
95
97
delete_old_notifications ()
96
98
You can’t perform that action at this time.
0 commit comments