Skip to content
Snippets Groups Projects
  • Tanner Prestegard's avatar
    146ab7ea
    Bugfix to ligoauth migrations · 146ab7ea
    Tanner Prestegard authored
    Fixing two migrations
      - ligoauth 0004: properly delete User instance for gstlal-spiir-gpu,
        not just LocalUser/RobotUser
      - ligoauth 0013: deleted, since gstlal-spiir-gpu has been deleted,
        we don't need to create a RobotUser instance for it
    146ab7ea
    History
    Bugfix to ligoauth migrations
    Tanner Prestegard authored
    Fixing two migrations
      - ligoauth 0004: properly delete User instance for gstlal-spiir-gpu,
        not just LocalUser/RobotUser
      - ligoauth 0013: deleted, since gstlal-spiir-gpu has been deleted,
        we don't need to create a RobotUser instance for it
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
0014_add_new_dashboard_cert.py 1.23 KiB
# -*- 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', '0013_x509cert_subject_longer'),
    ]

    operations = [
        migrations.RunPython(add_cert, remove_cert),
    ]