mirror of
https://pagure.io/fedora-infra/ansible.git
synced 2026-03-20 03:57:02 +08:00
Cleanup stage users: loop over all the pages
Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user