Skip to content

Commit

Permalink
[FEAT] add default user token based on the ENA_TOKEN parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
dameyerdave committed Jan 4, 2024
1 parent 6b9855c commit 89ffc03
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"quotechar",
"rdchem",
"templatecategories",
"userkey",
"webin",
"wellcompounds",
"wellwithdrawals"
Expand Down
20 changes: 20 additions & 0 deletions api/app/core/management/commands/initusertoken.py
Original file line number Diff line number Diff line change
@@ -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")
1 change: 1 addition & 0 deletions api/app/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &

Expand Down

0 comments on commit 89ffc03

Please sign in to comment.