1
0
mirror of https://github.com/thingsboard/thingsboard-gateway synced 2025-10-26 22:31:42 +08:00

Added cert config params to tb_gateway.yaml

This commit is contained in:
samson0v
2022-10-24 11:44:22 +03:00
parent bb5419439b
commit 70750dcb10

View File

@@ -27,9 +27,6 @@ except ImportError:
log = logging.getLogger("tb_connection")
CHECK_CERT_PERIOD = 86400
CERTIFICATE_DAYS_LEFT = 3
class TBClient(threading.Thread):
def __init__(self, config, config_folder_path):
@@ -67,6 +64,8 @@ class TBClient(threading.Thread):
self.__ca_cert = self.__config_folder_path + credentials.get("caCert") if credentials.get("caCert") is not None else None
self.__private_key = self.__config_folder_path + credentials.get("privateKey") if credentials.get("privateKey") is not None else None
self.__cert = self.__config_folder_path + credentials.get("cert") if credentials.get("cert") is not None else None
self.__check_cert_period = credentials.get('checkCertPeriod', 86400)
self.__certificate_days_left = credentials.get('certificateDaysLeft', 3)
# check certificates for end date
self._check_cert_thread = threading.Thread(name='Check Certificates Thread',
@@ -96,18 +95,18 @@ class TBClient(threading.Thread):
def _check_certificates(self):
while not self.__stopped and not self.__paused:
if time() - self._last_cert_check_time >= CHECK_CERT_PERIOD:
if time() - self._last_cert_check_time >= self.__check_cert_period:
if self.__cert:
log.info('Will generate new certificate')
new_cert = TBUtility.check_certificate(self.__cert, key=self.__private_key,
days_left=CERTIFICATE_DAYS_LEFT)
days_left=self.__certificate_days_left)
if new_cert:
self.client.send_attributes({'newCertificate': new_cert})
if self.__ca_cert:
is_outdated = TBUtility.check_certificate(self.__ca_cert, generate_new=False,
days_left=CERTIFICATE_DAYS_LEFT)
days_left=self.__certificate_days_left)
if is_outdated:
self.client.send_attributes({'CACertificate': 'CA certificate will outdated soon'})