From c779476bc6838790444fd7c38332576f0fee0583 Mon Sep 17 00:00:00 2001
From: Tanner Prestegard <tanner.prestegard@ligo.org>
Date: Fri, 15 Mar 2019 20:48:14 -0500
Subject: [PATCH] Add new robot certificate for 'hinj' account and update email

---
 .../0026_update_hinj_acct_and_certs.py        | 50 +++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100644 gracedb/ligoauth/migrations/0026_update_hinj_acct_and_certs.py

diff --git a/gracedb/ligoauth/migrations/0026_update_hinj_acct_and_certs.py b/gracedb/ligoauth/migrations/0026_update_hinj_acct_and_certs.py
new file mode 100644
index 000000000..d2ed6d5cb
--- /dev/null
+++ b/gracedb/ligoauth/migrations/0026_update_hinj_acct_and_certs.py
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.18 on 2019-03-15 20:38
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+USERNAME = 'hinj'
+NEW_CERT = '/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=ldas-grid.ligo.caltech.edu/CN=hwinjmonitor/CN=Thomas Massinger/CN=UID:thomas.massinger.robot'
+OLD_EMAIL = 'mhulko@caltech.edu'
+NEW_EMAIL = 'tmassing@ligo.caltech.edu'
+
+
+def update_acct(apps, schema_editor):
+    RobotUser = apps.get_model('ligoauth', 'RobotUser')
+
+    # Get user
+    user = RobotUser.objects.get(username=USERNAME)
+
+    # Create new certificate for user
+    user.x509cert_set.create(subject=NEW_CERT)
+
+    # Update email
+    user.email = NEW_EMAIL
+    user.save(update_fields=['email'])
+
+
+def revert_acct(apps, schema_editor):
+    RobotUser = apps.get_model('ligoauth', 'RobotUser')
+
+    # Get user
+    user = RobotUser.objects.get(username=USERNAME)
+
+    # Delete new certificate
+    user.x509cert_set.get(subject=NEW_CERT).delete()
+
+    # Revert email
+    user.email = OLD_EMAIL
+    user.save(update_fields=['email'])
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('ligoauth', '0025_update_emfollow_certs'),
+    ]
+
+    operations = [
+        migrations.RunPython(update_acct, revert_acct),
+    ]
-- 
GitLab