diff --git a/gracedb/ligoauth/migrations/0029_update_detchar_certs.py b/gracedb/ligoauth/migrations/0029_update_detchar_certs.py new file mode 100644 index 0000000000000000000000000000000000000000..6abc4408e6fd5f1d63c3a6c73a023e5e28526de4 --- /dev/null +++ b/gracedb/ligoauth/migrations/0029_update_detchar_certs.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.18 on 2019-04-30 14:14 +from __future__ import unicode_literals + +from django.db import migrations + +# At present, we won't delete the old certificate (it's not yet expired) +# so that the user can make a seamless transfer without auth issues + +ACCOUNT = { + 'name': 'detchar', + 'new_cert': '/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=detchar.ligo.caltech.edu/CN=detchar/CN=Alexander Urban/CN=UID:alexander.urban.robot', + #'old_cert': '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=detchar/detchar.ligo.caltech.edu', +} + + +def update_certs(apps, schema_editor): + RobotUser = apps.get_model('ligoauth', 'RobotUser') + + # Get user + user = RobotUser.objects.get(username=ACCOUNT['name']) + + # Create new certificate + user.x509cert_set.create(subject=ACCOUNT['new_cert']) + + # Delete old cert + #user.x509cert_set.get(subject=ACCOUNT['old_cert']).delete() + + +def revert_certs(apps, schema_editor): + RobotUser = apps.get_model('ligoauth', 'RobotUser') + + # Get user + user = RobotUser.objects.get(username=ACCOUNT['name']) + + # Delete new certificate + cert = user.x509cert_set.get(subject=ACCOUNT['new_cert']) + cert.delete() + + # Create old certificate + #user.x509cert_set.create(subject=ACCOUNT['old_cert']) + + +class Migration(migrations.Migration): + + dependencies = [ + ('ligoauth', '0028_create_gbm_followup_account_and_certs'), + ] + + operations = [ + migrations.RunPython(update_certs, revert_certs), + ]