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
|
<?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(
|
$aConfig = array(
|
||||||
'host' => '127.0.0.1',
|
'host' => getenv('LW_DB_HOST') ?: '127.0.0.1',
|
||||||
'database' => 'legacyworlds',
|
'database' => getenv('LW_DB_NAME') ?: 'legacyworlds',
|
||||||
'user' => 'legacyworlds',
|
'user' => getenv('LW_DB_USER_NAME') ?: 'legacyworlds',
|
||||||
'password' => 'password for the standard database user',
|
'password' => readSecret('LW_DB_USER_PASS'),
|
||||||
'adminUser' => 'legacyworlds_admin',
|
'adminUser' => getenv('LW_DB_ADMIN_NAME') ?: 'legacyworlds_admin',
|
||||||
'adminPassword' => 'password for the administrative database user',
|
'adminPassword' => readSecret('LW_DB_ADMIN_PASS'),
|
||||||
'ctrlFifo' =>'/tmp/.lwFifo',
|
'ctrlFifo' =>'/tmp/.lwFifo',
|
||||||
'ctrlPath' =>'/tmp/.lwControl'
|
'ctrlPath' =>'/tmp/.lwControl'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
function __dbConnect($admin = false) {
|
function __dbConnect(bool $admin = false): \PgSql\Connection|bool {
|
||||||
global $aConfig;
|
global $aConfig;
|
||||||
$h = $aConfig['host'];
|
$h = $aConfig['host'];
|
||||||
$d = $aConfig['database'];
|
$d = $aConfig['database'];
|
||||||
|
|
Loading…
Add table
Reference in a new issue