2022-06-12 18:25:51 +02:00
|
|
|
import logging
|
|
|
|
|
|
|
|
import click
|
|
|
|
|
|
|
|
from fittrackee.cli.app import app
|
|
|
|
|
|
|
|
from .clean import clean_tokens
|
|
|
|
|
|
|
|
handler = logging.StreamHandler()
|
2022-09-15 13:14:55 +02:00
|
|
|
logger = logging.getLogger('fittrackee_clean_oauth2_tokens')
|
2022-06-12 18:25:51 +02:00
|
|
|
logger.setLevel(logging.INFO)
|
|
|
|
logger.addHandler(handler)
|
|
|
|
|
|
|
|
|
|
|
|
@click.group(name='oauth2')
|
|
|
|
def oauth2_cli() -> None:
|
|
|
|
"""Manage OAuth2 tokens."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@oauth2_cli.command('clean')
|
2022-08-03 16:47:03 +02:00
|
|
|
@click.option('--days', type=int, required=True, help='Number of days.')
|
2022-06-12 18:25:51 +02:00
|
|
|
def clean(
|
|
|
|
days: int,
|
|
|
|
) -> None:
|
|
|
|
"""Clean tokens expired for more than provided number of days"""
|
|
|
|
with app.app_context():
|
|
|
|
deleted_rows = clean_tokens(days)
|
|
|
|
logger.info(f'Expired deleted tokens: {deleted_rows}.')
|