Commit b099f6e3 authored by Alexander Pace's avatar Alexander Pace
Browse files

adding asimov account and cert

parent 3036aeea
Pipeline #155910 passed with stages
in 18 minutes and 28 seconds
# Generated by Django 2.2.10 on 2020-07-01 19:40
from django.db import migrations, models
from django.conf import settings
ROBOTS = [
{
'username' : 'asimov',
'first_name' : '',
'last_name' : 'Daniel Williams', # Note that the last_name acts as a display
'email' : 'daniel.williams@ligo.org',
'dns' : [
"/DC=org/DC=cilogon/C=US/O=LIGO/OU=Robots/CN=git.ligo.org/CN=asimov/CN=Daniel Williams/CN=UID:daniel.williams.robot",
]
},
]
def create_robots(apps, schema_editor):
User = apps.get_model('auth', 'User')
X509Cert = apps.get_model('ligoauth', 'X509Cert')
AuthGroup = apps.get_model('ligoauth', 'AuthGroup')
lvc_group = AuthGroup.objects.get(name=settings.LVC_GROUP)
robot_group = AuthGroup.objects.get(name='robot_accounts')
for entry in ROBOTS:
user, created = User.objects.get_or_create(username=entry['username'])
if created:
user.first_name = entry['first_name']
user.last_name = entry['last_name']
user.email = entry['email']
user.is_active = True
user.is_staff = False
user.is_superuser = False
user.save()
# Create the cert objects and link them to our user.
for dn in entry['dns']:
cert, created = X509Cert.objects.get_or_create(subject=dn,
user=user)
# Add our user to the LVC group. This permission is required to
# do most things, but may *NOT* always be appropriate. It may
# also be necessary to give the robotic user permission to populate
# a particular pipeline.
lvc_group.user_set.add(user)
# Add user to robot accounts
robot_group.user_set.add(user)
def delete_robots(apps, schema_editor):
User = apps.get_model('auth', 'User')
X509Cert = apps.get_model('ligoauth', 'X509Cert')
for entry in ROBOTS:
for dn in entry['dns']:
X509Cert.objects.get(subject=dn).delete()
User.objects.get(username=entry['username']).delete()
class Migration(migrations.Migration):
dependencies = [
('ligoauth', '0068_setup_swiftgrb'),
]
operations = [
migrations.RunPython(create_robots, delete_robots),
]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment