2023-04-09 14:14:38 +00:00
|
|
|
import click
|
2024-03-15 18:58:06 +00:00
|
|
|
from flask.cli import with_appcontext
|
|
|
|
|
2023-04-09 09:37:04 +00:00
|
|
|
from canaille.app import models
|
2023-04-09 14:14:38 +00:00
|
|
|
from canaille.app.commands import with_backendcontext
|
2024-04-16 20:42:29 +00:00
|
|
|
from canaille.backends import Backend
|
2023-04-09 14:14:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
@click.command()
|
|
|
|
@with_appcontext
|
|
|
|
@with_backendcontext
|
|
|
|
def clean():
|
2023-12-28 17:31:57 +00:00
|
|
|
"""Remove expired tokens and authorization codes."""
|
2024-04-16 20:42:29 +00:00
|
|
|
for t in Backend.instance.query(models.Token):
|
2023-04-09 14:14:38 +00:00
|
|
|
if t.is_expired():
|
2024-04-16 20:42:29 +00:00
|
|
|
Backend.instance.delete(t)
|
2023-04-09 14:14:38 +00:00
|
|
|
|
2024-04-16 20:42:29 +00:00
|
|
|
for a in Backend.instance.query(models.AuthorizationCode):
|
2023-04-09 14:14:38 +00:00
|
|
|
if a.is_expired():
|
2024-04-16 20:42:29 +00:00
|
|
|
Backend.instance.delete(a)
|
2023-04-09 14:14:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
def register(cli):
|
|
|
|
cli.add_command(clean)
|