librenms/LibreNMS/config.py
Nash Kaminski 9bb6b19832
Support for SSL/TLS protected connections to MySQL databases (#14142)
* Allow configuration of the SSL/TLS operating mode when connecting to a mysql database

* Support SSL/TLS DB connections in the dispatcher service as well

* Apply black formatting standards to Python files

* Suppress pylint errors as redis module is not installed when linting

* More pylint fixes

* Correct typo in logging output

* Refactor SSL/TLS changes into DBConfig class instead of ServiceConfig

* Define DB config variables as class vars instead of instance vars

* Break circular import
2022-08-07 14:53:29 -05:00

24 lines
683 B
Python

class DBConfig:
"""
Bare minimal config class for LibreNMS.DB class usage
"""
# Start with defaults and override
db_host = "localhost"
db_port = 0
db_socket = None
db_user = "librenms"
db_pass = ""
db_name = "librenms"
db_sslmode = "disabled"
db_ssl_ca = "/etc/ssl/certs/ca-certificates.crt"
def populate(self, _config):
for key, val in _config.items():
if key == "db_port":
# Special case: port number
self.db_port = int(val)
elif key.startswith("db_"):
# Prevent prototype pollution by enforcing prefix
setattr(DBConfig, key, val)