Cleanup stage users: loop over all the pages

Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
This commit is contained in:
Aurélien Bompard
2026-01-13 17:31:05 +01:00
parent d18fb23702
commit 2d80cc95c2

View File

@@ -14,12 +14,16 @@ os.environ["KRB5_CLIENT_KTNAME"] = KEYTAB.format(hostname=hostname)
client = ClientMeta(hostname)
client.login_kerberos()
threshold = datetime.utcnow() - timedelta(days=KEEP_DAYS)
for user in client.stageuser_find()["result"]:
username = user["uid"][0]
created_on = datetime.strptime(
user["fascreationtime"][0]["__datetime__"], "%Y%m%d%H%M%SZ"
)
if created_on > threshold:
continue
print(f"Deleting old stage user: {username}")
client.stageuser_del(username)
while True:
response = client.stageuser_find()
for user in response["result"]:
username = user["uid"][0]
created_on = datetime.strptime(
user["fascreationtime"][0]["__datetime__"], "%Y%m%d%H%M%SZ"
)
if created_on > threshold:
continue
print(f"Deleting old stage user: {username}")
client.stageuser_del(username)
if not response["truncated"]:
break