mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-22 08:56:42 -06:00
Merge pull request #2062 from acelaya-forks/feature/string-db-credentials
Feature/string db credentials
This commit is contained in:
commit
74180a4381
17
CHANGELOG.md
17
CHANGELOG.md
@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.
|
|||||||
|
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).
|
The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
### Added
|
||||||
|
* *Nothing*
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
* *Nothing*
|
||||||
|
|
||||||
|
### Deprecated
|
||||||
|
* *Nothing*
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
* *Nothing*
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
* [#2058](https://github.com/shlinkio/shlink/issues/2058) Fix DB credentials provided as env vars being casted to `int` if they include only numbers.
|
||||||
|
|
||||||
|
|
||||||
## [4.0.2] - 2024-03-09
|
## [4.0.2] - 2024-03-09
|
||||||
### Added
|
### Added
|
||||||
* *Nothing*
|
* *Nothing*
|
||||||
|
@ -16,6 +16,10 @@ return (static function (): array {
|
|||||||
'mssql' => 'pdo_sqlsrv',
|
'mssql' => 'pdo_sqlsrv',
|
||||||
default => 'pdo_mysql',
|
default => 'pdo_mysql',
|
||||||
};
|
};
|
||||||
|
$readCredentialAsString = static function (EnvVars $envVar): string|null {
|
||||||
|
$value = $envVar->loadFromEnv();
|
||||||
|
return $value === null ? null : (string) $value;
|
||||||
|
};
|
||||||
$resolveDefaultPort = static fn () => match ($driver) {
|
$resolveDefaultPort = static fn () => match ($driver) {
|
||||||
'postgres' => '5432',
|
'postgres' => '5432',
|
||||||
'mssql' => '1433',
|
'mssql' => '1433',
|
||||||
@ -28,6 +32,7 @@ return (static function (): array {
|
|||||||
'postgres' => 'utf8',
|
'postgres' => 'utf8',
|
||||||
default => null,
|
default => null,
|
||||||
};
|
};
|
||||||
|
|
||||||
$resolveConnection = static fn () => match ($driver) {
|
$resolveConnection = static fn () => match ($driver) {
|
||||||
null, 'sqlite' => [
|
null, 'sqlite' => [
|
||||||
'driver' => 'pdo_sqlite',
|
'driver' => 'pdo_sqlite',
|
||||||
@ -36,8 +41,8 @@ return (static function (): array {
|
|||||||
default => [
|
default => [
|
||||||
'driver' => $resolveDriver(),
|
'driver' => $resolveDriver(),
|
||||||
'dbname' => EnvVars::DB_NAME->loadFromEnv('shlink'),
|
'dbname' => EnvVars::DB_NAME->loadFromEnv('shlink'),
|
||||||
'user' => EnvVars::DB_USER->loadFromEnv(),
|
'user' => $readCredentialAsString(EnvVars::DB_USER),
|
||||||
'password' => EnvVars::DB_PASSWORD->loadFromEnv(),
|
'password' => $readCredentialAsString(EnvVars::DB_PASSWORD),
|
||||||
'host' => EnvVars::DB_HOST->loadFromEnv(EnvVars::DB_UNIX_SOCKET->loadFromEnv()),
|
'host' => EnvVars::DB_HOST->loadFromEnv(EnvVars::DB_UNIX_SOCKET->loadFromEnv()),
|
||||||
'port' => EnvVars::DB_PORT->loadFromEnv($resolveDefaultPort()),
|
'port' => EnvVars::DB_PORT->loadFromEnv($resolveDefaultPort()),
|
||||||
'unix_socket' => $isMysqlCompatible ? EnvVars::DB_UNIX_SOCKET->loadFromEnv() : null,
|
'unix_socket' => $isMysqlCompatible ? EnvVars::DB_UNIX_SOCKET->loadFromEnv() : null,
|
||||||
|
Loading…
Reference in New Issue
Block a user