Skip to content

Commit f7f7a8c

Browse files
authored
Clean up some useless code (#119)
1 parent a3c7a9f commit f7f7a8c

File tree

1 file changed

+4
-31
lines changed

1 file changed

+4
-31
lines changed

ldap_auth_provider.py

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,19 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
import logging
17+
import ssl
1618
from typing import Optional
1719

20+
from pkg_resources import parse_version
1821
from twisted.internet import threads
1922

20-
2123
import ldap3
2224
import ldap3.core.exceptions
23-
24-
import ssl
25-
26-
import logging
2725
import synapse
2826

29-
from pkg_resources import parse_version
30-
31-
3227
__version__ = "0.1.4"
3328

34-
35-
try:
36-
import ldap3
37-
import ldap3.core.exceptions
38-
39-
# ldap3 v2 changed ldap3.AUTH_SIMPLE -> ldap3.SIMPLE
40-
try:
41-
LDAP_AUTH_SIMPLE = ldap3.AUTH_SIMPLE
42-
except AttributeError:
43-
LDAP_AUTH_SIMPLE = ldap3.SIMPLE
44-
except ImportError: # pragma: no cover
45-
ldap3 = None
46-
pass
47-
48-
4929
logger = logging.getLogger(__name__)
5030

5131

@@ -62,18 +42,11 @@ class LDAPMode(object):
6242

6343

6444
class LdapAuthProvider(object):
65-
__version__ = "0.1"
6645
_ldap_tls = ldap3.Tls(validate=ssl.CERT_REQUIRED)
6746

6847
def __init__(self, config, account_handler):
6948
self.account_handler = account_handler
7049

71-
if not ldap3: # pragma: no cover
72-
raise RuntimeError(
73-
'Missing ldap3 library. '
74-
'This is required for LDAP Authentication.'
75-
)
76-
7750
self.ldap_mode = config.mode
7851
self.ldap_uris = [config.uri] if isinstance(config.uri, str) else config.uri
7952
self.ldap_start_tls = config.start_tls
@@ -492,7 +465,7 @@ async def _ldap_simple_bind(self, server, bind_dn, password):
492465
conn = await threads.deferToThread(
493466
ldap3.Connection,
494467
server, bind_dn, password,
495-
authentication=LDAP_AUTH_SIMPLE,
468+
authentication=ldap3.SIMPLE,
496469
read_only=True,
497470
)
498471
logger.debug(

0 commit comments

Comments
 (0)