*config-show: Do not show empty roles/attributes

If the role or attribute is empty (i.e. no server provides the role or
the caller has no read access to  the required information) do not
return empty attributes. This is consistent with other behavior
displayed by optional multivalued Params.

https://pagure.io/freeipa/issue/7029

Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
Martin Babinsky authored and Martin Basti committed 2017-07-04 14:42:43 +02:00
1 parent 22b0ae440a
commit f4d77533f5
2 files changed
+9 -4

No files matched your search

+1 -2
View File
@@ -278,8 +278,7 @@ class config(LDAPObject):
role_config = backend.config_retrieve(role_name)
for key, value in role_config.items():
if value:
entry_attrs.update({key: value})
entry_attrs.update({key: value})
def show_servroles_attributes(self, entry_attrs, *roles, **options):
+8 -2
View File
@@ -81,13 +81,17 @@ class serverroles(Backend):
reason=_("{role}: role not found".format(role=role_name)))
def _get_enabled_masters(self, role_name):
result = {}
role = self._get_role(role_name)
enabled_masters = [
r[u'server_server'] for r in role.status(self.api, server=None) if
r[u'status'] == ENABLED]
return {role.attr_name: enabled_masters}
if enabled_masters:
result.update({role.attr_name: enabled_masters})
return result
def _get_assoc_attributes(self, role_name):
role = self._get_role(role_name)
@@ -136,7 +140,9 @@ class serverroles(Backend):
for name, attr in assoc_attributes.items():
attr_value = attr.get(self.api)
result.update({name: attr_value})
if attr_value:
result.update({name: attr_value})
return result