From 306de2031f5f9755e1351f41092189cef0664c7e Mon Sep 17 00:00:00 2001
From: "alexander.pace@ligo.org" <alexander.pace@ligo.org>
Date: Thu, 14 Nov 2019 12:51:46 -0600
Subject: [PATCH] Three new migrations

New certificates for nagios, gstlalcbc, and detchar
---
 .../migrations/0056_update_dashboard_cert.py  | 44 +++++++++++++++++
 .../migrations/0057_gstlalcbc_luigi_cert.py   | 43 +++++++++++++++++
 .../migrations/0058_add_more_detchar_certs.py | 47 +++++++++++++++++++
 3 files changed, 134 insertions(+)
 create mode 100644 gracedb/ligoauth/migrations/0056_update_dashboard_cert.py
 create mode 100644 gracedb/ligoauth/migrations/0057_gstlalcbc_luigi_cert.py
 create mode 100644 gracedb/ligoauth/migrations/0058_add_more_detchar_certs.py

diff --git a/gracedb/ligoauth/migrations/0056_update_dashboard_cert.py b/gracedb/ligoauth/migrations/0056_update_dashboard_cert.py
new file mode 100644
index 000000000..76de8da6d
--- /dev/null
+++ b/gracedb/ligoauth/migrations/0056_update_dashboard_cert.py
@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.20 on 2019-06-03 20:10
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+# Note: the CN in the cert is for detchar-la, not detchar.
+
+ACCOUNT = {
+    'name': 'nagios',
+    'new_cert': '/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=dashboard.ligo.org/CN=NagiosShibScraper/CN=Shawn Kwang/CN=UID:shawn.kwang.robot',
+}
+
+
+def add_cert(apps, schema_editor):
+    RobotUser = apps.get_model('auth', 'User')
+
+    # Get user
+    user = RobotUser.objects.get(username=ACCOUNT['name'])
+
+    # Create new certificate
+    user.x509cert_set.create(subject=ACCOUNT['new_cert'])
+
+
+def delete_cert(apps, schema_editor):
+    RobotUser = apps.get_model('auth', 'User')
+
+    # Get user
+    user = RobotUser.objects.get(username=ACCOUNT['name'])
+
+    # Delete new certificate
+    cert = user.x509cert_set.get(subject=ACCOUNT['new_cert'])
+    cert.delete()
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('ligoauth', '0055_update_detchar_cert'),
+    ]
+
+    operations = [
+        migrations.RunPython(add_cert, delete_cert),
+    ]
diff --git a/gracedb/ligoauth/migrations/0057_gstlalcbc_luigi_cert.py b/gracedb/ligoauth/migrations/0057_gstlalcbc_luigi_cert.py
new file mode 100644
index 000000000..f1bc0af53
--- /dev/null
+++ b/gracedb/ligoauth/migrations/0057_gstlalcbc_luigi_cert.py
@@ -0,0 +1,43 @@
+ngo 1.11.20 on 2019-06-03 20:10
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+# Note: the CN in the cert is for detchar-la, not detchar.
+
+ACCOUNT = {
+    'name': 'gstlalcbc',
+    'new_cert': '/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=submit.nemo.uwm.edu/CN=gstlal_online_luigi/CN=Duncan Meacher/CN=UID:duncan.meacher.robot',
+}
+
+
+def add_cert(apps, schema_editor):
+    RobotUser = apps.get_model('auth', 'User')
+
+    # Get user
+    user = RobotUser.objects.get(username=ACCOUNT['name'])
+
+    # Create new certificate
+    user.x509cert_set.create(subject=ACCOUNT['new_cert'])
+
+
+def delete_cert(apps, schema_editor):
+    RobotUser = apps.get_model('auth', 'User')
+
+    # Get user
+    user = RobotUser.objects.get(username=ACCOUNT['name'])
+
+    # Delete new certificate
+    cert = user.x509cert_set.get(subject=ACCOUNT['new_cert'])
+    cert.delete()
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('ligoauth', '0056_update_dashboard_cert'),
+    ]
+
+    operations = [
+        migrations.RunPython(add_cert, delete_cert),
+    ]
diff --git a/gracedb/ligoauth/migrations/0058_add_more_detchar_certs.py b/gracedb/ligoauth/migrations/0058_add_more_detchar_certs.py
new file mode 100644
index 000000000..dfb8b8e55
--- /dev/null
+++ b/gracedb/ligoauth/migrations/0058_add_more_detchar_certs.py
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.20 on 2019-06-03 20:10
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+# detchar is on a tear getting new certs, so I'm doing three
+# at once.
+
+gracedb_account = 'detchar'
+new_certs = ['/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=detchar.ligo-wa.caltech.edu/CN=detchar_ligo-wa/CN=Alexander Urban/CN=UID:alexander.urban.robot',
+        '/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=detchar.ligo.caltech.edu/CN=detchar_cit/CN=Alexander Urban/CN=UID:alexander.urban.robot',
+        '/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=ldas-pcdev1.ligo-la.caltech.edu/CN=detchar_ldas-pcdev1_ligo-la/CN=Michael Thomas/CN=UID:michael.thomas.robot']
+
+
+def add_cert(apps, schema_editor):
+    RobotUser = apps.get_model('auth', 'User')
+
+    # Get user
+    user = RobotUser.objects.get(username=gracedb_account)
+
+    # Create new certificates
+    for cert in new_certs:
+        user.x509cert_set.create(subject=cert)
+
+
+def delete_cert(apps, schema_editor):
+    RobotUser = apps.get_model('auth', 'User')
+
+    # Get user
+    user = RobotUser.objects.get(username=gracedb_account)
+
+    # Delete new certificates
+    for cert in new_certs:
+      cert = user.x509cert_set.get(subject=cert)
+      cert.delete()
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('ligoauth', '0057_gstlalcbc_luigi_cert'),
+    ]
+
+    operations = [
+        migrations.RunPython(add_cert, delete_cert),
+    ]
-- 
GitLab