diff --git a/gracedb/ligoauth/migrations/0015_add_new_dashboard_cert.py b/gracedb/ligoauth/migrations/0015_add_new_dashboard_cert.py new file mode 100644 index 0000000000000000000000000000000000000000..6173c204fefe8802d98f799ef6ff1dbdebe7879a --- /dev/null +++ b/gracedb/ligoauth/migrations/0015_add_new_dashboard_cert.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.16 on 2018-12-03 16:43 +from __future__ import unicode_literals + +from django.db import migrations + +ACCOUNT = { + 'username': 'nagios', + 'new_cert': '/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=dashboard.ligo.org/CN=NagiosShibScraper/CN=Thomas Downes/CN=UID:thomas.downes.robot', +} + +def add_cert(apps, schema_editor): + RobotUser = apps.get_model('ligoauth', 'RobotUser') + X509Cert = apps.get_model('ligoauth', 'X509Cert') + + # Get user + user = RobotUser.objects.get(username=ACCOUNT['username']) + + # Create new cert and associate with user + new_cert = X509Cert.objects.create(subject=ACCOUNT['new_cert']) + user.x509cert_set.add(new_cert) + + +def remove_cert(apps, schema_editor): + RobotUser = apps.get_model('ligoauth', 'RobotUser') + X509Cert = apps.get_model('ligoauth', 'X509Cert') + + # Get user + user = RobotUser.objects.get(username=ACCOUNT['username']) + + # Delete new certificate + new_cert = X509Cert.objects.get(subject=ACCOUNT['new_cert']) + new_cert.delete() + + +class Migration(migrations.Migration): + + dependencies = [ + ('ligoauth', '0014_x509cert_subject_longer'), + ] + + operations = [ + migrations.RunPython(add_cert, remove_cert), + ]