From 94dddcb6d64c3b52046ffad1a863964acd31299e Mon Sep 17 00:00:00 2001
From: Tanner Prestegard <tanner.prestegard@ligo.org>
Date: Mon, 3 Dec 2018 12:49:38 -0600
Subject: [PATCH] Add new robot cert for dashboard/nagios monitor

---
 .../migrations/0015_add_new_dashboard_cert.py | 44 +++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 gracedb/ligoauth/migrations/0015_add_new_dashboard_cert.py

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 000000000..6173c204f
--- /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),
+    ]
-- 
GitLab