LdapClient: replace private __get_option method by protected _get_option
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
To make call by inherited class object easier.
This commit is contained in:
parent
3bf87222fd
commit
e7e07a944a
1 changed files with 11 additions and 11 deletions
|
@ -356,7 +356,7 @@ class LdapClient:
|
||||||
if initialize:
|
if initialize:
|
||||||
self.initialize()
|
self.initialize()
|
||||||
|
|
||||||
def __get_option(self, option, default=None, required=False):
|
def _get_option(self, option, default=None, required=False):
|
||||||
""" Retreive option value """
|
""" Retreive option value """
|
||||||
if self._options and hasattr(self._options, self._options_prefix + option):
|
if self._options and hasattr(self._options, self._options_prefix + option):
|
||||||
return getattr(self._options, self._options_prefix + option)
|
return getattr(self._options, self._options_prefix + option)
|
||||||
|
@ -397,11 +397,11 @@ class LdapClient:
|
||||||
""" Initialize LDAP connection """
|
""" Initialize LDAP connection """
|
||||||
if loaded_config:
|
if loaded_config:
|
||||||
self.config = loaded_config
|
self.config = loaded_config
|
||||||
uri = self.__get_option('uri', required=True)
|
uri = self._get_option('uri', required=True)
|
||||||
binddn = self.__get_option('binddn')
|
binddn = self._get_option('binddn')
|
||||||
log.info("Connect to LDAP server %s as %s", uri, binddn if binddn else 'annonymous')
|
log.info("Connect to LDAP server %s as %s", uri, binddn if binddn else 'annonymous')
|
||||||
self._conn = LdapServer(
|
self._conn = LdapServer(
|
||||||
uri, dn=binddn, pwd=self.__get_option('bindpwd'),
|
uri, dn=binddn, pwd=self._get_option('bindpwd'),
|
||||||
raiseOnError=True
|
raiseOnError=True
|
||||||
)
|
)
|
||||||
return self._conn.connect()
|
return self._conn.connect()
|
||||||
|
@ -413,8 +413,8 @@ class LdapClient:
|
||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
return value
|
return value
|
||||||
return value.decode(
|
return value.decode(
|
||||||
self.__get_option('encoding', default=DEFAULT_ENCODING),
|
self._get_option('encoding', default=DEFAULT_ENCODING),
|
||||||
self.__get_option('encoding_error_policy', default='ignore')
|
self._get_option('encoding_error_policy', default='ignore')
|
||||||
)
|
)
|
||||||
|
|
||||||
def encode(self, value):
|
def encode(self, value):
|
||||||
|
@ -423,7 +423,7 @@ class LdapClient:
|
||||||
return [self.encode(v) for v in value]
|
return [self.encode(v) for v in value]
|
||||||
if isinstance(value, bytes):
|
if isinstance(value, bytes):
|
||||||
return value
|
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):
|
def _get_obj(self, dn, attrs):
|
||||||
"""
|
"""
|
||||||
|
@ -694,7 +694,7 @@ class LdapClient:
|
||||||
for attr, values in attrs.items()
|
for attr, values in attrs.items()
|
||||||
)
|
)
|
||||||
try:
|
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')
|
log.debug('Just-try mode : do not really add object in LDAP')
|
||||||
return True
|
return True
|
||||||
assert self._conn or self.initialize()
|
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)
|
log.debug('%s: No change detected on RDN attibute %s', ldap_obj['dn'], rdn_attr)
|
||||||
|
|
||||||
try:
|
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')
|
log.debug('Just-try mode : do not really update object in LDAP')
|
||||||
return True
|
return True
|
||||||
assert self._conn or self.initialize()
|
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)
|
:param new_dn_or_rdn: The new LDAP object's DN (or RDN)
|
||||||
"""
|
"""
|
||||||
try:
|
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')
|
log.debug('Just-try mode : do not really move object in LDAP')
|
||||||
return True
|
return True
|
||||||
assert self._conn or self.initialize()
|
assert self._conn or self.initialize()
|
||||||
|
@ -808,7 +808,7 @@ class LdapClient:
|
||||||
:param ldap_obj: The original LDAP object to delete/drop
|
:param ldap_obj: The original LDAP object to delete/drop
|
||||||
"""
|
"""
|
||||||
try:
|
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')
|
log.debug('Just-try mode : do not really drop object in LDAP')
|
||||||
return True
|
return True
|
||||||
assert self._conn or self.initialize()
|
assert self._conn or self.initialize()
|
||||||
|
|
Loading…
Reference in a new issue