-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix possibility of Rails secret key not being set from config file.
Basically, after the changes in c65ea2f, this accidentally broke some other ordering issues when reading the config, so that if `cached_random_config_values.yml` contained a Rails secret token, and any other cached values were being generated, then the cached values would always take precedent. This fixes it by ensuring that any existing config should always take precedent over the cached config that's being generated. 18F/api.data.gov#437
- Loading branch information
Showing
2 changed files
with
41 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
local is_array = require "api-umbrella.utils.is_array" | ||
|
||
-- Like deep_merge_overwrite_arrays, but only assigns values from the source to | ||
-- the destination if the destination is nil. So any existing values on the | ||
-- destination object will be retained. | ||
local function deep_defaults(dest, src) | ||
if not src then return dest end | ||
|
||
for key, value in pairs(src) do | ||
if type(value) == "table" and type(dest[key]) == "table" then | ||
if is_array(value) or is_array(dest[key]) then | ||
if dest[key] == nil then | ||
dest[key] = value | ||
end | ||
else | ||
deep_defaults(dest[key], src[key]) | ||
end | ||
else | ||
if dest[key] == nil then | ||
dest[key] = value | ||
end | ||
end | ||
end | ||
|
||
return dest | ||
end | ||
|
||
return deep_defaults |