mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
ML] Fixes bug in module setup endpoint caused by PR 30935 (#34414)
* [ML] Fixes module setup endpoint * tweaks endpoint to allow trailing slash
This commit is contained in:
parent
5c457972d4
commit
3930c36898
2 changed files with 19 additions and 11 deletions
|
@ -267,15 +267,12 @@ export class DataRecognizer {
|
|||
|
||||
// load the config from disk
|
||||
const moduleConfig = await this.getModule(moduleId, jobPrefix);
|
||||
const manifestFile = await this.getManifestFile(moduleId);
|
||||
|
||||
if (indexPatternName === undefined &&
|
||||
manifestFile && manifestFile.json &&
|
||||
manifestFile.json.defaultIndexPattern === undefined) {
|
||||
if (indexPatternName === undefined && moduleConfig.defaultIndexPattern === undefined) {
|
||||
|
||||
throw Boom.badRequest(`No index pattern configured in "${moduleId}" configuration file and no index pattern passed to the endpoint`);
|
||||
}
|
||||
this.indexPatternName = (indexPatternName === undefined) ? manifestFile.json.defaultIndexPattern : indexPatternName;
|
||||
this.indexPatternName = (indexPatternName === undefined) ? moduleConfig.defaultIndexPattern : indexPatternName;
|
||||
this.indexPatternId = this.getIndexPatternId(this.indexPatternName);
|
||||
|
||||
// create an empty results object
|
||||
|
@ -573,6 +570,12 @@ export class DataRecognizer {
|
|||
// listing each job/datafeed/savedObject with a save success boolean
|
||||
createResultsTemplate(moduleConfig) {
|
||||
const results = {};
|
||||
const reducedConfig = {
|
||||
jobs: moduleConfig.jobs,
|
||||
datafeeds: moduleConfig.datafeeds,
|
||||
kibana: moduleConfig.kibana,
|
||||
};
|
||||
|
||||
function createResultsItems(configItems, resultItems, index) {
|
||||
resultItems[index] = [];
|
||||
configItems.forEach((j) => {
|
||||
|
@ -583,13 +586,13 @@ export class DataRecognizer {
|
|||
});
|
||||
}
|
||||
|
||||
Object.keys(moduleConfig).forEach((i) => {
|
||||
if (Array.isArray(moduleConfig[i])) {
|
||||
createResultsItems(moduleConfig[i], results, i);
|
||||
Object.keys(reducedConfig).forEach((i) => {
|
||||
if (Array.isArray(reducedConfig[i])) {
|
||||
createResultsItems(reducedConfig[i], results, i);
|
||||
} else {
|
||||
results[i] = {};
|
||||
Object.keys(moduleConfig[i]).forEach((k) => {
|
||||
createResultsItems(moduleConfig[i][k], results[i], k);
|
||||
Object.keys(reducedConfig[i]).forEach((k) => {
|
||||
createResultsItems(reducedConfig[i][k], results[i], k);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -73,7 +73,12 @@ export function dataRecognizer(server, commonRouteConfig) {
|
|||
path: '/api/ml/modules/get_module/{moduleId?}',
|
||||
handler(request) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const moduleId = request.params.moduleId;
|
||||
let moduleId = request.params.moduleId;
|
||||
if (moduleId === '') {
|
||||
// if the endpoint is called with a trailing /
|
||||
// the moduleId will be an empty string.
|
||||
moduleId = undefined;
|
||||
}
|
||||
return getModule(callWithRequest, moduleId)
|
||||
.catch(resp => wrapError(resp));
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue