LdapClient: improve just-try mode detection
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Benjamin Renard 2022-05-27 15:29:16 +02:00
parent 5f0527f0c3
commit 6ac1216ed8

View file

@ -369,6 +369,16 @@ class LdapClient:
return default
@property
def _just_try(self):
""" Check if just-try mode is enabled """
return self._get_option(
'just_try', default=(
self._config.get_option('just_try') if self._config
else False
)
)
def configure(self, comment=None, **kwargs):
""" Configure options on registered mylib.Config object """
assert self._config, "mylib.Config object not registered. Must be passed to __init__ as config keyword argument."
@ -697,7 +707,7 @@ class LdapClient:
for attr, values in attrs.items()
)
try:
if self._get_option('just_try', default=False):
if self._just_try:
log.debug('Just-try mode : do not really add object in LDAP')
return True
assert self._conn or self.initialize()
@ -766,7 +776,7 @@ class LdapClient:
log.debug('%s: No change detected on RDN attibute %s', ldap_obj['dn'], rdn_attr)
try:
if self._get_option('just_try', default=False):
if self._just_try:
log.debug('Just-try mode : do not really update object in LDAP')
return True
assert self._conn or self.initialize()
@ -792,7 +802,7 @@ class LdapClient:
:param new_dn_or_rdn: The new LDAP object's DN (or RDN)
"""
try:
if self._get_option('just_try', default=False):
if self._just_try:
log.debug('Just-try mode : do not really move object in LDAP')
return True
assert self._conn or self.initialize()
@ -811,7 +821,7 @@ class LdapClient:
:param ldap_obj: The original LDAP object to delete/drop
"""
try:
if self._get_option('just_try', default=False):
if self._just_try:
log.debug('Just-try mode : do not really drop object in LDAP')
return True
assert self._conn or self.initialize()