LdapClient: replace private __get_option method by protected _get_option
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

To make call by inherited class object easier.
This commit is contained in:
Benjamin Renard 2022-05-27 12:53:11 +02:00
parent 3bf87222fd
commit e7e07a944a

View file

@ -356,7 +356,7 @@ class LdapClient:
if initialize:
self.initialize()
def __get_option(self, option, default=None, required=False):
def _get_option(self, option, default=None, required=False):
""" Retreive option value """
if self._options and hasattr(self._options, self._options_prefix + option):
return getattr(self._options, self._options_prefix + option)
@ -397,11 +397,11 @@ class LdapClient:
""" Initialize LDAP connection """
if loaded_config:
self.config = loaded_config
uri = self.__get_option('uri', required=True)
binddn = self.__get_option('binddn')
uri = self._get_option('uri', required=True)
binddn = self._get_option('binddn')
log.info("Connect to LDAP server %s as %s", uri, binddn if binddn else 'annonymous')
self._conn = LdapServer(
uri, dn=binddn, pwd=self.__get_option('bindpwd'),
uri, dn=binddn, pwd=self._get_option('bindpwd'),
raiseOnError=True
)
return self._conn.connect()
@ -413,8 +413,8 @@ class LdapClient:
if isinstance(value, str):
return value
return value.decode(
self.__get_option('encoding', default=DEFAULT_ENCODING),
self.__get_option('encoding_error_policy', default='ignore')
self._get_option('encoding', default=DEFAULT_ENCODING),
self._get_option('encoding_error_policy', default='ignore')
)
def encode(self, value):
@ -423,7 +423,7 @@ class LdapClient:
return [self.encode(v) for v in value]
if isinstance(value, bytes):
return value
return value.encode(self.__get_option('encoding', default=DEFAULT_ENCODING))
return value.encode(self._get_option('encoding', default=DEFAULT_ENCODING))
def _get_obj(self, dn, attrs):
"""
@ -694,7 +694,7 @@ class LdapClient:
for attr, values in attrs.items()
)
try:
if self.__get_option('just_try', default=False):
if self._get_option('just_try', default=False):
log.debug('Just-try mode : do not really add object in LDAP')
return True
assert self._conn or self.initialize()
@ -763,7 +763,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._get_option('just_try', default=False):
log.debug('Just-try mode : do not really update object in LDAP')
return True
assert self._conn or self.initialize()
@ -789,7 +789,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._get_option('just_try', default=False):
log.debug('Just-try mode : do not really move object in LDAP')
return True
assert self._conn or self.initialize()
@ -808,7 +808,7 @@ class LdapClient:
:param ldap_obj: The original LDAP object to delete/drop
"""
try:
if self.__get_option('just_try', default=False):
if self._get_option('just_try', default=False):
log.debug('Just-try mode : do not really drop object in LDAP')
return True
assert self._conn or self.initialize()