diff --git a/gracedb/ligoauth/migrations/0025_update_emfollow_certs.py b/gracedb/ligoauth/migrations/0025_update_emfollow_certs.py new file mode 100644 index 0000000000000000000000000000000000000000..44a709bdb3727ca0254dd80ff82a0d99157f850f --- /dev/null +++ b/gracedb/ligoauth/migrations/0025_update_emfollow_certs.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.18 on 2019-03-01 14:37 +from __future__ import unicode_literals + +from django.db import migrations + + +USERNAME = 'emfollow' +NEW_CERTS = [ + '/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=emfollow.ligo.caltech.edu/CN=emfollow/CN=Leo Singer/CN=UID:leo.singer.robot', + '/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=emfollow.ligo-la.caltech.edu/CN=emfollow-la/CN=Leo Singer/CN=UID:leo.singer.robot', + '/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=emfollow.ligo-wa.caltech.edu/CN=emfollow-wa/CN=Leo Singer/CN=UID:leo.singer.robot', + '/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=emfollow.ligo.caltech.edu/CN=emfollow-playground/CN=Leo Singer/CN=UID:leo.singer.robot', + '/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=emfollow.ligo-la.caltech.edu/CN=emfollow-playground-la/CN=Leo Singer/CN=UID:leo.singer.robot', + '/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=emfollow.ligo-wa.caltech.edu/CN=emfollow-playground-wa/CN=Leo Singer/CN=UID:leo.singer.robot', +] + + +def update_certs(apps, schema_editor): + RobotUser = apps.get_model('ligoauth', 'RobotUser') + + # Get user + user = RobotUser.objects.get(username=USERNAME) + + # Create new certificates for user + for cert in NEW_CERTS: + user.x509cert_set.create(subject=cert) + + +def revert_certs(apps, schema_editor): + RobotUser = apps.get_model('ligoauth', 'RobotUser') + + # Get user + user = RobotUser.objects.get(username=USERNAME) + + # Delete certificates for user + for cert in NEW_CERTS: + user.x509cert_set.get(subject=cert).delete() + + +class Migration(migrations.Migration): + + dependencies = [ + ('ligoauth', '0024_create_gwhen_account_and_certs'), + ] + + operations = [ + migrations.RunPython(update_certs, revert_certs), + ]