awx/tools/scripts/ig-hotfix/role_chain.py
Jeff Bradberry 1f154742df Make the role_chain.py script emit a Graphviz file
of the Role relationships.
2024-06-10 16:36:22 -04:00

23 lines
640 B
Python

from collections import defaultdict
import sys
from django.contrib.contenttypes.models import ContentType
from awx.main.fields import ImplicitRoleField
from awx.main.models.rbac import Role
print("digraph G {")
for r in Role.objects.order_by('id'):
if r.content_type is None:
print(f' {r.id} [shape=box,label="id={r.id}\lsingleton={r.singleton_name}\l"]')
else:
print(f' {r.id} [shape=box,label="id={r.id}\lct={r.content_type}\lobject_id={r.object_id}\lrole_field={r.role_field}\l"]')
for r in Role.objects.order_by('id'):
for p in r.parents.all():
print(f" {p.id} -> {r.id}")
print("}")