Created
May 23, 2023 20:04
-
-
Save mlbiam/f0b1d7f1dc625b04e96ede19e94a255d to your computer and use it in GitHub Desktop.
clear-oidc-sessions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kubernetes import client, config | |
from kubernetes.client import CustomObjectsApi | |
from datetime import datetime,timezone | |
from sys import argv | |
config.load_kube_config() | |
group = "openunison.tremolo.io" | |
version = "v2" | |
plural = "oidc-sessions" | |
done = False | |
continueCookie = '' | |
while not done: | |
sessions = client.CustomObjectsApi().list_namespaced_custom_object(group=group,version=version,plural=plural,namespace='openunison',limit=int(argv[1]),_continue=continueCookie) | |
if sessions.get("metadata").get("continue") != '': | |
continueCookie = sessions.get("metadata").get("continue") | |
print("Records left: " + str(sessions.get("metadata").get("remainingItemCount"))) | |
else: | |
print("Last records") | |
done = True | |
for session in sessions.get("items"): | |
name = session.get("metadata").get("name") | |
expires = session.get("spec").get("expires") | |
expirests = datetime.fromisoformat(expires) | |
if expirests <= datetime.now(timezone.utc): | |
client.CustomObjectsApi().delete_namespaced_custom_object(group=group,version=version,plural=plural,namespace='openunison',name=name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment