Skip to content

Commit

Permalink
Fix overriding null configuration options in default.yml.
Browse files Browse the repository at this point in the history
Null values in default.yml were being treated as a special null type by
lyaml, which was preventing overrides from actually overriding the
null type. This prevented the omniauth-ldap and omniauth-cas options
from being set (see
#278 (comment))
  • Loading branch information
GUI committed Sep 14, 2016
1 parent 917ddf6 commit d8c5f74
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/api-umbrella/cli/read_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ local function read_runtime_config()
f:close()

config = lyaml.load(content)
nillify_yaml_nulls(config)
end
end

Expand All @@ -110,6 +111,7 @@ end
local function read_default_config()
local content = file.read(path.join(src_root_dir, "config/default.yml"), true)
config = lyaml.load(content)
nillify_yaml_nulls(config)
end

-- Handle setup of random secret tokens that should be be unique for API
Expand Down Expand Up @@ -159,6 +161,7 @@ local function read_system_config()
if content then
local overrides = lyaml.load(content)
deep_merge_overwrite_arrays(config, overrides)
nillify_yaml_nulls(config)
end
else
print("WARNING: Config file does not exist: ", config_path)
Expand Down
5 changes: 3 additions & 2 deletions src/api-umbrella/proxy/models/file_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ local function read_file()
local content = f:read("*all")
f:close()

return lyaml.load(content)
local data = lyaml.load(content)
nillify_yaml_nulls(data)
return data
end

local function set_defaults(data)
Expand Down Expand Up @@ -78,7 +80,6 @@ end

local function read()
local data = read_file()
nillify_yaml_nulls(data)
set_defaults(data)
cache_computed_settings(data["apiSettings"])

Expand Down
35 changes: 35 additions & 0 deletions test/integration/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

require('../test_helper');

var fs = require('fs'),
path = require('path'),
yaml = require('js-yaml');

describe('config', function() {
describe('overriding null values', function() {
shared.runServer({
web: {
admin: {
auth_strategies: {
ldap: {
options: {
host: 'example.com',
}
},
},
},
},
});

it('overrides a default null value', function() {
var defaultConfig = yaml.safeLoad(fs.readFileSync(path.resolve(__dirname, '../../config/default.yml')).toString());
var runtimeConfig = yaml.safeLoad(fs.readFileSync('/tmp/api-umbrella-test/var/run/runtime_config.yml').toString());

should.not.exist(defaultConfig.web.admin.auth_strategies.ldap.options);
runtimeConfig.web.admin.auth_strategies.ldap.options.should.eql({
host: 'example.com',
});
});
});
});

0 comments on commit d8c5f74

Please sign in to comment.