a2478bf
From 2a6784884fa931643f52ff01dc7dacf3da0be90f Mon Sep 17 00:00:00 2001
a2478bf
From: Mark Reynolds <mreynolds@redhat.com>
a2478bf
Date: Mon, 13 Jan 2020 19:17:04 -0500
a2478bf
Subject: [PATCH 2/2] Issue 50818 - dsconf pwdpolicy get error
a2478bf
a2478bf
Description:  When trying to retrieve a global or local policy we now see:
a2478bf
a2478bf
                policyError: 'PwPolicyManager' object has no attribute 'get_attr_list'
a2478bf
a2478bf
              Someone removed the function get_attr_list() along the way.
a2478bf
              Added the same logic back, and improved it to only report attributes
a2478bf
              that are set.
a2478bf
a2478bf
relates: https://pagure.io/389-ds-base/issue/50818
a2478bf
a2478bf
Reviewed by: spichugi(Thanks!)
a2478bf
---
a2478bf
 src/lib389/lib389/cli_conf/pwpolicy.py | 9 +++++----
a2478bf
 1 file changed, 5 insertions(+), 4 deletions(-)
a2478bf
a2478bf
diff --git a/src/lib389/lib389/cli_conf/pwpolicy.py b/src/lib389/lib389/cli_conf/pwpolicy.py
a2478bf
index f911997bf..67bfd8767 100644
a2478bf
--- a/src/lib389/lib389/cli_conf/pwpolicy.py
a2478bf
+++ b/src/lib389/lib389/cli_conf/pwpolicy.py
a2478bf
@@ -35,16 +35,17 @@ def _get_policy_type(inst, dn=None):
a2478bf
 def _get_pw_policy(inst, targetdn, log, use_json=None):
a2478bf
     pwp_manager = PwPolicyManager(inst)
a2478bf
     policy_type = _get_policy_type(inst, targetdn)
a2478bf
-    attr_list = pwp_manager.get_attr_list()
a2478bf
+    attr_list = list(pwp_manager.arg_to_attr.values())
a2478bf
     if "global" in policy_type.lower():
a2478bf
         targetdn = 'cn=config'
a2478bf
         attr_list.extend(['passwordIsGlobalPolicy', 'nsslapd-pwpolicy_local'])
a2478bf
-        attrs = inst.config.get_attrs_vals_utf8(attr_list)
a2478bf
+        all_attrs = inst.config.get_attrs_vals_utf8(attr_list)
a2478bf
+        attrs = {k: v for k, v in all_attrs.items() if len(v) > 0}
a2478bf
     else:
a2478bf
         policy = pwp_manager.get_pwpolicy_entry(targetdn)
a2478bf
         targetdn = policy.dn
a2478bf
-        attrs = policy.get_attrs_vals_utf8(attr_list)
a2478bf
-
a2478bf
+        all_attrs = policy.get_attrs_vals_utf8(attr_list)
a2478bf
+        attrs = {k: v for k, v in all_attrs.items() if len(v) > 0}
a2478bf
     if use_json:
a2478bf
         print(json.dumps({"type": "entry", "pwp_type": policy_type, "dn": ensure_str(targetdn), "attrs": attrs}))
a2478bf
     else:
a2478bf
-- 
a2478bf
2.24.1
a2478bf