From ec472218c408c2ad33510e8cc4f061ebffcf4a11 Mon Sep 17 00:00:00 2001 From: Blallo Date: Sat, 6 Jul 2019 21:24:26 +0200 Subject: [PATCH] Manage append and replace User modify. --- src/phi/async_ldap/model.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/phi/async_ldap/model.py b/src/phi/async_ldap/model.py index fe73514..42fb2ef 100644 --- a/src/phi/async_ldap/model.py +++ b/src/phi/async_ldap/model.py @@ -272,10 +272,16 @@ class User(Hackers): if not k == "dn": self._entry[k] = v - async def modify(self, key, value): + async def modify(self, key, value, append=False): async with self.client.connect(is_async=True) as conn: self._entry.connection = conn - await self._entry.change_attribute(key, LDAPModOp.REPLACE, value) + try: + if not append: + del self._entry[key] + self._entry[key] = value + except KeyError: + raise PhiAttributeMissing + await self._entry.modify() async def remove(self): async with self.client.connect(is_async=True) as conn: @@ -291,6 +297,10 @@ class PhiUserDoesNotExist(Exception): pass +class PhiAttributeMissing(Exception): + pass + + class Service(Robots): """ This class models a system user (i.e. users that are ancillary to