Blob Blame Raw
From f05d6e7bfc4e829118e53f69f247d345a90e7796 Mon Sep 17 00:00:00 2001
From: Mark Reynolds <mreynolds@redhat.com>
Date: Mon, 13 Jan 2020 19:17:04 -0500
Subject: [PATCH] Issue 50818 - dsconf pwdpolicy get error

Description:  When trying to retrieve a global or local policy we now see:

                policyError: 'PwPolicyManager' object has no attribute 'get_attr_list'

              Someone removed the function get_attr_list() along the way.
              Added the same logic back, and improved it to only report attributes
              that are set.

relates: https://pagure.io/389-ds-base/issue/50818

Reviewed by: spichugi(Thanks!)
---
 src/lib389/lib389/cli_conf/pwpolicy.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/lib389/lib389/cli_conf/pwpolicy.py b/src/lib389/lib389/cli_conf/pwpolicy.py
index f911997bf..67bfd8767 100644
--- a/src/lib389/lib389/cli_conf/pwpolicy.py
+++ b/src/lib389/lib389/cli_conf/pwpolicy.py
@@ -35,16 +35,17 @@ def _get_policy_type(inst, dn=None):
 def _get_pw_policy(inst, targetdn, log, use_json=None):
     pwp_manager = PwPolicyManager(inst)
     policy_type = _get_policy_type(inst, targetdn)
-    attr_list = pwp_manager.get_attr_list()
+    attr_list = list(pwp_manager.arg_to_attr.values())
     if "global" in policy_type.lower():
         targetdn = 'cn=config'
         attr_list.extend(['passwordIsGlobalPolicy', 'nsslapd-pwpolicy_local'])
-        attrs = inst.config.get_attrs_vals_utf8(attr_list)
+        all_attrs = inst.config.get_attrs_vals_utf8(attr_list)
+        attrs = {k: v for k, v in all_attrs.items() if len(v) > 0}
     else:
         policy = pwp_manager.get_pwpolicy_entry(targetdn)
         targetdn = policy.dn
-        attrs = policy.get_attrs_vals_utf8(attr_list)
-
+        all_attrs = policy.get_attrs_vals_utf8(attr_list)
+        attrs = {k: v for k, v in all_attrs.items() if len(v) > 0}
     if use_json:
         print(json.dumps({"type": "entry", "pwp_type": policy_type, "dn": ensure_str(targetdn), "attrs": attrs}))
     else:
-- 
2.21.1