Skip to content

Commit

Permalink
Merge pull request #51 from wpoely86/py3_fixes
Browse files Browse the repository at this point in the history
fix issue with list
  • Loading branch information
wdpypere committed Nov 17, 2023
2 parents 8b604c1 + d1e9664 commit d8b2abd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
13 changes: 5 additions & 8 deletions lib/vsc/ldap/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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())


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
'vsc-utils >= 2.0.0',
'python-ldap',
],
'version': '2.2.3',
'version': '2.2.4',
'author': [ag, kh, sdw, wdp, jt],
'maintainer': [ag],
}
Expand Down

0 comments on commit d8b2abd

Please sign in to comment.