-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Server-side create/update ingest pipelines (#62744)
- Loading branch information
1 parent
a841441
commit 7de73c8
Showing
13 changed files
with
386 additions
and
8 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
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
83 changes: 83 additions & 0 deletions
83
x-pack/plugins/ingest_pipelines/server/routes/api/create.ts
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,83 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import { i18n } from '@kbn/i18n'; | ||
import { schema } from '@kbn/config-schema'; | ||
|
||
import { Pipeline } from '../../../common/types'; | ||
import { API_BASE_PATH } from '../../../common/constants'; | ||
import { RouteDependencies } from '../../types'; | ||
|
||
const bodySchema = schema.object({ | ||
name: schema.string(), | ||
description: schema.string(), | ||
processors: schema.arrayOf(schema.recordOf(schema.string(), schema.any())), | ||
version: schema.maybe(schema.number()), | ||
onFailure: schema.maybe(schema.arrayOf(schema.recordOf(schema.string(), schema.any()))), | ||
}); | ||
|
||
export const registerCreateRoute = ({ | ||
router, | ||
license, | ||
lib: { isEsError }, | ||
}: RouteDependencies): void => { | ||
router.put( | ||
{ | ||
path: API_BASE_PATH, | ||
validate: { | ||
body: bodySchema, | ||
}, | ||
}, | ||
license.guardApiRoute(async (ctx, req, res) => { | ||
const { callAsCurrentUser } = ctx.core.elasticsearch.dataClient; | ||
const pipeline = req.body as Pipeline; | ||
|
||
const { name, description, processors, version, onFailure } = pipeline; | ||
|
||
try { | ||
// Check that a pipeline with the same name doesn't already exist | ||
const pipelineByName = await callAsCurrentUser('ingest.getPipeline', { id: name }); | ||
|
||
if (pipelineByName[name]) { | ||
return res.conflict({ | ||
body: new Error( | ||
i18n.translate('xpack.ingestPipelines.createRoute.duplicatePipelineIdErrorMessage', { | ||
defaultMessage: "There is already a pipeline with name '{name}'.", | ||
values: { | ||
name, | ||
}, | ||
}) | ||
), | ||
}); | ||
} | ||
} catch (e) { | ||
// Silently swallow error | ||
} | ||
|
||
try { | ||
const response = await callAsCurrentUser('ingest.putPipeline', { | ||
id: name, | ||
body: { | ||
description, | ||
processors, | ||
version, | ||
on_failure: onFailure, | ||
}, | ||
}); | ||
|
||
return res.ok({ body: response }); | ||
} catch (error) { | ||
if (isEsError(error)) { | ||
return res.customError({ | ||
statusCode: error.statusCode, | ||
body: error, | ||
}); | ||
} | ||
|
||
return res.internalError({ body: error }); | ||
} | ||
}) | ||
); | ||
}; |
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
70 changes: 70 additions & 0 deletions
70
x-pack/plugins/ingest_pipelines/server/routes/api/update.ts
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,70 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import { schema } from '@kbn/config-schema'; | ||
|
||
import { Pipeline } from '../../../common/types'; | ||
import { API_BASE_PATH } from '../../../common/constants'; | ||
import { RouteDependencies } from '../../types'; | ||
|
||
const bodySchema = schema.object({ | ||
description: schema.string(), | ||
processors: schema.arrayOf(schema.recordOf(schema.string(), schema.any())), | ||
version: schema.maybe(schema.number()), | ||
onFailure: schema.maybe(schema.arrayOf(schema.recordOf(schema.string(), schema.any()))), | ||
}); | ||
|
||
const paramsSchema = schema.object({ | ||
name: schema.string(), | ||
}); | ||
|
||
export const registerUpdateRoute = ({ | ||
router, | ||
license, | ||
lib: { isEsError }, | ||
}: RouteDependencies): void => { | ||
router.put( | ||
{ | ||
path: `${API_BASE_PATH}/{name}`, | ||
validate: { | ||
body: bodySchema, | ||
params: paramsSchema, | ||
}, | ||
}, | ||
license.guardApiRoute(async (ctx, req, res) => { | ||
const { callAsCurrentUser } = ctx.core.elasticsearch.dataClient; | ||
const { name } = req.params; | ||
const pipeline = req.body as Pipeline; | ||
|
||
const { description, processors, version, onFailure } = pipeline; | ||
|
||
try { | ||
// Verify pipeline exists; ES will throw 404 if it doesn't | ||
await callAsCurrentUser('ingest.getPipeline', { id: name }); | ||
|
||
const response = await callAsCurrentUser('ingest.putPipeline', { | ||
id: name, | ||
body: { | ||
description, | ||
processors, | ||
version, | ||
on_failure: onFailure, | ||
}, | ||
}); | ||
|
||
return res.ok({ body: response }); | ||
} catch (error) { | ||
if (isEsError(error)) { | ||
return res.customError({ | ||
statusCode: error.statusCode, | ||
body: error, | ||
}); | ||
} | ||
|
||
return res.internalError({ body: error }); | ||
} | ||
}) | ||
); | ||
}; |
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
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
12 changes: 12 additions & 0 deletions
12
x-pack/test/api_integration/apis/management/ingest_pipelines/index.ts
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,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import { FtrProviderContext } from '../../../ftr_provider_context'; | ||
|
||
export default function({ loadTestFile }: FtrProviderContext) { | ||
describe('Ingest Node Pipelines', () => { | ||
loadTestFile(require.resolve('./ingest_pipelines')); | ||
}); | ||
} |
Oops, something went wrong.