From 0ba2c93d7ffcf441d8fcb50f0645cfdf35b47f0c Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Mon, 8 Jun 2020 19:20:27 +0000 Subject: [PATCH] Added a showapikeys management command, to be able to easily see the api keys. - Legacy-Id: 17935 --- ietf/api/management/commands/showapikeys.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 ietf/api/management/commands/showapikeys.py diff --git a/ietf/api/management/commands/showapikeys.py b/ietf/api/management/commands/showapikeys.py new file mode 100644 index 000000000..48d2bec97 --- /dev/null +++ b/ietf/api/management/commands/showapikeys.py @@ -0,0 +1,21 @@ +# Copyright The IETF Trust 2018-2020, All Rights Reserved +# -*- coding: utf-8 -*- + +from django.core.management.base import BaseCommand + +import debug # pyflakes:ignore + +from ietf.person.models import PersonalApiKey + +class Command(BaseCommand): + + help = 'Show existing personal API keys' + + def add_arguments(self, parser): + pass + + def handle(self, *args, **options): + format = "%-36s %-24s %-64s %-16s" + self.stdout.write(format % ('Endpoint', 'Login', 'Key', 'Used')) + for key in PersonalApiKey.objects.filter(): + self.stdout.write(format % (key.endpoint, key.person.user.username, key.hash(), key.latest.strftime('%Y-%m-%d %H:%M') if key.latest else ''))