2020-10-08 17:54:04 +00:00
|
|
|
import random
|
|
|
|
import string
|
|
|
|
|
2020-10-06 13:46:22 +00:00
|
|
|
from django.core.management.base import BaseCommand
|
2020-10-08 17:54:04 +00:00
|
|
|
from django.core.exceptions import ObjectDoesNotExist
|
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
from uncloud_pay.models import BillingAddress, RecurringPeriod, Product
|
2020-10-25 20:00:30 +00:00
|
|
|
from uncloud.models import UncloudProvider, UncloudNetwork
|
2020-10-06 16:53:13 +00:00
|
|
|
|
2020-10-06 13:46:22 +00:00
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = 'Add standard uncloud values'
|
|
|
|
|
|
|
|
def add_arguments(self, parser):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
2020-10-08 17:54:04 +00:00
|
|
|
# Order matters, objects can be dependent on each other
|
|
|
|
|
|
|
|
admin_username="uncloud-admin"
|
|
|
|
pw_length = 32
|
|
|
|
|
|
|
|
# Only set password if the user did not exist before
|
|
|
|
try:
|
|
|
|
admin_user = get_user_model().objects.get(username=settings.UNCLOUD_ADMIN_NAME)
|
|
|
|
except ObjectDoesNotExist:
|
|
|
|
random_password = ''.join(random.SystemRandom().choice(string.ascii_lowercase + string.digits) for _ in range(pw_length))
|
|
|
|
|
|
|
|
admin_user = get_user_model().objects.create_user(username=settings.UNCLOUD_ADMIN_NAME, password=random_password)
|
|
|
|
admin_user.is_superuser=True
|
|
|
|
admin_user.is_staff=True
|
|
|
|
admin_user.save()
|
|
|
|
|
|
|
|
print(f"Created admin user '{admin_username}' with password '{random_password}'")
|
|
|
|
|
|
|
|
BillingAddress.populate_db_defaults()
|
2020-10-06 13:46:22 +00:00
|
|
|
RecurringPeriod.populate_db_defaults()
|
2020-10-06 16:53:13 +00:00
|
|
|
Product.populate_db_defaults()
|
2020-10-11 20:32:08 +00:00
|
|
|
|
|
|
|
UncloudNetwork.populate_db_defaults()
|
|
|
|
UncloudProvider.populate_db_defaults()
|