From 63b0a9c097c8a6c255a2ac6916e96ccdf47a8da5 Mon Sep 17 00:00:00 2001 From: Tanner Prestegard <tanner.prestegard@ligo.org> Date: Mon, 17 Dec 2018 13:31:49 -0600 Subject: [PATCH] Update certs for LLO CDS --- .../migrations/0018_update_cds_llo_certs.py | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 gracedb/ligoauth/migrations/0018_update_cds_llo_certs.py diff --git a/gracedb/ligoauth/migrations/0018_update_cds_llo_certs.py b/gracedb/ligoauth/migrations/0018_update_cds_llo_certs.py new file mode 100644 index 000000000..f05781a96 --- /dev/null +++ b/gracedb/ligoauth/migrations/0018_update_cds_llo_certs.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.16 on 2018-12-14 15:55 +from __future__ import unicode_literals + +from django.db import migrations + +ACCOUNT_NAME = 'cds_llo' +NEW_CERT = '/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=cds-outbound.ligo-la.caltech.edu/CN=exttrig/CN=Keith Thorne/CN=UID:keith.thorne.robot' +OLD_CERTS = [ + '/DC=org/DC=ligo/O=LIGO/OU=Services/CN=exttrig/cds-outbound.ligo-la.caltech.edu', +] + + +def update_certs(apps, schema_editor): + User = apps.get_model('auth', 'User') + + # Get user + user = User.objects.get(username=ACCOUNT_NAME) + + # Create new certificate + user.x509cert_set.create(subject=NEW_CERT) + + # Delete old certificates + for subj in OLD_CERTS: + old_cert = user.x509cert_set.get(subject=subj) + old_cert.delete() + + +def revert_certs(apps, schema_editor): + User = apps.get_model('auth', 'User') + X509Cert = apps.get_model('ligoauth', 'X509Cert') + + # Delete new certificate + new_cert = X509Cert.objects.get(subject=NEW_CERT) + new_cert.delete() + + # Get user + user = User.objects.get(username=ACCOUNT_NAME) + + # Create old certificates + for subj in OLD_CERTS: + user.x509cert_set.create(subject=subj) + + +class Migration(migrations.Migration): + + dependencies = [ + ('ligoauth', '0017_update_cds_lho_certs'), + ] + + operations = [ + migrations.RunPython(update_certs, revert_certs), + ] -- GitLab