Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
0025_update_emfollow_certs.py 1.74 KiB
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-03-01 14:37
from __future__ import unicode_literals

from django.db import migrations


USERNAME = 'emfollow'
NEW_CERTS = [
    '/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=emfollow.ligo.caltech.edu/CN=emfollow/CN=Leo Singer/CN=UID:leo.singer.robot',
    '/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=emfollow.ligo-la.caltech.edu/CN=emfollow-la/CN=Leo Singer/CN=UID:leo.singer.robot',
    '/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=emfollow.ligo-wa.caltech.edu/CN=emfollow-wa/CN=Leo Singer/CN=UID:leo.singer.robot',
    '/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=emfollow.ligo.caltech.edu/CN=emfollow-playground/CN=Leo Singer/CN=UID:leo.singer.robot',
    '/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=emfollow.ligo-la.caltech.edu/CN=emfollow-playground-la/CN=Leo Singer/CN=UID:leo.singer.robot',
    '/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=emfollow.ligo-wa.caltech.edu/CN=emfollow-playground-wa/CN=Leo Singer/CN=UID:leo.singer.robot',
]


def update_certs(apps, schema_editor):
    RobotUser = apps.get_model('ligoauth', 'RobotUser')

    # Get user
    user = RobotUser.objects.get(username=USERNAME)

    # Create new certificates for user
    for cert in NEW_CERTS:
        user.x509cert_set.create(subject=cert)


def revert_certs(apps, schema_editor):
    RobotUser = apps.get_model('ligoauth', 'RobotUser')

    # Get user
    user = RobotUser.objects.get(username=USERNAME)

    # Delete certificates for user
    for cert in NEW_CERTS:
        user.x509cert_set.get(subject=cert).delete()


class Migration(migrations.Migration):

    dependencies = [
        ('ligoauth', '0024_create_gwhen_account_and_certs'),
    ]

    operations = [
        migrations.RunPython(update_certs, revert_certs),
    ]