mirror of https://gitee.com/bigwinds/arangodb
More consistent config/deps output in Foxx API (devel) (#3792)
* Correctly expose parsed/raw config This makes accessing the configuration more consistent by distinguishing between the raw (assigned) and parsed (validated/default) values. Previously there was no way to recognise default values for unset config options and the "current" value did not actually reflect what the service sees. * Add minimal option to config/deps routes The default values are backwards compatible with the existing behaviour but can be overridden to consistently get more/less output. * Actually merge warnings into non-mininal response
This commit is contained in:
parent
054989cd41
commit
05d0c81d7d
|
@ -228,68 +228,98 @@ instanceRouter.use('/configuration', configRouter)
|
|||
.response(200, schemas.configs);
|
||||
|
||||
configRouter.get((req, res) => {
|
||||
res.json(req.service.getConfiguration());
|
||||
});
|
||||
res.json(req.service.getConfiguration(req.queryParams.minimal));
|
||||
})
|
||||
.queryParam('minimal', joi.boolean().default(false));
|
||||
|
||||
configRouter.patch((req, res) => {
|
||||
const warnings = FoxxManager.setConfiguration(req.service.mount, {
|
||||
configuration: req.body,
|
||||
replace: false
|
||||
});
|
||||
const values = req.service.getConfiguration(true);
|
||||
res.json({
|
||||
values,
|
||||
warnings
|
||||
});
|
||||
const values = req.service.getConfiguration(req.queryParams.minimal);
|
||||
if (req.queryParams.minimal) {
|
||||
res.json({values, warnings});
|
||||
} else {
|
||||
if (warnings) {
|
||||
for (const key of Object.keys(warnings)) {
|
||||
values[key].warning = warnings[key];
|
||||
}
|
||||
}
|
||||
res.json(values);
|
||||
}
|
||||
})
|
||||
.body(joi.object().required());
|
||||
.body(joi.object().required())
|
||||
.queryParam('minimal', joi.boolean().default(true));
|
||||
|
||||
configRouter.put((req, res) => {
|
||||
const warnings = FoxxManager.setConfiguration(req.service.mount, {
|
||||
configuration: req.body,
|
||||
replace: true
|
||||
});
|
||||
const values = req.service.getConfiguration(true);
|
||||
res.json({
|
||||
values,
|
||||
warnings
|
||||
});
|
||||
const values = req.service.getConfiguration(req.queryParams.minimal);
|
||||
if (req.queryParams.minimal) {
|
||||
res.json({values, warnings});
|
||||
} else {
|
||||
if (warnings) {
|
||||
for (const key of Object.keys(warnings)) {
|
||||
values[key].warning = warnings[key];
|
||||
}
|
||||
}
|
||||
res.json(values);
|
||||
}
|
||||
})
|
||||
.body(joi.object().required());
|
||||
.body(joi.object().required())
|
||||
.queryParam('minimal', joi.boolean().default(true));
|
||||
|
||||
const depsRouter = createRouter();
|
||||
instanceRouter.use('/dependencies', depsRouter)
|
||||
.response(200, schemas.deps);
|
||||
|
||||
depsRouter.get((req, res) => {
|
||||
res.json(req.service.getDependencies());
|
||||
});
|
||||
res.json(req.service.getDependencies(req.queryParams.minimal));
|
||||
})
|
||||
.queryParam('minimal', joi.boolean().default(false));
|
||||
|
||||
depsRouter.patch((req, res) => {
|
||||
const warnings = FoxxManager.setDependencies(req.service.mount, {
|
||||
dependencies: req.body,
|
||||
replace: true
|
||||
});
|
||||
const values = req.service.getDependencies(true);
|
||||
res.json({
|
||||
values,
|
||||
warnings
|
||||
});
|
||||
const values = req.service.getDependencies(req.queryParams.minimal);
|
||||
if (req.queryParams.minimal) {
|
||||
res.json({values, warnings});
|
||||
} else {
|
||||
if (warnings) {
|
||||
for (const key of Object.keys(warnings)) {
|
||||
values[key].warning = warnings[key];
|
||||
}
|
||||
}
|
||||
res.json(values);
|
||||
}
|
||||
})
|
||||
.body(joi.object().required());
|
||||
.body(joi.object().required())
|
||||
.queryParam('minimal', joi.boolean().default(true));
|
||||
|
||||
depsRouter.put((req, res) => {
|
||||
const warnings = FoxxManager.setDependencies(req.service.mount, {
|
||||
dependencies: req.body,
|
||||
replace: true
|
||||
});
|
||||
const values = req.service.getDependencies(true);
|
||||
res.json({
|
||||
values,
|
||||
warnings
|
||||
});
|
||||
const values = req.service.getDependencies(req.queryParams.minimal);
|
||||
if (req.queryParams.minimal) {
|
||||
res.json({values, warnings});
|
||||
} else {
|
||||
if (warnings) {
|
||||
for (const key of Object.keys(warnings)) {
|
||||
values[key].warning = warnings[key];
|
||||
}
|
||||
}
|
||||
res.json(values);
|
||||
}
|
||||
})
|
||||
.body(joi.object().required());
|
||||
.body(joi.object().required())
|
||||
.queryParam('minimal', joi.boolean().default(true));
|
||||
|
||||
const devRouter = createRouter();
|
||||
instanceRouter.use('/development', devRouter)
|
||||
|
|
|
@ -463,12 +463,13 @@ module.exports =
|
|||
getConfiguration (simple) {
|
||||
const config = {};
|
||||
const definitions = this.manifest.configuration;
|
||||
const options = this._configuration;
|
||||
const options = this.configuration;
|
||||
for (const name of Object.keys(definitions)) {
|
||||
const dfn = definitions[name];
|
||||
const value = options[name] === undefined ? dfn.default : options[name];
|
||||
config[name] = simple ? value : Object.assign({}, dfn, {
|
||||
title: getReadableName(name),
|
||||
currentRaw: this._configuration[name],
|
||||
current: value
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue