You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and dots ('.'), can be up to 35 characters long. Letters must be lowercase.
21 lines
935 B
21 lines
935 B
from django.core.management.base import BaseCommand |
|
from api.models import MasterKey |
|
|
|
class Command(BaseCommand): |
|
help = 'Generate a new master key' |
|
|
|
def add_arguments(self, parser): |
|
parser.add_argument('--description', type=str, help='Description for the key') |
|
parser.add_argument('--permissions', nargs='+', help='List of permissions for the key') |
|
|
|
def handle(self, *args, **kwargs): |
|
description = kwargs.get('description') or 'Generated via management command' |
|
permissions = kwargs.get('permissions') or [] |
|
|
|
master_key = MasterKey.generate_key( |
|
description=description, |
|
permissions=permissions |
|
) |
|
|
|
self.stdout.write(self.style.SUCCESS(f'Successfully created master key: {master_key.key_id}')) |
|
self.stdout.write(self.style.WARNING(f'Key value (save this securely, it will not be shown again): {master_key.key_value}')) |