feat: read most of the admin config from env vars
This commit is contained in:
parent
de7ed2a996
commit
bc5a70c4c6
1 changed files with 25 additions and 7 deletions
|
@ -1,18 +1,36 @@
|
|||
<?php
|
||||
|
||||
|
||||
function readSecret(string $varName): string {
|
||||
$fileVarName = $varName . '_FILE';
|
||||
$fileName = getenv($fileVarName);
|
||||
if ($fileName !== false) {
|
||||
$value = @file_get_contents($fileName);
|
||||
if ($value === false) {
|
||||
throw new \Exception("Could not read secret from file $fileName");
|
||||
}
|
||||
} else {
|
||||
$value = getenv($varName);
|
||||
if ($value === false) {
|
||||
throw new \Exception("Could not read secret from variable $varName");
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
$aConfig = array(
|
||||
'host' => '127.0.0.1',
|
||||
'database' => 'legacyworlds',
|
||||
'user' => 'legacyworlds',
|
||||
'password' => 'password for the standard database user',
|
||||
'adminUser' => 'legacyworlds_admin',
|
||||
'adminPassword' => 'password for the administrative database user',
|
||||
'host' => getenv('LW_DB_HOST') ?: '127.0.0.1',
|
||||
'database' => getenv('LW_DB_NAME') ?: 'legacyworlds',
|
||||
'user' => getenv('LW_DB_USER_NAME') ?: 'legacyworlds',
|
||||
'password' => readSecret('LW_DB_USER_PASS'),
|
||||
'adminUser' => getenv('LW_DB_ADMIN_NAME') ?: 'legacyworlds_admin',
|
||||
'adminPassword' => readSecret('LW_DB_ADMIN_PASS'),
|
||||
'ctrlFifo' =>'/tmp/.lwFifo',
|
||||
'ctrlPath' =>'/tmp/.lwControl'
|
||||
);
|
||||
|
||||
|
||||
function __dbConnect($admin = false) {
|
||||
function __dbConnect(bool $admin = false): \PgSql\Connection|bool {
|
||||
global $aConfig;
|
||||
$h = $aConfig['host'];
|
||||
$d = $aConfig['database'];
|
||||
|
|
Loading…
Reference in a new issue