Skip to content

Commit ffaba39

Browse files
committed
ADD support to ENV DATABASE_ALIAS_PSWD_FILE.
Allows to deploy applications with file secrets in docker containers.
1 parent 41b63cc commit ffaba39

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/ConnectParams.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,22 @@ public static function fromEnv(string $alias, ?array $env = null)
4444
$hostKey = "DATABASE_{$alias}_HOST";
4545
$portKey = "DATABASE_{$alias}_PORT";
4646
$userKey = "DATABASE_{$alias}_USER";
47-
$pswdKey = "DATABASE_{$alias}_PSWD";
4847
$nameKey = "DATABASE_{$alias}_NAME";
4948
$encdKey = "DATABASE_{$alias}_ENCD";
49+
$pswdKey = "DATABASE_{$alias}_PSWD";
50+
$pwflKey = "DATABASE_{$alias}_PSWD_FILE";
5051

5152
$host = $env[$hostKey] ?? $driver->getDefaultHost();
5253
$port = $env[$portKey] ?? $driver->getDefaultPort();
5354
$user = $env[$userKey] ?? $driver->getDefaultUser();
54-
$pswd = $env[$pswdKey] ?? $driver->getDefaultPswd();
5555
$name = $env[$nameKey] ?? $alias;
5656
$encd = $env[$encdKey] ?? null;
5757

58+
$pswd = $env[$pswdKey] ?? $driver->getDefaultPswd();
59+
if (!empty($env[$pwflKey]) && file_exists($env[$pwflKey])) {
60+
$pswd = file_get_contents($env[$pwflKey]);
61+
}
62+
5863
return new ConnectParams($driver, $host, $user, $pswd, $name, $port, $encd);
5964
}
6065

0 commit comments

Comments
 (0)