Forked from
IGWN Computing and Software / GraceDB / GraceDB Server
1231 commits behind the upstream repository.
-
Tanner Prestegard authoredTanner Prestegard authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
0021_create_deepclean_account_and_certs.py 1.57 KiB
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2019-01-04 18:39
from __future__ import unicode_literals
from django.db import migrations
ACCOUNT = {
'username': 'deepclean',
'email': 'michael.coughlin@ligo.org',
'first_name': '',
'last_name': 'LIGO/Virgo ML Noise Cleaning',
}
CERTS = [
'/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=ldas-pcdev2.ligo-wa.caltech.edu/CN=deepclean_lho/CN=Michael Coughlin/CN=UID:michael.coughlin.robot',
'/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=ldas-pcdev2.ligo-la.caltech.edu/CN=deepclean_llo/CN=Michael Coughlin/CN=UID:michael.coughlin.robot',
]
def create_account_and_certs(apps, schema_editor):
RobotUser = apps.get_model('ligoauth', 'RobotUser')
X509Cert = apps.get_model('ligoauth', 'X509Cert')
# Create user
user = RobotUser.objects.create(**ACCOUNT)
# Create X509 certificates
for subject in CERTS:
user.x509cert_set.create(subject=subject)
def delete_account_and_certs(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 certs
for cert in user.x509cert_set.filter(subject__in=CERTS):
cert.delete()
# Delete full User object
user.user_ptr.delete()
class Migration(migrations.Migration):
dependencies = [
('ligoauth', '0020_remove_old_dashboard_certs'),
]
operations = [
migrations.RunPython(create_account_and_certs,
delete_account_and_certs),
]