From d1e966418db3b275d9a2518c7660dae09a056dd4 Mon Sep 17 00:00:00 2001 From: Ward Poelmans Date: Tue, 14 Nov 2023 16:27:07 -0700 Subject: [PATCH] fix issue with list --- lib/vsc/ldap/utils.py | 13 +++++-------- setup.py | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/vsc/ldap/utils.py b/lib/vsc/ldap/utils.py index a837ec7..4cc09cd 100644 --- a/lib/vsc/ldap/utils.py +++ b/lib/vsc/ldap/utils.py @@ -274,8 +274,11 @@ def add(self, dn, attributes): if self.ldap_connection is None: self.bind() - changes = [(k, [v]) for (k, v) in attributes if not isinstance(v, list)] - changes.extend([(k, v) for (k, v) in attributes if isinstance(v, list)]) + def attr_encode(value): + return [x.encode("utf-8") if isinstance(x, str) else x for x in value] + + changes = [(k, [v.encode("utf-8")]) for (k, v) in attributes if not isinstance(v, list)] + changes.extend([(k, attr_encode(v)) for (k, v) in attributes if isinstance(v, list)]) logging.info("Adding for dn=%s with changes = %s", dn, changes) try: @@ -575,8 +578,6 @@ def user_add(self, cn, attributes): @type attributes: dictionary with attributes for which a value should be added """ dn = f"cn={cn},{self.configuration.user_dn_base}" - attributes = {key:[v.encode("utf-8") if isinstance(v, str) else v for v in values] - for key, values in attributes.items()} self.ldap.add(dn, attributes.items()) def group_add(self, cn, attributes): @@ -586,8 +587,6 @@ def group_add(self, cn, attributes): @type attributes: dictionary with attributes for which a value should be added """ dn = f"cn={cn},{self.configuration.group_dn_base}" - attributes = {key:[v.encode("utf-8") if isinstance(v, str) else v for v in values] - for key, values in attributes.items()} self.ldap.add(dn, attributes.items()) def project_add(self, cn, attributes): @@ -597,8 +596,6 @@ def project_add(self, cn, attributes): @type attributes: dictionary with attributes for which a value should be added """ dn = f"cn={cn},{self.configuration.project_dn_base}" - attributes = {key:[v.encode("utf-8") if isinstance(v, str) else v for v in values] - for key, values in attributes.items()} self.ldap.add(dn, attributes.items()) diff --git a/setup.py b/setup.py index eca1722..5cfce84 100644 --- a/setup.py +++ b/setup.py @@ -42,7 +42,7 @@ 'future >= 0.16.0', 'python-ldap', ], - 'version': '2.2.3', + 'version': '2.2.4', 'author': [ag, kh, sdw, wdp, jt], 'maintainer': [ag], }