1
1
import inspect
2
2
import sys
3
- from typing import Any , cast , Optional
3
+ from typing import Any , Optional , cast
4
4
5
5
from twisted .internet import reactor , task
6
- from twisted .internet .endpoints import serverFromString , quoteStringArgument
6
+ from twisted .internet .endpoints import quoteStringArgument , serverFromString
7
7
from twisted .internet .interfaces import IReactorCore , IStreamServerEndpoint
8
8
from twisted .python import log
9
9
@@ -71,12 +71,18 @@ def __init__(
71
71
if self .debug :
72
72
log .msg ("Creating an LDAPServerFactory." )
73
73
factory = OAuthLDAPServerFactory (
74
- domain , oauth_client , background_refresh = background_refresh , enable_mirrored_groups = enable_mirrored_groups , refresh_interval = refresh_interval
74
+ domain ,
75
+ oauth_client ,
76
+ background_refresh = background_refresh ,
77
+ enable_mirrored_groups = enable_mirrored_groups ,
78
+ refresh_interval = refresh_interval ,
75
79
)
76
80
77
81
if background_refresh :
78
82
if self .debug :
79
- log .msg (f"Starting background refresh (interval={ factory .adaptor .refresh_interval } )" )
83
+ log .msg (
84
+ f"Starting background refresh (interval={ factory .adaptor .refresh_interval } )"
85
+ )
80
86
loop = task .LoopingCall (factory .adaptor .refresh )
81
87
loop .start (factory .adaptor .refresh_interval )
82
88
@@ -88,11 +94,18 @@ def __init__(
88
94
89
95
# Attach a listening endpoint
90
96
if tls_port :
91
- if not (tls_certificate or tls_private_key ):
92
- raise ValueError ("No TLS certificate or private key provided. Make sure you provide these parameters or disable TLS by not providing the TLS port" )
97
+ if not tls_certificate :
98
+ msg = "No TLS certificate provided. Please provide one with --tls-certificate or disable TLS by not providing the --tls-port argument."
99
+ raise ValueError (msg )
100
+ if not tls_private_key :
101
+ msg = "No TLS private key provided. Please provide one with --tls-private-key or disable TLS by not providing the --tls-port argument."
102
+ raise ValueError (msg )
93
103
if self .debug :
94
104
log .msg ("Attaching a listening endpoint (TLS)." )
95
- ssl_endpoint : IStreamServerEndpoint = serverFromString (reactor , f"ssl:{ tls_port } :privateKey={ quoteStringArgument (tls_private_key )} :certKey={ quoteStringArgument (tls_certificate )} " )
105
+ ssl_endpoint : IStreamServerEndpoint = serverFromString (
106
+ reactor ,
107
+ f"ssl:{ tls_port } :privateKey={ quoteStringArgument (tls_private_key )} :certKey={ quoteStringArgument (tls_certificate )} " ,
108
+ )
96
109
ssl_endpoint .listen (factory )
97
110
98
111
# Load the Twisted reactor
0 commit comments