Make the role_chain.py script emit a Graphviz file

of the Role relationships.
This commit is contained in:
Jeff Bradberry 2024-05-03 15:43:48 -04:00
parent 85fc81aab1
commit 1f154742df

View File

@ -1,5 +1,4 @@
from collections import defaultdict
import os
import sys
from django.contrib.contenttypes.models import ContentType
@ -8,7 +7,16 @@ from awx.main.fields import ImplicitRoleField
from awx.main.models.rbac import Role
r_id = int(os.environ.get('role'))
r = Role.objects.get(id=r_id)
print("digraph G {")
print(r)
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("}")