diff --git a/ligoauth/migrations/0001_initial.py b/ligoauth/migrations/0001_initial.py index 3d3194b339b01fee67cf9287a7d7958382f2ab9a..20f185f7da26e07faaf76516ca740ce8463bf6ae 100644 --- a/ligoauth/migrations/0001_initial.py +++ b/ligoauth/migrations/0001_initial.py @@ -1,14 +1,19 @@ # -*- coding: utf-8 -*- +# Generated by Django 1.11.5 on 2017-10-26 19:56 from __future__ import unicode_literals -from django.db import models, migrations from django.conf import settings +import django.contrib.auth.models +from django.db import migrations, models +import django.db.models.deletion class Migration(migrations.Migration): + initial = True + dependencies = [ - ('auth', '0001_initial'), + ('auth', '0008_auto_20171020_1045'), migrations.swappable_dependency(settings.AUTH_USER_MODEL), ] @@ -16,18 +21,15 @@ class Migration(migrations.Migration): migrations.CreateModel( name='AlternateEmail', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('email', models.EmailField(max_length=254)), ], - options={ - }, - bases=(models.Model,), ), migrations.CreateModel( name='LigoLdapUser', fields=[ - ('user_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)), - ('ldap_dn', models.CharField(unique=True, max_length=100)), + ('user_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)), + ('ldap_dn', models.CharField(max_length=100, unique=True)), ], options={ 'abstract': False, @@ -35,11 +37,14 @@ class Migration(migrations.Migration): 'verbose_name_plural': 'users', }, bases=('auth.user',), + managers=[ + ('objects', django.contrib.auth.models.UserManager()), + ], ), migrations.CreateModel( name='LocalUser', fields=[ - ('user_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)), + ('user_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to=settings.AUTH_USER_MODEL)), ], options={ 'abstract': False, @@ -47,22 +52,21 @@ class Migration(migrations.Migration): 'verbose_name_plural': 'users', }, bases=('auth.user',), + managers=[ + ('objects', django.contrib.auth.models.UserManager()), + ], ), migrations.CreateModel( name='X509Cert', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('subject', models.CharField(max_length=200)), ('users', models.ManyToManyField(to=settings.AUTH_USER_MODEL)), ], - options={ - }, - bases=(models.Model,), ), migrations.AddField( model_name='alternateemail', name='user', - field=models.ForeignKey(to=settings.AUTH_USER_MODEL), - preserve_default=True, + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), ), ] diff --git a/ligoauth/migrations/0002_auto_20150708_1134.py b/ligoauth/migrations/0002_auto_20150708_1134.py deleted file mode 100644 index ac7fee15a4732cc30761b65c2cb140d8a07bd800..0000000000000000000000000000000000000000 --- a/ligoauth/migrations/0002_auto_20150708_1134.py +++ /dev/null @@ -1,27 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations -import django.contrib.auth.models - - -class Migration(migrations.Migration): - - dependencies = [ - ('ligoauth', '0001_initial'), - ] - - operations = [ - migrations.AlterModelManagers( - name='ligoldapuser', - managers=[ - ('objects', django.contrib.auth.models.UserManager()), - ], - ), - migrations.AlterModelManagers( - name='localuser', - managers=[ - ('objects', django.contrib.auth.models.UserManager()), - ], - ), - ] diff --git a/ligoauth/migrations/0002_set_ligoauth_ligoldapuser_charset.py b/ligoauth/migrations/0002_set_ligoauth_ligoldapuser_charset.py new file mode 100644 index 0000000000000000000000000000000000000000..27cca8c494849644fc807be3f7b5bc2ee2d37ab1 --- /dev/null +++ b/ligoauth/migrations/0002_set_ligoauth_ligoldapuser_charset.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.5 on 2017-11-06 15:20 +from __future__ import unicode_literals + +from django.db import migrations, models + +from ligoauth.models import LigoLdapUser + +# Sets the ligoauth_ligoldapuser table to use utf-8 for the +# charset and collation. Otherwise you can get annoying warnings +# like 'incorrect string value from the Django mysql backend when +# saving users with accented characters in their names. +# +# We don't use the "correct" format for inserting parameters in the raw +# SQL query, but that's because apparently you can't do that with the +# table name itself. I don't see how there could be an SQL injection attack +# through the migrations, so I'm going to pronounce this safe. + +# Table name +TABLE_NAME = LigoLdapUser._meta.db_table + +class Migration(migrations.Migration): + + dependencies = [ + ('ligoauth', '0001_initial'), + ] + + operations = [ + migrations.RunSQL( + ["ALTER TABLE {table_name} DEFAULT CHARACTER SET UTF8;".format( + table_name=TABLE_NAME)], + ["ALTER TABLE {table_name} CONVERT TO CHARACTER SET UTF8;".format( + table_name=TABLE_NAME)], + ) + ] diff --git a/ligoauth/migrations/0003_auto_20150819_1201.py b/ligoauth/migrations/0003_auto_20150819_1201.py deleted file mode 100644 index 7b0280eca5bacbd3d8ea015ef791836843fe0216..0000000000000000000000000000000000000000 --- a/ligoauth/migrations/0003_auto_20150819_1201.py +++ /dev/null @@ -1,56 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations - -users = [ - { - 'username' : 'TIGER', - 'first_name' : '', - 'last_name' : 'TIGER', - 'email' : 'salvatore.vitale@ligo.org', - 'dns' : [ - "/DC=org/DC=ligo/O=LIGO/OU=Services/CN=TIGER/ldas-pcdev1.ligo.caltech.edu", - ] - }, -] - -def add_robot_user(apps, schema_editor): - X509Cert = apps.get_model("ligoauth", "X509Cert") - LocalUser = apps.get_model("ligoauth", "LocalUser") - - for entry in users: - user, created = LocalUser.objects.get_or_create(username=entry['username']) - if created: - user.first_name = entry['first_name'] - user.last_name = entry['last_name'] - user.email = entry['email'] - user.is_active = True - user.is_staff = False - user.is_superuser = False - user.save() - current_dns = set([cert.subject for cert in user.x509cert_set.all()]) - new_dns = set(entry['dns']) - - missing_dns = new_dns - current_dns - redundant_dns = current_dns - new_dns - - for dn in missing_dns: - cert, created = X509Cert.objects.get_or_create(subject=dn) - if created: - cert.save() - cert.users.add(user) - - for dn in redundant_dns: - cert = X509Cert.objects.get(subject=dn) - cert.users.remove(user) - -class Migration(migrations.Migration): - - dependencies = [ - ('ligoauth', '0002_auto_20150708_1134'), - ] - - operations = [ - migrations.RunPython(add_robot_user), - ] diff --git a/ligoauth/migrations/0003_initial_localuser_and_x509cert_data.py b/ligoauth/migrations/0003_initial_localuser_and_x509cert_data.py new file mode 100644 index 0000000000000000000000000000000000000000..3df08c76307f6970fb4ffb5fd118ced81df58be6 --- /dev/null +++ b/ligoauth/migrations/0003_initial_localuser_and_x509cert_data.py @@ -0,0 +1,394 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.5 on 2017-10-27 14:39 +from __future__ import unicode_literals + +from django.db import migrations +from django.conf import settings + +# List of robot user account information and their corresponding +# x509 certificate subjects. Based on current production database +# content (27 Oct 2017) +LOCALUSERS = [ + { + 'username': 'bayestar-mic', + 'last_name': 'BAYESTAR O3 Preview', + 'email': 'leo.singer@ligo.org', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=Online_CBC_BAYESTAR_O3_Preview/node746.cluster.ldas.cit' + ], + }, + { + 'username': 'bayeswave', + 'last_name': 'BayesWave at CIT', + 'email': 'margaret.millhouse@montana.edu', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=bw_online/ldas-grid.ligo.caltech.edu', + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=bayeswave/ldas-grid.ligo.caltech.edu' + ], + }, + { + 'username': 'bwb_online', + 'last_name': 'BWB Online at CIT', + 'email': 'meg.millhouse@ligo.org', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=bwb_online/ldas-grid.ligo.caltech.edu' + ], + }, + { + 'username': 'cds_lho', + 'last_name': 'CDS at LHO', + 'email': 'barker@ligo-wa.caltech.edu', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=h1fescript0/cds.ligo-wa.caltech.edu' + ], + }, + { + 'username': 'cds_llo', + 'last_name': 'CDS at LLO', + 'email': 'kthorne@ligo-la.caltech.edu', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=exttrig/cds-outbound.ligo-la.caltech.edu' + ], + }, + { + 'username': 'detchar', + 'last_name': 'Detchar', + 'email': 'pankow@gravity.phys.uwm.edu', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=detchar/dcs.ligo-wa.caltech.edu', + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=detchar/detchar.ligo.caltech.edu', + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=detchar/ldas-pcdev1.ligo-la.caltech.edu' + ], + }, + { + 'username': 'excesspower-processor ', + 'last_name': 'Excess Power Processor', + 'email': 'pankow@gravity.phys.uwm.edu', + 'x509certs': [ + '/DC=org/DC=doegrids/OU=Services/CN=excesspower-processor/marlin.phys.uwm.edu' + ], + }, + { + 'username': 'exttrig', + 'last_name': 'exttrig', + 'email': 'kthorne@ligo-la.caltech.edu', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=exttrig/cds-output.ligo-la.caltech.edu' + ], + }, + { + 'username': 'gcn_circulars', + 'last_name': 'GCN Circulars', + 'email': 'roy.williams@ligo.org', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=gcncirculars/embb-dev.ligo.caltech.edu' + ], + }, + { + 'username': 'gcn_sender', + 'last_name': 'GCN Sender', + 'email': 'branson@gravity.phys.uwm.edu', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=approvalbot/curly.phys.uwm.edu', + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=gcn_sender/gracedb.phys.uwm.edu', + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=gcn_sender/archie.phys.uwm.edu' + ], + }, + { + 'username': 'gdb-processor', + 'last_name': 'GDB Processor', + 'email': 'gdb_processor@gravity.phys.uwm.edu ', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=gdb_processor/pcdev2.phys.uwm.edu', + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=gdb-processor/marlin.phys.uwm.edu' + ], + }, + { + 'username': 'gdb_pe', + 'last_name': 'GDB PE', + 'email': 'vivien@caltech.edu', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=gdb_pe/ldas-pcdev1.ligo.caltech.edu' + ], + }, + { + 'username': 'gis', + 'last_name': 'GIS', + 'email': 'xavier.amador@ligo.org', + 'x509certs': [ + '/DC=org/DC=doegrids/OU=Services/CN=gis/lscgis.phys.uwm.edu' + ], + }, + { + 'username': 'gracedb.processor', + 'last_name': 'GraceDB Processor', + 'email': 'alexander.urban@ligo.org', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=gracedb.processor/ldas-grid.ligo.caltech.edu', + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=gracedb.processor/emfollow.ligo.caltech.edu' + ], + }, + { + 'username': 'grb.exttrig', + 'last_name': 'GRB ExtTrig', + 'email': 'talukder@uoregon.edu', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=grb.exttrig/ldas-pcdev1.ligo.caltech.edu' + ], + }, + { + 'username': 'GRD_INJ', + 'last_name': 'GRD Injection', + 'email': 'cmbiwer@syr.edu', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=GRD_INJ/h1guardian0.cds.ligo-wa.caltech.edu' + ], + }, + { + 'username': 'gstinjector', + 'last_name': 'gstinjector', + 'email': 'laleh.sadeghian@ligo.org', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=gstinjector/soapbox.cgca.uwm.edu', + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=gstinjector/ldas-pcdev13.ligo.caltech.edu', + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=gstinjector/peloton.cgca.uwm.edu' + ], + }, + { + 'username': 'gstlal-spiir', + 'last_name': 'GSTLAL SPIIR Analysis', + 'email': 'qi.chu@ligo.org', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=gstlal-spiir/ldas-pcdev1.ligo.caltech.edu' + ], + }, + { + 'username': 'gstlal-spiir-gpu', + 'last_name': 'GSTLAL SPIIR GPU Analysis ', + 'email': 'qi.chu@ligo.org', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=gstlal-spiir-gpu/ldas-pcdev1.ligo.caltech.edu' + ], + }, + { + 'username': 'gstlalbbh', + 'last_name': 'GstlalBBH at CIT', + 'email': 'kent@ligo.caltech.edu', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=gstlalbbh/ldas-grid.ligo.caltech.edu' + ], + }, + { + 'username': 'gstlalcbc', + 'last_name': 'GstLal CBC', + 'email': 'chad.r.hanna@gmail.com', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=gstlalcbc/pcdev3.phys.uwm.edu', + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=gstlalcbc/cbc.ligo.caltech.edu', + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=gstlalcbc/ldas-pcdev1.ligo.caltech.edu' + ], + }, + { + 'username': 'gstlalcbcbbh', + 'last_name': 'gstlal BBH', + 'email': 'laleh.sadeghian@ligo.org', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=gstlalcbcbbh/pcdev3.phys.uwm.edu' + ], + }, + { + 'username': 'hinj', + 'last_name': 'HWINJ Monitor', + 'email': 'mhulko@caltech.edu', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=hinj/ldas-grid.ligo.caltech.edu' + ], + }, + { + 'username': 'idq-la', + 'last_name': 'iDQ at LLO', + 'email': 'ressick@mit.edu', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=idqLLO/ldas-grid.ligo-la.caltech.edu' + ], + }, + { + 'username': 'idq-wa', + 'last_name': 'iDQ at LHO', + 'email': 'ressick@mit.edu', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=idqLHO/ldas-grid.ligo-wa.caltech.edu' + ], + }, + { + 'username': 'LIB_PE', + 'last_name': 'LIB PE at CIT', + 'email': 'salvatore.vitale@ligo.mit.edu', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=LIB/ldas-pcdev5.ligo.caltech.edu' + ], + }, + { + 'username': 'losc_summary', + 'last_name': 'LOSC Summary', + 'email': 'tmassing@ligo.caltech.edu', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=publicsummary/losc-data.ligo.caltech.edu' + ], + }, + { + 'username': 'lumin', + 'last_name': 'LUMIN', + 'email': 'bmoe@gravity.phys.uwm.edu', + 'x509certs': [ + '/DC=org/DC=doegrids/OU=Services/CN=luminrobot/ldas-pcdev1.ligo.caltech.edu' + ], + }, + { + 'username': 'MbtaAlert', + 'last_name': 'MBTA Alert', + 'email': 'mours@lapp.in2p3.fr', + 'x509certs': [ + '/C=IT/O=INFN/OU=Service/L=EGO/CN=MbtaAlert/olnode33.virgo.infn.it', + '/C=IT/O=INFN/OU=Service/L=EGO/CN=MbtaAlert/olserver54.virgo.infn.it', + '/C=IT/O=INFN/OU=Service/L=EGO/CN=MbtaAlert/lscgw.virgo.infn.it', + '/C=IT/O=INFN/OU=Service/L=EGO/CN=MbtaAlert/olnode04.virgo.infn.it' + ], + }, + { + 'username': 'nagios', + 'last_name': 'Nagios Monitor', + 'email': 'admins@phys.uwm.edu', + 'x509certs': [ + '/DC=org/DC=doegrids/OU=Services/CN=nagios/sentry.phys.uwm.edu', + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=nagios/sentry.phys.uwm.edu', + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=nagios/gracedb.cgca.uwm.edu', + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=nagios/dashboard.cgca.uwm.edu' + ], + }, + { + 'username': 'oLIB', + 'last_name': 'oLIB at CIT', + 'email': 'rlynch@mit.edu', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=oLIB/ldas-grid.ligo.caltech.edu' + ], + }, + { + 'username': 'omega', + 'last_name': 'Omega Analysis', + 'email': '', + 'x509certs': [ + '/DC=org/DC=doegrids/OU=Services/CN=omegarobot/node499.ldas-cit.ligo.caltech.edu' + ], + }, + { + 'username': 'pankow', + 'last_name': 'Pankow Robot', + 'email': 'pankow@gravity.phys.uwm.edu', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=pankow/pcdev2.cgca.uwm.edu' + ], + }, + { + 'username': 'pycbclive', + 'last_name': 'PyCBC Live', + 'email': 'alex.nitz@aei.mpg.de', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=pycbclive/pycbclive.atlas.aei.uni-hannover.de' + ], + }, + { + 'username': 'skymap_viewer', + 'last_name': 'SkymapViewer', + 'email': 'roy.williams@ligo.org', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=SkymapViewer/losc-data.ligo.caltech.edu' + ], + }, + { + 'username': 'TIGER', + 'last_name': 'TIGER at CIT', + 'email': 'salvatore.vitale@ligo.org', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=TIGER/ldas-pcdev1.ligo.caltech.edu' + ], + }, + { + 'username': 'virgo_detchar', + 'last_name': 'Virgo Detchar', + 'email': 'leroy@lal.in2p3.fr', + 'x509certs': [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=Virgodetchar/lscgw.virgo.infn.it' + ], + }, + { + 'username': 'waveburst', + 'last_name': 'Cwb Analysis', + 'email': 'bmoe@gravity.phys.uwm.edu', + 'x509certs': [ + '/DC=org/DC=doegrids/OU=Services/CN=waveburst/ldas-pcdev1.ligo.caltech.edu', + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=waveburst/ldas-pcdev1.ligo-wa.caltech.edu', + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=waveburst/ldas-pcdev1.ligo-la.caltech.edu', + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=waveburst/ldas-grid.ligo-wa.caltech.edu', + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=waveburst/ldas-grid.ligo-la.caltech.edu', + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=waveburst/ldas-grid.ligo.caltech.edu', + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=waveburst/ldas-pcdev1.ligo.caltech.edu', + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=waveburst-atlas/atlas9.atlas.aei.uni-hannover.de' + ], + }, +] + +def add_localusers_and_x509certs(apps, schema_editor): + LocalUser = apps.get_model('ligoauth', 'LocalUser') + X509Cert = apps.get_model('ligoauth', 'X509Cert') + Group = apps.get_model('auth', 'Group') + + # Create user accounts + lvc_group = Group.objects.get(name=settings.LVC_GROUP) + for l_dict in LOCALUSERS: + localuser, created = LocalUser.objects.get_or_create(username=l_dict['username']) + localuser.last_name = l_dict['last_name'] + localuser.email = l_dict['last_name'] + localuser.save() + + # Add user to LSC group + lvc_group.user_set.add(localuser) + + # Create corresponding X509 certificates + for subject in l_dict['x509certs']: + cert, c_created = X509Cert.objects.get_or_create(subject=subject) + cert.users.add(localuser) + +def remove_localusers_and_x509certs(apps, schema_editor): + LocalUser = apps.get_model('ligoauth', 'LocalUser') + X509Cert = apps.get_model('ligoauth', 'X509Cert') + + for l_dict in LOCALUSERS: + try: + localuser = LocalUser.objects.get(username=l_dict['username']) + except LocalUser.DoesNotExist: + print('LocalUser {0} not found to be deleted, skipping' \ + .format(l_dict['username'])) + for subject in l_dict['x509certs']: + try: + cert = X509Cert.objects.get(subject=subject) + except X509Cert.DoesNotExist: + print(('X509Cert with subject {0}, corresponding to user {1} ' + 'not found to be deleted, skipping').format(subject, + l_dict['username'])) + cert.delete() + localuser.delete() + +class Migration(migrations.Migration): + + dependencies = [ + ('auth', '0010_initial_group_data'), + ('ligoauth', '0002_set_ligoauth_ligoldapuser_charset'), + ] + + operations = [ + migrations.RunPython(add_localusers_and_x509certs, + remove_localusers_and_x509certs), + ] + diff --git a/ligoauth/migrations/0004_add_grdinj.py b/ligoauth/migrations/0004_add_grdinj.py deleted file mode 100644 index f3cc6032010188c3a9326f47fb9401263f8ed245..0000000000000000000000000000000000000000 --- a/ligoauth/migrations/0004_add_grdinj.py +++ /dev/null @@ -1,67 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations, models -from django.conf import settings - -ROBOTS = [ - { - 'username' : 'GRDINJ', - 'first_name' : '', - 'last_name' : 'GRDINJ', # Note that the last_name acts as a display - 'email' : 'cmbiwer@syr.edu', - 'dns' : [ - "/DC=org/DC=ligo/O=LIGO/OU=Services/CN=GRD_INJ/h1guardian0.cds.ligo-wa.caltech.edu", - ] - }, -] - -def create_robots(apps, schema_editor): - LocalUser = apps.get_model('ligoauth', 'LocalUser') - X509Cert = apps.get_model('ligoauth', 'X509Cert') - Group = apps.get_model('auth', 'Group') - lvc_group = Group.objects.get(name=settings.LVC_GROUP) - - for entry in ROBOTS: - user, created = LocalUser.objects.get_or_create(username=entry['username']) - if created: - user.first_name = entry['first_name'] - user.last_name = entry['last_name'] - user.email = entry['email'] - user.is_active = True - user.is_staff = False - user.is_superuser = False - user.save() - - # Create the cert objects and link them to our user. - for dn in entry['dns']: - cert, created = X509Cert.objects.get_or_create(subject=dn) - if created: - cert.save() - cert.users.add(user) - - # Add our user to the LVC group. This permission is required to - # do most things, but may *NOT* always be appropriate. It may - # also be necessary to give the robotic user permission to populate - # a particular pipeline. - lvc_group.user_set.add(user) - -def delete_robots(apps, schema_editor): - LocalUser = apps.get_model('ligoauth', 'LocalUser') - X509Cert = apps.get_model('ligoauth', 'X509Cert') - - for entry in ROBOTS: - for dn in entry['dns']: - X509Cert.objects.get(subject=dn).delete() - LocalUser.objects.get(username=entry['username']).delete() - - -class Migration(migrations.Migration): - - dependencies = [ - ('ligoauth', '0003_auto_20150819_1201'), - ] - - operations = [ - migrations.RunPython(create_robots) - ] diff --git a/ligoauth/migrations/0005_add_robot_grdinj.py b/ligoauth/migrations/0005_add_robot_grdinj.py deleted file mode 100644 index 6e4b4af433f73f5fd81dd6b11d45c97cdaf0849c..0000000000000000000000000000000000000000 --- a/ligoauth/migrations/0005_add_robot_grdinj.py +++ /dev/null @@ -1,69 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations, models -from django.conf import settings - -ROBOTS = [ - { - 'username' : 'GRD_INJ', - 'first_name' : '', - 'last_name' : 'GRD Injection', # Note that the last_name acts as a display - 'email' : 'cmbiwer@syr.edu', - 'dns' : [ - "/DC=org/DC=ligo/O=LIGO/OU=Services/CN=GRD_INJ/h1guardian0.cds.ligo-wa.caltech.edu", - ] - }, -] - -def create_robots(apps, schema_editor): - LocalUser = apps.get_model('ligoauth', 'LocalUser') - X509Cert = apps.get_model('ligoauth', 'X509Cert') - Group = apps.get_model('auth', 'Group') - lvc_group = Group.objects.get(name=settings.LVC_GROUP) - - for entry in ROBOTS: - user, created = LocalUser.objects.get_or_create(username=entry['username']) - if created: - user.first_name = entry['first_name'] - user.last_name = entry['last_name'] - user.email = entry['email'] - user.is_active = True - user.is_staff = False - user.is_superuser = False - user.save() - - # Create the cert objects and link them to our user. - for dn in entry['dns']: - cert, created = X509Cert.objects.get_or_create(subject=dn) - if created: - cert.save() - cert.users.add(user) - - # Add our user to the LVC group. This permission is required to - # do most things, but may *NOT* always be appropriate. It may - # also be necessary to give the robotic user permission to populate - # a particular pipeline. - lvc_group.user_set.add(user) - print "Added User GRD_INJ" - -def delete_robots(apps, schema_editor): - LocalUser = apps.get_model('ligoauth', 'LocalUser') - X509Cert = apps.get_model('ligoauth', 'X509Cert') - - for entry in ROBOTS: - for dn in entry['dns']: - X509Cert.objects.get(subject=dn).delete() - LocalUser.objects.get(username=entry['username']).delete() - - - -class Migration(migrations.Migration): - - dependencies = [ - ('ligoauth', '0004_add_grdinj'), - ] - - operations = [ - migrations.RunPython(create_robots) - ] diff --git a/ligoauth/migrations/0006_readd_gstlalcbc_test.py b/ligoauth/migrations/0006_readd_gstlalcbc_test.py deleted file mode 100644 index 6e36f12d753ecfeb37b4178e0e060588266af7a3..0000000000000000000000000000000000000000 --- a/ligoauth/migrations/0006_readd_gstlalcbc_test.py +++ /dev/null @@ -1,69 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations, models -from django.conf import settings - - -ROBOTS = [ - { - 'username' : 'gstlalcbc', - 'first_name' : '', - 'last_name' : 'gstlalcbc', # Note that the last_name acts as a display - 'email' : 'crh184@psu.edu', - 'dns' : [ - "/DC=org/DC=ligo/O=LIGO/OU=Services/CN=gstlalcbc/cbc.ligo.caltech.edu", - ] - }, -] - -def create_robots(apps, schema_editor): - LocalUser = apps.get_model('ligoauth', 'LocalUser') - X509Cert = apps.get_model('ligoauth', 'X509Cert') - Group = apps.get_model('auth', 'Group') - lvc_group = Group.objects.get(name=settings.LVC_GROUP) - - for entry in ROBOTS: - user, created = LocalUser.objects.get_or_create(username=entry['username']) - if created: - user.first_name = entry['first_name'] - user.last_name = entry['last_name'] - user.email = entry['email'] - user.is_active = True - user.is_staff = False - user.is_superuser = False - user.save() - - # Create the cert objects and link them to our user. - for dn in entry['dns']: - cert, created = X509Cert.objects.get_or_create(subject=dn) - if created: - cert.save() - cert.users.add(user) - - # Add our user to the LVC group. This permission is required to - # do most things, but may *NOT* always be appropriate. It may - # also be necessary to give the robotic user permission to populate - # a particular pipeline. - lvc_group.user_set.add(user) - print "Added User gstlalcbc!" - -def delete_robots(apps, schema_editor): - LocalUser = apps.get_model('ligoauth', 'LocalUser') - X509Cert = apps.get_model('ligoauth', 'X509Cert') - - for entry in ROBOTS: - for dn in entry['dns']: - X509Cert.objects.get(subject=dn).delete() - LocalUser.objects.get(username=entry['username']).delete() - -class Migration(migrations.Migration): - - dependencies = [ - ('ligoauth', '0005_add_robot_grdinj'), - ] - - - operations = [ - migrations.RunPython(create_robots) - ] diff --git a/ligoauth/migrations/0007_add_pycbclive_robot.py b/ligoauth/migrations/0007_add_pycbclive_robot.py deleted file mode 100644 index 91389fd9f4a6b83b23dd461a46bbe21086ba4fb1..0000000000000000000000000000000000000000 --- a/ligoauth/migrations/0007_add_pycbclive_robot.py +++ /dev/null @@ -1,70 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations, models -from django.conf import settings - -ROBOTS = [ - { - 'username' : 'pycbclive', - 'first_name' : '', - 'last_name' : 'PyCBC Live', # Note that the last_name acts as a display - 'email' : 'alex.nitz@aei.mpg.de', - 'dns' : [ - "/DC=org/DC=ligo/O=LIGO/OU=Services/CN=pycbclive/pycbclive.atlas.aei.uni-hannover.de", - ] - }, -] - - -def create_robots(apps, schema_editor): - LocalUser = apps.get_model('ligoauth', 'LocalUser') - X509Cert = apps.get_model('ligoauth', 'X509Cert') - Group = apps.get_model('auth', 'Group') - lvc_group = Group.objects.get(name=settings.LVC_GROUP) - - for entry in ROBOTS: - user, created = LocalUser.objects.get_or_create(username=entry['username']) - if created: - user.first_name = entry['first_name'] - user.last_name = entry['last_name'] - user.email = entry['email'] - user.is_active = True - user.is_staff = False - user.is_superuser = False - user.save() - - # Create the cert objects and link them to our user. - for dn in entry['dns']: - cert, created = X509Cert.objects.get_or_create(subject=dn) - if created: - cert.save() - cert.users.add(user) - - # Add our user to the LVC group. This permission is required to - # do most things, but may *NOT* always be appropriate. It may - # also be necessary to give the robotic user permission to populate - # a particular pipeline. - lvc_group.user_set.add(user) - - -def delete_robots(apps, schema_editor): - LocalUser = apps.get_model('ligoauth', 'LocalUser') - X509Cert = apps.get_model('ligoauth', 'X509Cert') - - for entry in ROBOTS: - for dn in entry['dns']: - X509Cert.objects.get(subject=dn).delete() - LocalUser.objects.get(username=entry['username']).delete() - - - -class Migration(migrations.Migration): - - dependencies = [ - ('ligoauth', '0006_readd_gstlalcbc_test'), - ] - - operations = [ - migrations.RunPython(create_robots), - ] diff --git a/ligoauth/migrations/0008_add_exttrig.py b/ligoauth/migrations/0008_add_exttrig.py deleted file mode 100644 index f225d57442c5c46f626ded209e2228c4eef24520..0000000000000000000000000000000000000000 --- a/ligoauth/migrations/0008_add_exttrig.py +++ /dev/null @@ -1,68 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations, models -from django.conf import settings - -ROBOTS = [ - { - 'username' : 'exttrig', - 'first_name' : '', - 'last_name' : 'exttrig', # Note that the last_name acts as a display - 'email' : 'kthorne@ligo-la.caltech.edu', - 'dns' : [ - "/DC=org/DC=ligo/O=LIGO/OU=Services/CN=exttrig/cds-output.ligo-la.caltech.edu", - ] - }, -] - - -def create_robots(apps, schema_editor): - LocalUser = apps.get_model('ligoauth', 'LocalUser') - X509Cert = apps.get_model('ligoauth', 'X509Cert') - Group = apps.get_model('auth', 'Group') - lvc_group = Group.objects.get(name=settings.LVC_GROUP) - - for entry in ROBOTS: - user, created = LocalUser.objects.get_or_create(username=entry['username']) - if created: - user.first_name = entry['first_name'] - user.last_name = entry['last_name'] - user.email = entry['email'] - user.is_active = True - user.is_staff = False - user.is_superuser = False - user.save() - - # Create the cert objects and link them to our user. - for dn in entry['dns']: - cert, created = X509Cert.objects.get_or_create(subject=dn) - if created: - cert.save() - cert.users.add(user) - - # Add our user to the LVC group. This permission is required to - # do most things, but may *NOT* always be appropriate. It may - # also be necessary to give the robotic user permission to populate - # a particular pipeline. - lvc_group.user_set.add(user) - - -def delete_robots(apps, schema_editor): - LocalUser = apps.get_model('ligoauth', 'LocalUser') - X509Cert = apps.get_model('ligoauth', 'X509Cert') - - for entry in ROBOTS: - for dn in entry['dns']: - X509Cert.objects.get(subject=dn).delete() - LocalUser.objects.get(username=entry['username']).delete() - -class Migration(migrations.Migration): - - dependencies = [ - ('ligoauth', '0007_add_pycbclive_robot'), - ] - - operations = [ - migrations.RunPython(create_robots), - ] diff --git a/ligoauth/migrations/0009_add_pankow_robot_and_cert.py b/ligoauth/migrations/0009_add_pankow_robot_and_cert.py deleted file mode 100644 index 2ba09135460342ab7aa2ba8723caaf66b28073ee..0000000000000000000000000000000000000000 --- a/ligoauth/migrations/0009_add_pankow_robot_and_cert.py +++ /dev/null @@ -1,59 +0,0 @@ -# -*- coding: utf-8 -*- -# Default imports -from __future__ import unicode_literals -from django.db import migrations, models -from django.conf import settings - -ROBOT = {'username': 'pankow', - 'first_name': '', - 'last_name': 'Pankow Robot', - 'email': 'pankow@gravity.phys.uwm.edu', - 'is_active': True, - 'is_staff': False, - 'is_superuser': False -} -CERT_SUBJ = '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=pankow/pcdev2.cgca.uwm.edu' - -def create_robot(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - Group = apps.get_model('auth','Group') - lvc_group = Group.objects.get(name=settings.LVC_GROUP) - - # get or create user - user, created = LocalUser.objects.get_or_create(username=ROBOT['username']) - if created: - for key in ROBOT.keys(): - setattr(user, key, ROBOT[key]) - user.save() - - # Add user to LVC group. - lvc_group.user_set.add(user) - lvc_group.save() - - # get or create certificate, add user - cert, c_created = X509Cert.objects.get_or_create(subject=CERT_SUBJ) - cert.users.add(user) - cert.save() - -def delete_robot(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - - # Delete user. - LocalUser.objects.get(username=ROBOT['username']).delete() - - # Delete cert. - X509Cert.objects.get(subject=CERT_SUBJ).delete() - -class Migration(migrations.Migration): - - dependencies = [ - ('ligoauth', '0008_add_exttrig'), - ] - - operations = [ - migrations.RunPython(create_robot, delete_robot) - ] - -# End of file diff --git a/ligoauth/migrations/0010_add_nagios_gracedb_robot_and_cert.py b/ligoauth/migrations/0010_add_nagios_gracedb_robot_and_cert.py deleted file mode 100644 index 7f0873bcfb223b04db57d8faab956e87a67e2d4a..0000000000000000000000000000000000000000 --- a/ligoauth/migrations/0010_add_nagios_gracedb_robot_and_cert.py +++ /dev/null @@ -1,61 +0,0 @@ -# -*- coding: utf-8 -*- -# Default imports -from __future__ import unicode_literals -from django.db import migrations, models -from django.conf import settings - -ROBOT = {'username': 'nagios', - 'first_name': '', - 'last_name': 'Nagios Monitor', - 'email': 'admins@phys.uwm.edu', - 'is_active': True, - 'is_staff': False, - 'is_superuser': False -} -# Certificate for nagios user on gracedb. -CERT_SUBJ = '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=nagios/gracedb.cgca.uwm.edu' - -def create_robot(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - Group = apps.get_model('auth','Group') - lvc_group = Group.objects.get(name=settings.LVC_GROUP) - - # get or create user - user, created = LocalUser.objects.get_or_create(username=ROBOT['username']) - if created: - for key in ROBOT.keys(): - setattr(user, key, ROBOT[key]) - user.save() - - # Add user to LVC group. - if not lvc_group in user.groups.all(): - lvc_group.user_set.add(user) - lvc_group.save() - - # get or create certificate, add user - cert, c_created = X509Cert.objects.get_or_create(subject=CERT_SUBJ) - cert.users.add(user) - cert.save() - -def delete_robot(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - - # Delete user. - LocalUser.objects.get(username=ROBOT['username']).delete() - - # Delete cert. - X509Cert.objects.get(subject=CERT_SUBJ).delete() - -class Migration(migrations.Migration): - - dependencies = [ - ('ligoauth', '0009_add_pankow_robot_and_cert'), - ] - - operations = [ - migrations.RunPython(create_robot, delete_robot) - ] - -# End of file diff --git a/ligoauth/migrations/0011_add_O2_hwinj_logger_account.py b/ligoauth/migrations/0011_add_O2_hwinj_logger_account.py deleted file mode 100644 index 0f406ad444bb7b13cc79902b45b54fab4b5bdb12..0000000000000000000000000000000000000000 --- a/ligoauth/migrations/0011_add_O2_hwinj_logger_account.py +++ /dev/null @@ -1,91 +0,0 @@ -# -*- coding: utf-8 -*- -# Default imports -from __future__ import unicode_literals -from django.db import migrations, models -from django.conf import settings - -ROBOT = {'username': 'hinj', - 'first_name': '', - 'last_name': 'HWINJ Monitor', - 'email': 'mhulko@caltech.edu', - 'is_active': True, - 'is_staff': False, - 'is_superuser': False -} - -# Certificate for nagios user on gracedb. -CERT_SUBJ = '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=hinj/ldas-grid.ligo.caltech.edu' - -def create_robot(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - Group = apps.get_model('auth','Group') - Permission = apps.get_model('auth','Permission') - Pipeline = apps.get_model('gracedb','Pipeline') - UserObjectPermission = apps.get_model('guardian','UserObjectPermission') - ContentType = apps.get_model('contenttypes','ContentType') - - lvc_group = Group.objects.get(name=settings.LVC_GROUP) - add_event_perm = Permission.objects.get(codename='add_event') - - # get or create user - user, created = LocalUser.objects.get_or_create(username=ROBOT['username']) - if created: - for key in ROBOT.keys(): - setattr(user, key, ROBOT[key]) - - # Give user permission to add events - if add_event_perm not in user.user_permissions.all(): - user.user_permissions.add(add_event_perm) - - # Set up ability for user to populate for HardwareInjection pipeline. - p = Permission.objects.get(codename='populate_pipeline') - ctype = ContentType.objects.get(app_label='gracedb', model='pipeline') - hwinj_pipeline = Pipeline.objects.get(name='HardwareInjection') - - # Create UserObjectPermission - UserObjectPermission.objects.create(user=user, permission=p, - content_type=ctype, object_pk=hwinj_pipeline.id) - - # Save user - user.save() - - # Add user to LVC group. - if not lvc_group in user.groups.all(): - lvc_group.user_set.add(user) - lvc_group.save() - - # get or create certificate, add user - cert, c_created = X509Cert.objects.get_or_create(subject=CERT_SUBJ) - cert.users.add(user) - cert.save() - -def delete_robot(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - UserObjectPermission = apps.get_model('guardian','UserObjectPermission') - - # Get user - user = LocalUser.objects.get(username=ROBOT['username']) - - # Delete UserObjectPermission objects. - for uop in user.userobjectpermission_set.all(): - uop.delete() - - # Delete user. - user.delete() - - # Delete cert. - X509Cert.objects.get(subject=CERT_SUBJ).delete() - -class Migration(migrations.Migration): - - dependencies = [ - ('ligoauth', '0010_add_nagios_gracedb_robot_and_cert'), - ] - - operations = [ - migrations.RunPython(create_robot, delete_robot) - ] - -# End of file diff --git a/ligoauth/migrations/0012_update_iDQ_robot.py b/ligoauth/migrations/0012_update_iDQ_robot.py deleted file mode 100644 index f4d71b25a16605fe8a78fd3789f96b5a629fe73f..0000000000000000000000000000000000000000 --- a/ligoauth/migrations/0012_update_iDQ_robot.py +++ /dev/null @@ -1,82 +0,0 @@ -# -*- coding: utf-8 -*- -# Default imports -from __future__ import unicode_literals -from django.db import migrations, models -from django.conf import settings - -ROBOTS = [{'username': 'idq-la', - 'newcert': '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=idqLLO/ldas-grid.ligo-la.caltech.edu', - 'oldcert': [ - '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=idq/ldas-pcdev1.ligo-la.caltech.edu', - '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=idq/ldas-pcdev2.ligo-la.caltech.edu' - ], - 'newemail': 'ressick@mit.edu', - 'oldemail': 'rvaulin@mit.edu', - }, - {'username': 'idq-wa', - 'newcert': '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=idqLHO/ldas-grid.ligo-wa.caltech.edu', - 'oldcert': [ - '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=idq/ldas-pcdev1.ligo-wa.caltech.edu', - '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=idq/ldas-pcdev2.ligo-wa.caltech.edu' - ], - 'newemail': 'ressick@mit.edu', - 'oldemail': 'rvaulin@mit.edu', - }, -] - -def create_robots(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - Group = apps.get_model('auth','Group') - lvc_group = Group.objects.get(name=settings.LVC_GROUP) - - # Get/create new user, get/create new cert, associate user with cert. - for entry in ROBOTS: - # get user - user = LocalUser.objects.get(username=entry['username']) - user.email = entry['newemail'] - user.save() - - # get or create certificate, add user - cert, c_created = X509Cert.objects.get_or_create(subject=entry['newcert']) - cert.users.add(user) - cert.save() - - # Delete old certs. - for oldcert in entry['oldcert']: - try: - cert = X509Cert.objects.get(subject=oldcert) - cert.delete() - except: - pass - -def delete_robots(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - - # Delete users. - for entry in ROBOTS: - user = LocalUser.objects.get(username=entry['username']) - user.email = entry['oldemail'] - user.save() - - # Create oldcerts, add to user - for oldcert in entry['oldcert']: - cert, created = X509Cert.objects.get_or_create(subject=oldcert) - cert.users.add(user) - cert.save() - - # Delete newcert. - X509Cert.objects.get(subject=entry['newcert']).delete() - -class Migration(migrations.Migration): - - dependencies = [ - ('ligoauth', '0011_add_O2_hwinj_logger_account'), - ] - - operations = [ - migrations.RunPython(create_robots, delete_robots) - ] - -# End of file diff --git a/ligoauth/migrations/0013_update_bayeswave_robot.py b/ligoauth/migrations/0013_update_bayeswave_robot.py deleted file mode 100644 index fd6875229fc784fbd5faf49fbe8c7e859e7cf5a2..0000000000000000000000000000000000000000 --- a/ligoauth/migrations/0013_update_bayeswave_robot.py +++ /dev/null @@ -1,69 +0,0 @@ -# -*- coding: utf-8 -*- -# Default imports -from __future__ import unicode_literals -from django.db import migrations, models -from django.conf import settings - -ROBOTS = [{'username': 'bayeswave', - 'newcert': '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=bayeswave_online/ldas-grid.ligo.caltech.edu', - 'oldcert': '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=bayeswave/ldas-grid.ligo.caltech.edu', - 'newemail': 'margaret.millhouse@montana.edu', - 'oldemail': 'jkanner@caltech.edu', - }, -] - -def create_robots(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - - # Get/create new user, get/create new cert, associate user with cert. - for entry in ROBOTS: - # get user - user = LocalUser.objects.get(username=entry['username']) - user.email = entry['newemail'] - user.save() - - # get or create certificate, add user - cert, c_created = X509Cert.objects.get_or_create(subject=entry['newcert']) - cert.users.add(user) - cert.save() - - # Delete old certs. - try: - cert = X509Cert.objects.get(subject=entry['oldcert']) - cert.delete() - except: - pass - -def delete_robots(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - - # Delete users. - for entry in ROBOTS: - user = LocalUser.objects.get(username=entry['username']) - user.email = entry['oldemail'] - user.save() - - # Create oldcerts, add to user - cert, created = X509Cert.objects.get_or_create(subject=entry['oldcert']) - cert.users.add(user) - cert.save() - - # Delete newcert. - try: - X509Cert.objects.get(subject=entry['newcert']).delete() - except: - pass - -class Migration(migrations.Migration): - - dependencies = [ - ('ligoauth', '0012_update_iDQ_robot'), - ] - - operations = [ - migrations.RunPython(create_robots, delete_robots) - ] - -# End of file diff --git a/ligoauth/migrations/0014_update_lib_robot.py b/ligoauth/migrations/0014_update_lib_robot.py deleted file mode 100644 index c05298c39fce36b3daacda4aeaeaf28ef9ebd96a..0000000000000000000000000000000000000000 --- a/ligoauth/migrations/0014_update_lib_robot.py +++ /dev/null @@ -1,65 +0,0 @@ -# -*- coding: utf-8 -*- -# Default imports -from __future__ import unicode_literals -from django.db import migrations, models -from django.conf import settings - -ROBOTS = [{'username': 'LIB', - 'newcert': '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=LIB/ldas-pcdev5.ligo.caltech.edu', - 'oldcert': '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=LIB/ldas-pcdev1.ligo.caltech.edu' - }, -] - -def create_robots(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - - # Get/create new user, get/create new cert, associate user with cert. - for entry in ROBOTS: - # get user - user = LocalUser.objects.get(username=entry['username']) - user.save() - - # get or create certificate, add user - cert, c_created = X509Cert.objects.get_or_create(subject=entry['newcert']) - cert.users.add(user) - cert.save() - - # Delete old certs. - try: - cert = X509Cert.objects.get(subject=entry['oldcert']) - cert.delete() - except: - pass - -def delete_robots(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - - # Delete users. - for entry in ROBOTS: - user = LocalUser.objects.get(username=entry['username']) - user.save() - - # Create oldcerts, add to user - cert, created = X509Cert.objects.get_or_create(subject=entry['oldcert']) - cert.users.add(user) - cert.save() - - # Delete newcert. - try: - X509Cert.objects.get(subject=entry['newcert']).delete() - except: - pass - -class Migration(migrations.Migration): - - dependencies = [ - ('ligoauth', '0013_update_bayeswave_robot'), - ] - - operations = [ - migrations.RunPython(create_robots, delete_robots) - ] - -# End of file diff --git a/ligoauth/migrations/0015_update_bayestar_robot.py b/ligoauth/migrations/0015_update_bayestar_robot.py deleted file mode 100644 index ff3765c7db4193de6d034a60f6d6d6cc9a63e74a..0000000000000000000000000000000000000000 --- a/ligoauth/migrations/0015_update_bayestar_robot.py +++ /dev/null @@ -1,73 +0,0 @@ -# -*- coding: utf-8 -*- -# Default imports -from __future__ import unicode_literals -from django.db import migrations, models -from django.conf import settings - -ROBOTS = [{'username': 'bayestar-mic', - 'old_lastname': 'BAYESTAR MIC', - 'new_lastname': 'BAYESTAR O3 Preview', - 'newcert': '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=Online_CBC_BAYESTAR_O3_Preview/node746.cluster.ldas.cit', - 'oldcert': '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=bayestar-mic/node529.cluster.ldas.cit', - 'newemail': 'leo.singer@ligo.org', - 'oldemail': 'lsinger@caltech.edu', - }, -] - -def create_robots(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - - # Get/create new user, get/create new cert, associate user with cert. - for entry in ROBOTS: - # get user, update email - user = LocalUser.objects.get(username=entry['username']) - user.email = entry['newemail'] - user.last_name = entry['new_lastname'] - user.save() - - # get or create certificate, add user - cert, c_created = X509Cert.objects.get_or_create(subject=entry['newcert']) - cert.users.add(user) - cert.save() - - # Delete old certs. - try: - cert = X509Cert.objects.get(subject=entry['oldcert']) - cert.delete() - except: - pass - -def delete_robots(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - - for entry in ROBOTS: - # revert email - user = LocalUser.objects.get(username=entry['username']) - user.email = entry['oldemail'] - user.last_name = entry['old_lastname'] - user.save() - - # Create oldcerts, add to user - cert, created = X509Cert.objects.get_or_create(subject=entry['oldcert']) - cert.users.add(user) - cert.save() - - # Delete newcert. - try: - X509Cert.objects.get(subject=entry['newcert']).delete() - except: - pass - -class Migration(migrations.Migration): - - dependencies = [ - ('ligoauth', '0014_update_lib_robot'), - ] - - operations = [ - migrations.RunPython(create_robots, delete_robots) - ] - -# End of file diff --git a/ligoauth/migrations/0016_add_losc_account.py b/ligoauth/migrations/0016_add_losc_account.py deleted file mode 100644 index bfec17cb4f48051bdd59ccffc28cf66c87a82a0d..0000000000000000000000000000000000000000 --- a/ligoauth/migrations/0016_add_losc_account.py +++ /dev/null @@ -1,68 +0,0 @@ -# -*- coding: utf-8 -*- -# Default imports -from __future__ import unicode_literals -from django.db import migrations, models -from django.conf import settings - -ROBOT = {'username': 'losc_summary', - 'first_name': '', - 'last_name': 'LOSC Summary', - 'email': 'tmassing@ligo.caltech.edu', - 'is_active': True, - 'is_staff': False, - 'is_superuser': False -} - -# Certificate for nagios user on gracedb. -CERT_SUBJ = '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=publicsummary/losc-data.ligo.caltech.edu' - -def create_robot(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - Group = apps.get_model('auth','Group') - - lvc_group = Group.objects.get(name=settings.LVC_GROUP) - - # get or create user - user, created = LocalUser.objects.get_or_create(username=ROBOT['username']) - if created: - for key in ROBOT.keys(): - setattr(user, key, ROBOT[key]) - - # Save user - user.save() - - # Add user to LVC group. - if not lvc_group in user.groups.all(): - lvc_group.user_set.add(user) - lvc_group.save() - - # get or create certificate, add user - cert, c_created = X509Cert.objects.get_or_create(subject=CERT_SUBJ) - cert.users.add(user) - cert.save() - -def delete_robot(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - - # Get user - user = LocalUser.objects.get(username=ROBOT['username']) - - # Delete user. - user.delete() - - # Delete cert. - X509Cert.objects.get(subject=CERT_SUBJ).delete() - -class Migration(migrations.Migration): - - dependencies = [ - ('ligoauth', '0015_update_bayestar_robot'), - ] - - operations = [ - migrations.RunPython(create_robot, delete_robot) - ] - -# End of file diff --git a/ligoauth/migrations/0017_add_virgo_detchar.py b/ligoauth/migrations/0017_add_virgo_detchar.py deleted file mode 100644 index 1e70f570c57342eb97703db037c7c329c0555f5c..0000000000000000000000000000000000000000 --- a/ligoauth/migrations/0017_add_virgo_detchar.py +++ /dev/null @@ -1,68 +0,0 @@ -# -*- coding: utf-8 -*- -# Default imports -from __future__ import unicode_literals -from django.db import migrations, models -from django.conf import settings - -ROBOT = {'username': 'virgo_detchar', - 'first_name': '', - 'last_name': 'Virgo Detchar', - 'email': 'leroy@lal.in2p3.fr', - 'is_active': True, - 'is_staff': False, - 'is_superuser': False -} - -# Certificate for nagios user on gracedb. -CERT_SUBJ = '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=Virgodetchar/lscgw.virgo.infn.it' - -def create_robot(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - Group = apps.get_model('auth','Group') - - lvc_group = Group.objects.get(name=settings.LVC_GROUP) - - # get or create user - user, created = LocalUser.objects.get_or_create(username=ROBOT['username']) - if created: - for key in ROBOT.keys(): - setattr(user, key, ROBOT[key]) - - # Save user - user.save() - - # Add user to LVC group. - if not lvc_group in user.groups.all(): - lvc_group.user_set.add(user) - lvc_group.save() - - # get or create certificate, add user - cert, c_created = X509Cert.objects.get_or_create(subject=CERT_SUBJ) - cert.users.add(user) - cert.save() - -def delete_robot(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - - # Get user - user = LocalUser.objects.get(username=ROBOT['username']) - - # Delete user. - user.delete() - - # Delete cert. - X509Cert.objects.get(subject=CERT_SUBJ).delete() - -class Migration(migrations.Migration): - - dependencies = [ - ('ligoauth', '0016_add_losc_account'), - ] - - operations = [ - migrations.RunPython(create_robot, delete_robot) - ] - -# End of file diff --git a/ligoauth/migrations/0018_update_lib_accounts.py b/ligoauth/migrations/0018_update_lib_accounts.py deleted file mode 100644 index ddf893bf7f0f6027107305c9b4b2c0f370f930ad..0000000000000000000000000000000000000000 --- a/ligoauth/migrations/0018_update_lib_accounts.py +++ /dev/null @@ -1,69 +0,0 @@ -# -*- coding: utf-8 -*- -# Default imports -from __future__ import unicode_literals -from django.db import migrations, models -from django.conf import settings - -ROBOTS = [{'username': {'old': 'LIB', 'new': 'LIB_PE'}, - 'last_name': {'old': 'LIB at CIT', 'new': 'LIB PE at CIT'}, - }, - {'username': 'oLIB', - 'last_name': {'old': 'LIB at CIT', 'new': 'oLIB at CIT'}, - }, -] - -def create_robots(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - - # Get user and update information - for entry in ROBOTS: - update_username = False - # get user - if isinstance(entry['username'], dict): - username = entry['username']['old'] - update_username = True - else: - username = entry['username'] - user = LocalUser.objects.get(username=username) - - # update information - if update_username: - user.username = entry['username']['new'] - user.last_name = entry['last_name']['new'] - - # save - user.save() - -def delete_robots(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - - # Get user and update information - for entry in ROBOTS: - update_username = False - # get user - if isinstance(entry['username'], dict): - username = entry['username']['new'] - update_username = True - else: - username = entry['username'] - user = LocalUser.objects.get(username=username) - - # update information - if update_username: - user.username = entry['username']['old'] - user.last_name = entry['last_name']['old'] - - # save - user.save() - -class Migration(migrations.Migration): - - dependencies = [ - ('ligoauth', '0017_add_virgo_detchar'), - ] - - operations = [ - migrations.RunPython(create_robots, delete_robots) - ] - -# End of file diff --git a/ligoauth/migrations/0019_add_mbta_cert.py b/ligoauth/migrations/0019_add_mbta_cert.py deleted file mode 100644 index 1239267073e003ab717ae07d80f7bb9780cc6430..0000000000000000000000000000000000000000 --- a/ligoauth/migrations/0019_add_mbta_cert.py +++ /dev/null @@ -1,45 +0,0 @@ -# -*- coding: utf-8 -*- -# Default imports -from __future__ import unicode_literals -from django.db import migrations, models -from django.conf import settings - -ROBOT = { - 'username': 'MbtaAlert', - 'newcert': '/C=IT/O=INFN/OU=Service/L=EGO/CN=MbtaAlert/olserver54.virgo.infn.it', -} - -def create_cert(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - - # Get user - user = LocalUser.objects.get(username=ROBOT['username']) - - # create new certificate, add user - cert = X509Cert.objects.create(subject=ROBOT['newcert']) - cert.users.add(user) - cert.save() - -def delete_cert(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - - # Get user - user = LocalUser.objects.get(username=ROBOT['username']) - - # Remove new certificate - cert = X509Cert.objects.get(subject=ROBOT['newcert']) - cert.delete() - -class Migration(migrations.Migration): - - dependencies = [ - ('ligoauth', '0018_update_lib_accounts'), - ] - - operations = [ - migrations.RunPython(create_cert, delete_cert) - ] - -# End of file diff --git a/ligoauth/migrations/0020_update_bayeswave_robots.py b/ligoauth/migrations/0020_update_bayeswave_robots.py deleted file mode 100644 index 877b0dfb47ece6802d43565364f0069a92d5b003..0000000000000000000000000000000000000000 --- a/ligoauth/migrations/0020_update_bayeswave_robots.py +++ /dev/null @@ -1,65 +0,0 @@ -# -*- coding: utf-8 -*- -# Default imports -from __future__ import unicode_literals -from django.db import migrations, models -from django.conf import settings - -# Request to update certificate from Meg Millhouse (7 Aug 2017) -UPDATE_ROBOT = { - 'username': 'bayeswave', - 'newcert': '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=bw_online/ldas-grid.ligo.caltech.edu', - 'oldcert': [ - '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=bayeswave_online/ldas-grid.ligo.caltech.edu', - ], -} - -def update_certs(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - - # Create new cert - newcert, c_created = X509Cert.objects.get_or_create( - subject=UPDATE_ROBOT['newcert']) - - # Add new cert to bayeswave user - bw_user = LocalUser.objects.get(username=UPDATE_ROBOT['username']) - newcert.users.add(bw_user) - newcert.save() - - # delete old certs - for oc in UPDATE_ROBOT['oldcert']: - oldcert = X509Cert.objects.get(subject=oc) - oldcert.delete() - - # Save user - bw_user.save() - -def revert_certs(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - - # Delete new cert. - newcert = X509Cert.objects.get(subject=UPDATE_ROBOT['newcert']) - newcert.delete() - - # Create old certs and add user - bw_user = LocalUser.objects.get(username=UPDATE_ROBOT['username']) - for oc in UPDATE_ROBOT['oldcert']: - oldcert, created = X509Cert.objects.get_or_create(subject=oc) - oldcert.users.add(bw_user) - oldcert.save() - - # Save user - bw_user.save() - -class Migration(migrations.Migration): - - dependencies = [ - ('ligoauth', '0019_add_mbta_cert'), - ] - - operations = [ - migrations.RunPython(update_certs, revert_certs) - ] - -# End of file diff --git a/ligoauth/migrations/0021_gstlal_UWM_cert.py b/ligoauth/migrations/0021_gstlal_UWM_cert.py deleted file mode 100644 index 465b9e9a6c6157948fc1908cebe7b85a7809841d..0000000000000000000000000000000000000000 --- a/ligoauth/migrations/0021_gstlal_UWM_cert.py +++ /dev/null @@ -1,47 +0,0 @@ -# -*- coding: utf-8 -*- -# Default imports -from __future__ import unicode_literals -from django.db import migrations, models -from django.conf import settings - -# Request to update certificate from Meg Millhouse (7 Aug 2017) -ROBOT = { - 'username': 'gstlalcbc', - 'newcert': '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=gstlalcbc/pcdev3.phys.uwm.edu', -} - -def add_cert(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - - # Create new cert - newcert, c_created = X509Cert.objects.get_or_create( - subject=ROBOT['newcert']) - - # Add new cert to user - user = LocalUser.objects.get(username=ROBOT['username']) - newcert.users.add(user) - newcert.save() - - # Save user - user.save() - -def remove_cert(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - - # Delete new cert. - newcert = X509Cert.objects.get(subject=ROBOT['newcert']) - newcert.delete() - -class Migration(migrations.Migration): - - dependencies = [ - ('ligoauth', '0020_update_bayeswave_robots'), - ] - - operations = [ - migrations.RunPython(add_cert, remove_cert) - ] - -# End of file diff --git a/ligoauth/migrations/0022_update_detchar_certs.py b/ligoauth/migrations/0022_update_detchar_certs.py deleted file mode 100644 index 192f56b808e5d09ae806e2bfd9c927d94b65886b..0000000000000000000000000000000000000000 --- a/ligoauth/migrations/0022_update_detchar_certs.py +++ /dev/null @@ -1,84 +0,0 @@ -# -*- coding: utf-8 -*- -# Default imports -from __future__ import unicode_literals -from django.db import migrations, models -from django.conf import settings - -# Request to update certificate from Meg Millhouse (7 Aug 2017) -ROBOT = { - 'username': 'detchar', - 'newcerts': [ - '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=detchar/detchar.ligo.caltech.edu', - '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=detchar/dcs.ligo-wa.caltech.edu', - ], - 'oldcerts': [ - '/DC=org/DC=doegrids/OU=Services/CN=detchar/ldas-pcdev1.ligo-la.caltech.edu', - '/DC=org/DC=doegrids/OU=Services/CN=detchar/ldas-pcdev1.ligo.caltech.edu', - '/DC=org/DC=doegrids/OU=Services/CN=detchar/ldas-pcdev4.ligo.caltech.edu', - '/DC=org/DC=doegrids/OU=Services/CN=detchar/ldas-pcdev1.ligo-wa.caltech.edu', - '/DC=org/DC=doegrids/OU=Services/CN=detchar/ldas-grid.ligo.caltech.edu', - '/DC=org/DC=doegrids/OU=Services/CN=detchar/ldas-pcdev2.ligo-wa.caltech.edu', - '/DC=org/DC=doegrids/OU=Services/CN=detchar/ldas-pcdev2.ligo-la.caltech.edu', - '/DC=org/DC=doegrids/OU=Services/CN=detchar/ldas-grid.ligo-la.caltech.edu', - '/DC=org/DC=doegrids/OU=Services/CN=detchar/ldas-pcdev2.ligo.caltech.edu', - '/DC=org/DC=doegrids/OU=Services/CN=detchar/ldas-pcdev3.ligo.caltech.edu', - '/DC=org/DC=doegrids/OU=Services/CN=detchar/ldas-grid.ligo-wa.caltech.edu', - '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=detchar/ldas-pcdev1.ligo.caltech.edu', - '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=detchar/ldas-pcdev1.ligo-wa.caltech.edu', - ], -} - -def update_certs(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - - # Create new certs - user = LocalUser.objects.get(username=ROBOT['username']) - for cert in ROBOT['newcerts']: - newcert, c_created = X509Cert.objects.get_or_create( - subject=cert) - - # Add new cert to user - newcert.users.add(user) - newcert.save() - - # Save user - user.save() - - # Remove old certs - for cert in ROBOT['oldcerts']: - oldcert = X509Cert.objects.get(subject=cert) - oldcert.delete() - -def revert_certs(apps, schema_editor): - LocalUser = apps.get_model('ligoauth','LocalUser') - X509Cert = apps.get_model('ligoauth','X509Cert') - - # Delete new certs. - for cert in ROBOT['newcerts']: - newcert = X509Cert.objects.get(subject=cert) - newcert.delete() - - # Create old certs - user = LocalUser.objects.get(username=ROBOT['username']) - for cert in ROBOT['oldcerts']: - oldcert, created = X509Cert.objects.get_or_create(subject=cert) - - # Add to user - oldcert.users.add(user) - oldcert.save() - - # Save user - user.save() - -class Migration(migrations.Migration): - - dependencies = [ - ('ligoauth', '0021_gstlal_UWM_cert'), - ] - - operations = [ - migrations.RunPython(update_certs, revert_certs) - ] - -# End of file