Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(config): Add missing handling for envCache in getKeys()
NC_ env variable overrides were not appearing in
the output of `occ config:list system` nor `occ
config:system:get xxx`. This was creating nearly
impossible to diagnose configuration/ behavior
disprepancies.

- Refactored readData() so that we aren't saving
  the entire environment in the envCache anymore
  (only those prefixed "NC_") and so that we save
  NC_ provided config values under their real
  key.
- Refactored getValue() to accommodate readData()
  refactor
- Fixed getKeys() to properly return
  envCache keys too

Environment provided config variables now appear
in `occ config:list system` as expected.

Environment provided config variables now appear
when queried via `occ config:system:get KEY`

envCache is now free of non-NC stuff.

Signed-off-by: Josh Richards <[email protected]>
  • Loading branch information
joshtrichards authored and backportbot[bot] committed Sep 16, 2024
commit 4b9a74658dddae9bdd1757f5a88f932316c21cd0
17 changes: 12 additions & 5 deletions lib/private/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function __construct($configDir, $fileName = 'config.php') {
* @return array an array of key names
*/
public function getKeys() {
return array_keys($this->cache);
return array_merge(array_keys($this->cache), array_keys($this->envCache));
}

/**
Expand All @@ -95,9 +95,8 @@ public function getKeys() {
* @return mixed the value or $default
*/
public function getValue($key, $default = null) {
$envKey = self::ENV_PREFIX . $key;
if (isset($this->envCache[$envKey])) {
return $this->envCache[$envKey];
if (isset($this->envCache[$key])) {
return $this->envCache[$key];
}

if (isset($this->cache[$key])) {
Expand Down Expand Up @@ -257,7 +256,15 @@ private function readData() {
}
}

$this->envCache = getenv();
// grab any "NC_" environment variables
$envRaw = getenv();
// only save environment variables prefixed with "NC_" in the cache
foreach ($envRaw as $rawEnvKey => $rawEnvValue) {
if (str_starts_with($rawEnvKey, self::ENV_PREFIX)) {
$realKey = explode(self::ENV_PREFIX, $rawEnvKey)[1];
$this->envCache[$realKey] = $rawEnvValue;
}
}
}

/**
Expand Down