22
22
from urllib .parse import urlparse
23
23
24
24
from tornado .concurrent import run_on_executor
25
- from traitlets import Any , Bool , List , Unicode , default
25
+ from traitlets import Any , Dict , Unicode , default
26
26
27
27
from .kv_proxy import TKvProxy
28
+ from .traefik_utils import deep_merge
28
29
29
30
30
31
class TraefikEtcdProxy (TKvProxy ):
@@ -34,42 +35,9 @@ class TraefikEtcdProxy(TKvProxy):
34
35
35
36
provider_name = "etcd"
36
37
37
- etcd_client_ca_cert = Unicode (
38
+ etcd_client_kwargs = Dict (
38
39
config = True ,
39
- allow_none = True ,
40
- default_value = None ,
41
- help = """Etcd client root certificates""" ,
42
- )
43
-
44
- etcd_client_cert_crt = Unicode (
45
- config = True ,
46
- allow_none = True ,
47
- default_value = None ,
48
- help = """Etcd client certificate chain
49
- (etcd_client_cert_key must also be specified)""" ,
50
- )
51
-
52
- etcd_client_cert_key = Unicode (
53
- config = True ,
54
- allow_none = True ,
55
- default_value = None ,
56
- help = """Etcd client private key
57
- (etcd_client_cert_crt must also be specified)""" ,
58
- )
59
-
60
- # The grpc client (used by the Python etcd library) doesn't allow untrusted
61
- # etcd certificates, although traefik does allow them.
62
- etcd_insecure_skip_verify = Bool (
63
- False ,
64
- config = True ,
65
- help = """Traefik will by default validate SSL certificate of etcd backend""" ,
66
- )
67
-
68
- grpc_options = List (
69
- config = True ,
70
- allow_none = True ,
71
- default_value = None ,
72
- help = """Any grpc options that need to be passed to the etcd client""" ,
40
+ help = """Extra keyword arguments to pass to the etcd Python client constructor""" ,
73
41
)
74
42
75
43
@default ("executor" )
@@ -120,10 +88,6 @@ def _default_client(self):
120
88
kwargs = {
121
89
'host' : etcd_service .hostname ,
122
90
'port' : etcd_service .port ,
123
- 'ca_cert' : self .etcd_client_ca_cert ,
124
- 'cert_cert' : self .etcd_client_cert_crt ,
125
- 'cert_key' : self .etcd_client_cert_key ,
126
- 'grpc_options' : self .grpc_options ,
127
91
}
128
92
if self .etcd_password :
129
93
kwargs .update (
@@ -132,6 +96,8 @@ def _default_client(self):
132
96
"password" : self .etcd_password ,
133
97
}
134
98
)
99
+ if self .etcd_client_kwargs :
100
+ kwargs .update (self .etcd_client_kwargs )
135
101
return etcd3 .client (** kwargs )
136
102
137
103
def _cleanup (self ):
@@ -194,29 +160,22 @@ async def _kv_atomic_delete(self, *keys):
194
160
def _setup_traefik_static_config (self ):
195
161
self .log .debug ("Setting up the etcd provider in the static config" )
196
162
url = urlparse (self .etcd_url )
197
- self .static_config .update (
198
- {
199
- "providers" : {
200
- "etcd" : {
201
- "endpoints" : [url .netloc ],
202
- "rootKey" : self .kv_traefik_prefix ,
203
- }
204
- }
205
- }
206
- )
163
+ etcd_config = {
164
+ "endpoints" : [url .netloc ],
165
+ "rootKey" : self .kv_traefik_prefix ,
166
+ }
207
167
if url .scheme == "https" :
208
168
# If etcd is running over TLS, then traefik needs to know
209
- tls_conf = {}
210
- if self .etcd_client_ca_cert is not None :
211
- tls_conf ["ca" ] = self .etcd_client_ca_cert
212
- tls_conf ["insecureSkipVerify" ] = self .etcd_insecure_skip_verify
213
- self .static_config ["providers" ]["etcd" ]["tls" ] = tls_conf
169
+ etcd_config ["tls" ] = {}
214
170
215
171
if self .etcd_username and self .etcd_password :
216
- self . static_config [ "providers" ][ "etcd" ] .update (
172
+ etcd_config .update (
217
173
{
218
174
"username" : self .etcd_username ,
219
175
"password" : self .etcd_password ,
220
176
}
221
177
)
178
+ self .static_config = deep_merge (
179
+ self .static_config , {"providers" : {"etcd" : etcd_config }}
180
+ )
222
181
return super ()._setup_traefik_static_config ()
0 commit comments