diff --git a/.vscode/settings.json b/.vscode/settings.json index 10605d4..73195e5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -53,6 +53,7 @@ "quotechar", "rdchem", "templatecategories", + "userkey", "webin", "wellcompounds", "wellwithdrawals" diff --git a/api/app/core/management/commands/initusertoken.py b/api/app/core/management/commands/initusertoken.py new file mode 100644 index 0000000..27a3a7e --- /dev/null +++ b/api/app/core/management/commands/initusertoken.py @@ -0,0 +1,20 @@ +from django.core.management.base import BaseCommand +from django.contrib.auth import get_user_model +from rest_framework.authtoken.models import Token +from os import environ +from core import log +from uuid import uuid4 + + +class Command(BaseCommand): + def handle(self, *args, **options): + username = environ.get("ENA_USER", "ena") + User = get_user_model() + if not User.objects.filter(username=username).exists(): + user = User.objects.create(username=username, password=uuid4().hex) + log.debug("User account created") + userkey = environ.get("ENA_TOKEN", uuid4().hex) + Token.objects.create(user=user, key=userkey) + log.debug("Token created") + else: + log.warning("User account exists") diff --git a/api/app/entrypoint.sh b/api/app/entrypoint.sh index 4cd4648..1bca62e 100755 --- a/api/app/entrypoint.sh +++ b/api/app/entrypoint.sh @@ -8,6 +8,7 @@ python manage.py wait_for_db python manage.py makemigrations python manage.py migrate python manage.py initadmin +python manage.py initusertoken python manage.py db init python manage.py upload_process &