Reload Consul config on SIGHUP
It is especially useful when somebody is changing the value of `token`
@@ -122,7 +122,7 @@ class ConsulClient(base.Consul):
def __init__(self, *args, **kwargs):
self._cert = kwargs.pop('cert', None)
self._ca_cert = kwargs.pop('ca_cert', None)
- self._token = kwargs.get('token')
+ self.token = kwargs.get('token')
super(ConsulClient, self).__init__(*args, **kwargs)
def connect(self, *args, **kwargs):
@@ -131,10 +131,14 @@ class ConsulClient(base.Consul):
kwargs['cert'] = self._cert
if self._ca_cert:
kwargs['ca_cert'] = self._ca_cert
- if self._token:
- kwargs['token'] = self._token
+ if self.token:
+ kwargs['token'] = self.token
return HTTPClient(**kwargs)
+ def set_token(self, token):
+ self.token = token
+ self.http.token = self.token
+
def catch_consul_errors(func):
def wrapper(*args, **kwargs):
@@ -232,6 +236,13 @@ class Consul(AbstractDCS):
logger.info('waiting on consul')
time.sleep(5)
+ def reload_config(self, config):
+ consul = config.get('consul')
+ if consul:
+ self._client.set_token(consul.get('token'))
+
+ super(Consul, self).reload_config(config)
+
def set_ttl(self, ttl):
if self._client.http.set_ttl(ttl/2.0): # Consul multiplies the TTL by 2x
self._session = None
