Skip to content

Commit

Permalink
Issue 3656 - Extend schema function to return MAY or MUST attrs
Browse files Browse the repository at this point in the history
Add new paramters to get_allowed_attributes() to return just MAY or MUST
attributes

Related: https://pagure.io/freeipa/issue/3656

Signed-off-by: Mark Reynolds <mreynolds@redhat.com>
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
Reviewed-By: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
Reviewed-By: Christian Heimes <cheimes@redhat.com>
  • Loading branch information
mreynolds389 authored and flo-renaud committed Nov 28, 2023
1 parent 7ee2d7d commit 5c86141
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions ipapython/ipaldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1185,14 +1185,23 @@ def schema(self):
"""schema associated with this LDAP server"""
return self._get_schema()

def get_allowed_attributes(self, objectclasses, raise_on_unknown=False):
def get_allowed_attributes(self, objectclasses, raise_on_unknown=False,
attributes="all"):
if self.schema is None:
return None
allowed_attributes = []
for oc in objectclasses:
obj = self.schema.get_obj(ldap.schema.ObjectClass, oc)
if obj is not None:
allowed_attributes += obj.must + obj.may
if attributes == "must":
# Only return required(must) attrs
allowed_attributes += obj.must
elif attributes == "may":
# Only return allowed(may) attrs
allowed_attributes += obj.may
else:
# Return both allowed & required attrs
allowed_attributes += obj.must + obj.may
elif raise_on_unknown:
raise errors.NotFound(
reason=_('objectclass %s not found') % oc)
Expand All @@ -1201,7 +1210,6 @@ def get_allowed_attributes(self, objectclasses, raise_on_unknown=False):
def __enter__(self):
return self


def __exit__(self, exc_type, exc_value, traceback):
self.close()

Expand Down

0 comments on commit 5c86141

Please sign in to comment.