Browse Source

Add VRW user

V1
Joshua Rubingh 1 year ago
parent
commit
475ec90b6d
  1. 24
      VRE/apps/api/management/commands/dockersetup.py
  2. 4
      docker/entrypoint.api.sh
  3. 10
      docker/project.env
  4. 11
      docker/project.example.env

24
VRE/apps/api/management/commands/dockersetup.py

@ -1,11 +1,9 @@ @@ -1,11 +1,9 @@
from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import User
from django.contrib.auth.models import Group
from django.db.utils import IntegrityError
#from polls.models import Question as Poll
class Command(BaseCommand):
help = 'Setting up admin and tusd users for VRE'
@ -14,27 +12,35 @@ class Command(BaseCommand): @@ -14,27 +12,35 @@ class Command(BaseCommand):
parser.add_argument('password', help='Password')
parser.add_argument('email', help='Email address')
parser.add_argument('--nokey', help='Skip token key')
parser.add_argument('--key', help='Token key')
parser.add_argument('--secret', help='Token secret')
parser.add_argument('--group', help='Groupname to add the user to')
def handle(self, *args, **options):
try:
user = User.objects.create_superuser(username=options['username'], password=options['password'], email=options['email'])
self.stdout.write(self.style.SUCCESS('Successfully created user "%s"' % options['username']))
self.stdout.write(self.style.SUCCESS('Successfully created user "%s"' % (options['username'],)))
if options['key'] is not None and options['secret'] is not None:
user.token.key=options['key']
user.token.secret=options['secret']
user.token.save()
self.stdout.write(self.style.SUCCESS('Successfully created token for user "%s"' % options['username']))
self.stdout.write(self.style.SUCCESS('Successfully created token for user "%s"' % (options['username'],)))
else:
elif options['nokey'] is not None:
# We do not want an token for the admin
user.token.delete()
except IntegrityError as ex:
if 'unique constraint' in str(ex).lower():
self.stdout.write(self.style.WARNING('User "%s" already exists' % options['username']))
self.stdout.write(self.style.WARNING('User "%s" already exists' % (options['username'],)))
else:
raise CommandError('Could not create user "%s": %s' % (options['username'],ex))
raise CommandError('Could not create user "%s": %s' % (options['username'],ex))
if options['group'] is not None:
user = User.objects.get(username=options['username'])
new_group, created = Group.objects.get_or_create(name=options['group'])
user.groups.add(new_group)
self.stdout.write(self.style.SUCCESS('Added user "%s" to group "%s"' % (options['username'],options['group'])))

4
docker/entrypoint.api.sh

@ -23,8 +23,10 @@ python manage.py loaddata virtual_machine_initial_data @@ -23,8 +23,10 @@ python manage.py loaddata virtual_machine_initial_data
python manage.py collectstatic --noinput
# Create a super user
python manage.py dockersetup ${DJANGO_ADMIN_NAME} ${DJANGO_ADMIN_PASSWORD} ${DJANGO_ADMIN_EMAIL}
python manage.py dockersetup --nokey 1 ${DJANGO_ADMIN_NAME} ${DJANGO_ADMIN_PASSWORD} ${DJANGO_ADMIN_EMAIL}
# Create the HAWK REST user
python manage.py dockersetup --key ${DROPOFF_API_HAWK_KEY} --secret ${DROPOFF_API_HAWK_SECRET} ${DROPOFF_API_USER} ${DROPOFF_API_PASSWORD} ${DROPOFF_API_EMAIL}
# Create the VRW REST user
python manage.py dockersetup --group ${VRW_API_GROUP} ${VRW_API_USER} ${VRW_API_PASSWORD} ${VRW_API_EMAIL}
exec "$@"

10
docker/project.env

@ -121,3 +121,13 @@ DROPOFF_API_USER_SECRET=ExfcR524851PxVmbNzvR7qkoHwzSSJ1A @@ -121,3 +121,13 @@ DROPOFF_API_USER_SECRET=ExfcR524851PxVmbNzvR7qkoHwzSSJ1A
# What is the full VRE Portal domains. By default http://localhost:1337/api
VRE_BROKER_API=http://api-nginx/api
# VRW API settigs. This is for the VRW client to get data for creating Virtual Workspaces
# The security group that is allowed to access the VRW part of the REST API
VRW_API_GROUP=vrw-api
# The VRW username for the REST API
VRW_API_USER=vrw
# The VRW password for the REST API
VRW_API_PASSWORD=securepassword
# The VRW email address for the REST API
VRW_API_EMAIL=vrw+no-reply@rug.nl

11
docker/project.example.env

@ -67,3 +67,14 @@ DROPOFF_API_PASSWORD=doemaarwat @@ -67,3 +67,14 @@ DROPOFF_API_PASSWORD=doemaarwat
DROPOFF_API_EMAIL=tusd+no-reply@rug.nl
DROPOFF_API_HAWK_KEY=sDl6YmRv
DROPOFF_API_HAWK_SECRET=ExfcR524851PxVmbNzvR7qkoHwzSSJ1A
# VRW API settigs. This is for the VRW client to get data for creating Virtual Workspaces
# The security group that is allowed to access the VRW part of the REST API
# Make sure this variable has the same value of the Django setting: setting.VRW_API_GROUP
VRW_API_GROUP=vrw-api
# The VRW username for the REST API
VRW_API_USER=vrw
# The VRW password for the REST API
VRW_API_PASSWORD=securepassword
# The VRW email address for the REST API
VRW_API_EMAIL=vrw+no-reply@rug.nl
Loading…
Cancel
Save