mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Remove legacy db config (#16385)
* Remove legacy db config Should be configured via the environment or .env. * Lint fix * Remove call to removed method
This commit is contained in:
@ -478,9 +478,6 @@ class Config
|
||||
}
|
||||
|
||||
self::populateTime();
|
||||
|
||||
// populate legacy DB credentials, just in case something external uses them. Maybe remove this later
|
||||
self::populateLegacyDbCredentials();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -561,18 +558,6 @@ class Config
|
||||
self::set('time.twoyear', $now - 63072000); // time() - (2 * 365 * 24 * 60 * 60);
|
||||
}
|
||||
|
||||
public static function populateLegacyDbCredentials()
|
||||
{
|
||||
$db = config('database.default');
|
||||
|
||||
self::set('db_host', config("database.connections.$db.host", 'localhost'));
|
||||
self::set('db_name', config("database.connections.$db.database", 'librenms'));
|
||||
self::set('db_user', config("database.connections.$db.username", 'librenms'));
|
||||
self::set('db_pass', config("database.connections.$db.password"));
|
||||
self::set('db_port', config("database.connections.$db.port", 3306));
|
||||
self::set('db_socket', config("database.connections.$db.unix_socket"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the config has been loaded yet
|
||||
*
|
||||
|
@ -1,3 +1,6 @@
|
||||
import os
|
||||
|
||||
|
||||
class DBConfig:
|
||||
"""
|
||||
Bare minimal config class for LibreNMS.DB class usage
|
||||
@ -14,10 +17,17 @@ class DBConfig:
|
||||
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)
|
||||
self.db_host = os.getenv("DB_HOST", _config.get("db_host", self.db_host))
|
||||
self.db_name = os.getenv("DB_DATABASE", _config.get("db_name", self.db_name))
|
||||
self.db_pass = os.getenv("DB_PASSWORD", _config.get("db_pass", self.db_pass))
|
||||
self.db_port = int(os.getenv("DB_PORT", _config.get("db_port", self.db_port)))
|
||||
self.db_socket = os.getenv(
|
||||
"DB_SOCKET", _config.get("db_socket", self.db_socket)
|
||||
)
|
||||
self.db_user = os.getenv("DB_USERNAME", _config.get("db_user", self.db_user))
|
||||
self.db_sslmode = os.getenv(
|
||||
"DB_SSLMODE", _config.get("db_sslmode", self.db_sslmode)
|
||||
)
|
||||
self.db_ssl_ca = os.getenv(
|
||||
"MYSQL_ATTR_SSL_CA", _config.get("db_ssl_ca", self.db_ssl_ca)
|
||||
)
|
||||
|
@ -13,8 +13,5 @@ $init_modules = ['nodb'];
|
||||
require __DIR__ . '/includes/init.php';
|
||||
|
||||
if (App::runningInConsole()) {
|
||||
// fill in db variables for legacy external scripts
|
||||
Config::populateLegacyDbCredentials();
|
||||
|
||||
echo Config::toJson();
|
||||
}
|
||||
|
Reference in New Issue
Block a user