forked from ansible/awx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a cleanup_authtokens management command
We also will now clean these up during cleanup_deleted
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright (c) 2015 Ansible, Inc. | ||
# All Rights Reserved. | ||
|
||
# Python | ||
import datetime | ||
import logging | ||
from optparse import make_option | ||
|
||
# Django | ||
from django.db import transaction | ||
from django.core.management.base import BaseCommand | ||
from django.utils.timezone import now | ||
|
||
# AWX | ||
from awx.main.models import * # noqa | ||
|
||
class Command(BaseCommand): | ||
''' | ||
Management command to cleanup expired auth tokens | ||
''' | ||
|
||
help = 'Cleanup expired auth tokens.' | ||
|
||
def init_logging(self): | ||
log_levels = dict(enumerate([logging.ERROR, logging.INFO, | ||
logging.DEBUG, 0])) | ||
self.logger = logging.getLogger('awx.main.commands.cleanup_authtokens') | ||
handler = logging.StreamHandler() | ||
handler.setFormatter(logging.Formatter('%(message)s')) | ||
self.logger.addHandler(handler) | ||
self.logger.propagate = False | ||
|
||
@transaction.atomic | ||
def handle(self, *args, **options): | ||
self.init_logging() | ||
tokens_removed = AuthToken.objects.filter(expires__lt=now()) | ||
self.logger.log(99, "Removing %d expired auth tokens" % tokens_removed.count()) | ||
tokens_removed.delete() |
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