Skip to content
Snippets Groups Projects
Commit f483d5d9 authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB
Browse files

updating CWB robot certificates and email

parent fcad034b
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2018-04-30 16:12
#
# This migration adds a new "emfollow" user which will be used for
# EM follow-up activities. The old EM follow-up accounts will be deactivated
# and their X509Certs will be deleted.
from __future__ import unicode_literals
from django.db import migrations
from django.conf import settings
ACCOUNT = {
'username': 'waveburst',
'remove_certs': [
'/DC=org/DC=doegrids/OU=Services/CN=waveburst/ldas-pcdev1.ligo.caltech.edu',
'/DC=org/DC=ligo/O=LIGO/OU=Services/CN=waveburst/ldas-pcdev1.ligo.caltech.edu',
'/DC=org/DC=ligo/O=LIGO/OU=Services/CN=waveburst/ldas-grid.ligo.caltech.edu',
'/DC=org/DC=ligo/O=LIGO/OU=Services/CN=waveburst/ldas-grid.ligo-la.caltech.edu',
'/DC=org/DC=ligo/O=LIGO/OU=Services/CN=waveburst/ldas-grid.ligo-wa.caltech.edu',
'/DC=org/DC=ligo/O=LIGO/OU=Services/CN=waveburst/ldas-pcdev1.ligo-la.caltech.edu',
'/DC=org/DC=ligo/O=LIGO/OU=Services/CN=waveburst/ldas-pcdev1.ligo-wa.caltech.edu',
],
'new_certs': [
'/DC=org/DC=ligo/O=LIGO/OU=Services/CN=waveburst/cwb.ligo.caltech.edu',
],
'old_email': 'bmoe@gravity.phys.uwm.edu',
'new_email': 'marco.drago@ligo.org',
}
def update_account(apps, schema_editor):
LocalUser = apps.get_model('ligoauth', 'LocalUser')
X509Cert = apps.get_model('ligoauth', 'X509Cert')
# Get user
user = LocalUser.objects.get(username=ACCOUNT['username'])
# Delete old certificates
for subject in ACCOUNT['remove_certs']:
X509Cert.objects.get(subject=subject).delete()
# Create new certificates and associate with user
for subject in ACCOUNT['new_certs']:
new_cert = X509Cert.objects.create(subject=subject)
user.x509cert_set.add(new_cert)
# Update e-mail
user.email = ACCOUNT['new_email']
user.save()
def revert_account(apps, schema_editor):
LocalUser = apps.get_model('ligoauth', 'LocalUser')
X509Cert = apps.get_model('ligoauth', 'X509Cert')
# Get user
user = LocalUser.objects.get(username=ACCOUNT['username'])
# Create old certificates and associate with user
for subject in ACCOUNT['remove_certs']:
cert = X509Cert.objects.create(subject=subject)
user.x509cert_set.add(cert)
# Delete new certs
for subject in ACCOUNT['new_certs']:
X509Cert.objects.get(subject=subject).delete()
# Revert e-mail update
user.email = ACCOUNT['old_email']
user.save()
class Migration(migrations.Migration):
dependencies = [
('ligoauth', '0005_update_emfollow_accounts'),
]
operations = [
migrations.RunPython(update_account, revert_account),
]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment