You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
555 B

  1. from base64 import urlsafe_b64encode
  2. import os
  3. from django.core.management.base import BaseCommand
  4. from hc.accounts.models import Profile
  5. class Command(BaseCommand):
  6. help = """Create read-only API keys."""
  7. def handle(self, *args, **options):
  8. c = 0
  9. q = Profile.objects.filter(api_key_readonly="").exclude(api_key="")
  10. for profile in q:
  11. profile.api_key_readonly = urlsafe_b64encode(os.urandom(24)).decode()
  12. profile.save()
  13. c += 1
  14. return "Done! Generated %d readonly keys." % c