apibuild: Add infrastructure for generating ACL flag info into function docs

If the user of the 'docBuilder' class provides a dict (key is API name,
value is a tuple of arrays (acls, aclfilters), use the dict to generate
ACL definitions into the function definition.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2023-02-21 14:06:02 +01:00
parent 1f1bd6ab2d
commit d03b6bf0cb

View File

@ -2071,10 +2071,11 @@ class CParser:
class docBuilder: class docBuilder:
"""A documentation builder""" """A documentation builder"""
def __init__(self, name, syms, path='.', directories=['.'], includes=[]): def __init__(self, name, syms, path='.', directories=['.'], includes=[], acls=None):
self.name = name self.name = name
self.syms = syms self.syms = syms
self.path = path self.path = path
self.acls = acls
self.directories = directories self.directories = directories
if name == "libvirt": if name == "libvirt":
self.includes = includes + list(included_files.keys()) self.includes = includes + list(included_files.keys())
@ -2477,6 +2478,32 @@ class docBuilder:
except Exception: except Exception:
print("Exception:", sys.exc_info()[1], file=sys.stderr) print("Exception:", sys.exc_info()[1], file=sys.stderr)
self.warning("Failed to save function %s info: %s" % (name, repr(id.info))) self.warning("Failed to save function %s info: %s" % (name, repr(id.info)))
if self.acls and name in self.acls:
acls = self.acls[name][0]
aclfilters = self.acls[name][1]
if len(acls) > 0 or len(aclfilters) > 0:
output.write(" <acls>\n")
for acl in acls:
comp = acl.split(':', 3)
objname = comp[0].replace('_', '-')
perm = comp[1].replace('_', '-')
output.write(" <check object='%s' perm='%s'" % (objname, perm))
if len(comp) > 2:
output.write(" flags='%s'" % comp[2])
output.write("/>\n")
for aclfilter in aclfilters:
comp = aclfilter.split(':', 2)
objname = comp[0].replace('_', '-')
perm = comp[1].replace('_', '-')
output.write(" <filter object='%s' perm='%s'/>\n" % (objname, perm))
output.write(" </acls>\n")
output.write(" </%s>\n" % (id.type)) output.write(" </%s>\n" % (id.type))
def serialize_exports(self, output, file): def serialize_exports(self, output, file):