Skip to content

Commit

Permalink
Merge pull request #2227 from shlinkio/develop
Browse files Browse the repository at this point in the history
Release 4.2.3
  • Loading branch information
acelaya authored Oct 17, 2024
2 parents fa7969c + 615b443 commit 51de4b1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

## [4.2.3] - 2024-10-17
### Added
* *Nothing*

### Changed
* *Nothing*

### Deprecated
* *Nothing*

### Removed
* *Nothing*

### Fixed
* [#2225](https://github.com/shlinkio/shlink/issues/2225) Fix regression introduced in v4.2.2, making config options with `null` value to be promoted as env vars with value `''`, instead of being skipped.


## [4.2.2] - 2024-10-14
### Added
* *Nothing*
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"ramsey/uuid": "^4.7",
"shlinkio/doctrine-specification": "^2.1.1",
"shlinkio/shlink-common": "^6.3",
"shlinkio/shlink-config": "^3.2",
"shlinkio/shlink-config": "^3.2.1",
"shlinkio/shlink-event-dispatcher": "^4.1",
"shlinkio/shlink-importer": "^5.3.2",
"shlinkio/shlink-installer": "^9.2",
Expand Down
34 changes: 17 additions & 17 deletions module/Core/src/Config/EnvVars.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,23 @@ public function loadFromEnv(): mixed
return env($this->value) ?? $this->loadFromFileEnv() ?? $this->defaultValue();
}

/**
* Checks if an equivalent environment variable exists with the `_FILE` suffix. If so, it loads its value as a file,
* reads it, and returns its contents.
* This is useful when loading Shlink with docker compose and using secrets.
* See https://docs.docker.com/compose/use-secrets/
*/
private function loadFromFileEnv(): string|int|bool|null
{
$file = env(sprintf('%s_FILE', $this->value));
if ($file === null || ! is_file($file)) {
return null;
}

$content = file_get_contents($file);
return $content ? parseEnvVar($content) : null;
}

private function defaultValue(): string|int|bool|null
{
return match ($this) {
Expand Down Expand Up @@ -153,23 +170,6 @@ private function defaultValue(): string|int|bool|null
};
}

/**
* Checks if an equivalent environment variable exists with the `_FILE` suffix. If so, it loads its value as a file,
* reads it, and returns its contents.
* This is useful when loading Shlink with docker compose and using secrets.
* See https://docs.docker.com/compose/use-secrets/
*/
private function loadFromFileEnv(): string|int|bool|null
{
$file = env(sprintf('%s_FILE', $this->value));
if ($file === null || ! is_file($file)) {
return null;
}

$content = file_get_contents($file);
return $content ? parseEnvVar($content) : null;
}

public function existsInEnv(): bool
{
return $this->loadFromEnv() !== null;
Expand Down

0 comments on commit 51de4b1

Please sign in to comment.