2021-10-13 08:12:44 +00:00
|
|
|
import sys
|
2021-10-13 07:38:44 +00:00
|
|
|
|
2021-12-20 22:57:27 +00:00
|
|
|
import click
|
2021-10-13 07:38:44 +00:00
|
|
|
from canaille import create_app
|
2021-12-20 22:57:27 +00:00
|
|
|
from canaille.models import AuthorizationCode
|
|
|
|
from canaille.models import Token
|
2021-10-13 07:38:44 +00:00
|
|
|
from flask import current_app
|
2021-12-20 22:57:27 +00:00
|
|
|
from flask.cli import FlaskGroup
|
|
|
|
from flask.cli import with_appcontext
|
2021-04-04 16:25:37 +00:00
|
|
|
|
|
|
|
|
2021-10-13 07:38:44 +00:00
|
|
|
@click.group(cls=FlaskGroup, create_app=create_app)
|
|
|
|
def cli():
|
|
|
|
pass
|
2021-04-04 16:25:37 +00:00
|
|
|
|
|
|
|
|
2021-10-13 07:38:44 +00:00
|
|
|
@cli.command()
|
|
|
|
@with_appcontext
|
2021-04-04 16:25:37 +00:00
|
|
|
def clean():
|
|
|
|
"""
|
|
|
|
Remove expired tokens and authorization codes.
|
|
|
|
"""
|
2021-10-12 16:24:51 +00:00
|
|
|
from canaille import setup_ldap_connection, teardown_ldap_connection
|
2021-04-04 16:25:37 +00:00
|
|
|
|
2021-10-12 16:24:51 +00:00
|
|
|
setup_ldap_connection(current_app)
|
2021-04-04 16:25:37 +00:00
|
|
|
|
|
|
|
for t in Token.filter():
|
|
|
|
if t.is_expired():
|
|
|
|
t.delete()
|
|
|
|
|
|
|
|
for a in AuthorizationCode.filter():
|
|
|
|
if a.is_expired():
|
|
|
|
a.delete()
|
|
|
|
|
2021-10-12 16:24:51 +00:00
|
|
|
teardown_ldap_connection(current_app)
|
2021-10-13 08:12:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
|
|
|
@with_appcontext
|
|
|
|
def check():
|
|
|
|
"""
|
|
|
|
Check the configuration file.
|
|
|
|
"""
|
|
|
|
from canaille.configuration import validate, ConfigurationException
|
2021-10-29 12:20:06 +00:00
|
|
|
|
2021-10-13 08:12:44 +00:00
|
|
|
try:
|
|
|
|
validate(current_app.config, validate_remote=True)
|
|
|
|
except ConfigurationException as exc:
|
|
|
|
print(exc)
|
|
|
|
sys.exit(1)
|
2021-11-08 17:09:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
|
|
|
@with_appcontext
|
|
|
|
def install():
|
|
|
|
"""
|
2021-11-08 17:30:31 +00:00
|
|
|
Installs canaille elements from the configuration.
|
2021-11-08 17:09:05 +00:00
|
|
|
"""
|
|
|
|
from canaille.installation import install
|
2021-11-13 18:11:56 +00:00
|
|
|
from canaille.configuration import ConfigurationException
|
2021-11-08 17:09:05 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
install(current_app.config)
|
|
|
|
|
|
|
|
except ConfigurationException as exc:
|
|
|
|
print(exc)
|
|
|
|
sys.exit(1)
|