-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create the ftrSoApis FTR plugin #149188
Create the ftrSoApis FTR plugin #149188
Changes from 13 commits
fceb917
90136ae
959f3fd
122916b
13db670
9384667
12c6470
87db010
1bf8ba1
6bfd5a5
1c829b5
74e2717
f24e7d4
63cafed
f9f1e1f
934fef3
46a9a6b
ab041e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# ftrApis plugin | ||
|
||
Set of APIs used internally by the FTR. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test', | ||
rootDir: '../../..', | ||
roots: ['<rootDir>/src/plugins/ftr_apis'], | ||
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/src/plugins/ftr_apis', | ||
coverageReporters: ['text', 'html'], | ||
collectCoverageFrom: ['<rootDir>/src/plugins/ftr_apis/{common,public,server}/**/*.{js,ts,tsx}'], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"id": "ftrApis", | ||
"owner": { | ||
"name": "Core", | ||
"githubTeam": "kibana-core" | ||
}, | ||
"version": "kibana", | ||
"configPath": ["ftr_apis"], | ||
"server": true, | ||
"ui": false | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { schema, type TypeOf } from '@kbn/config-schema'; | ||
import type { PluginConfigDescriptor } from '@kbn/core/server'; | ||
|
||
const configSchema = schema.object({ | ||
disableApis: schema.boolean({ defaultValue: false }), | ||
}); | ||
|
||
export type ConfigType = TypeOf<typeof configSchema>; | ||
|
||
export const config: PluginConfigDescriptor<ConfigType> = { | ||
schema: configSchema, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { PluginInitializerContext } from '@kbn/core/server'; | ||
import { FtrApisPlugin } from './plugin'; | ||
|
||
export function plugin(initializerContext: PluginInitializerContext) { | ||
return new FtrApisPlugin(initializerContext); | ||
} | ||
|
||
export { config } from './config'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { CoreSetup, Plugin, PluginInitializerContext } from '@kbn/core/server'; | ||
import { registerRoutes } from './routes'; | ||
import type { ConfigType } from './config'; | ||
|
||
export class FtrApisPlugin implements Plugin { | ||
private readonly config: ConfigType; | ||
|
||
constructor(initializerContext: PluginInitializerContext) { | ||
this.config = initializerContext.config.get<ConfigType>(); | ||
} | ||
|
||
public setup({ http, savedObjects }: CoreSetup) { | ||
const router = http.createRouter(); | ||
if (!this.config.disableApis) { | ||
registerRoutes(router); | ||
} | ||
} | ||
|
||
public start() {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { IRouter } from '@kbn/core/server'; | ||
import { registerKbnClientSoRoutes } from './kbn_client_so'; | ||
|
||
export const registerRoutes = (router: IRouter) => { | ||
registerKbnClientSoRoutes(router); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { IRouter } from '@kbn/core/server'; | ||
import { schema } from '@kbn/config-schema'; | ||
import { KBN_CLIENT_API_PREFIX, listHiddenTypes, catchAndReturnBoomErrors } from './utils'; | ||
|
||
export const registerBulkDeleteRoute = (router: IRouter) => { | ||
router.post( | ||
{ | ||
path: `${KBN_CLIENT_API_PREFIX}/_bulk_delete`, | ||
options: { | ||
tags: ['access:ftrApis'], | ||
}, | ||
validate: { | ||
body: schema.arrayOf( | ||
schema.object({ | ||
type: schema.string(), | ||
id: schema.string(), | ||
}) | ||
), | ||
}, | ||
}, | ||
catchAndReturnBoomErrors(async (ctx, req, res) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI: I asked about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I wanted to, but it's actually used by the FTR KbnClient. Removing it causes some errors to not be properly wrapped, causing a lot of test suites to fail. |
||
const { savedObjects } = await ctx.core; | ||
const hiddenTypes = listHiddenTypes(savedObjects.typeRegistry); | ||
const soClient = savedObjects.getClient({ includedHiddenTypes: hiddenTypes }); | ||
|
||
const statuses = await soClient.bulkDelete(req.body, { force: true }); | ||
return res.ok({ body: statuses }); | ||
}) | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { IRouter } from '@kbn/core/server'; | ||
import { schema } from '@kbn/config-schema'; | ||
import { KBN_CLIENT_API_PREFIX, listHiddenTypes, catchAndReturnBoomErrors } from './utils'; | ||
|
||
export const registerCreateRoute = (router: IRouter) => { | ||
router.post( | ||
{ | ||
path: `${KBN_CLIENT_API_PREFIX}/{type}/{id?}`, | ||
options: { | ||
tags: ['access:ftrApis'], | ||
}, | ||
validate: { | ||
params: schema.object({ | ||
type: schema.string(), | ||
id: schema.maybe(schema.string()), | ||
}), | ||
query: schema.object({ | ||
overwrite: schema.boolean({ defaultValue: false }), | ||
}), | ||
body: schema.object({ | ||
attributes: schema.recordOf(schema.string(), schema.any()), | ||
migrationVersion: schema.maybe(schema.recordOf(schema.string(), schema.string())), | ||
references: schema.maybe( | ||
schema.arrayOf( | ||
schema.object({ | ||
name: schema.string(), | ||
type: schema.string(), | ||
id: schema.string(), | ||
}) | ||
) | ||
), | ||
}), | ||
}, | ||
}, | ||
catchAndReturnBoomErrors(async (ctx, req, res) => { | ||
const { type, id } = req.params; | ||
const { overwrite } = req.query; | ||
const { attributes, migrationVersion, references } = req.body; | ||
const { savedObjects } = await ctx.core; | ||
|
||
const hiddenTypes = listHiddenTypes(savedObjects.typeRegistry); | ||
const soClient = savedObjects.getClient({ includedHiddenTypes: hiddenTypes }); | ||
|
||
const options = { | ||
id, | ||
overwrite, | ||
migrationVersion, | ||
references, | ||
}; | ||
const result = await soClient.create(type, attributes, options); | ||
return res.ok({ body: result }); | ||
}) | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { IRouter } from '@kbn/core/server'; | ||
import { schema } from '@kbn/config-schema'; | ||
import { KBN_CLIENT_API_PREFIX, listHiddenTypes, catchAndReturnBoomErrors } from './utils'; | ||
|
||
export const registerDeleteRoute = (router: IRouter) => { | ||
router.delete( | ||
{ | ||
path: `${KBN_CLIENT_API_PREFIX}/{type}/{id}`, | ||
options: { | ||
tags: ['access:ftrApis'], | ||
}, | ||
validate: { | ||
params: schema.object({ | ||
type: schema.string(), | ||
id: schema.string(), | ||
}), | ||
}, | ||
}, | ||
catchAndReturnBoomErrors(async (ctx, req, res) => { | ||
const { type, id } = req.params; | ||
const { savedObjects } = await ctx.core; | ||
|
||
const hiddenTypes = listHiddenTypes(savedObjects.typeRegistry); | ||
const soClient = savedObjects.getClient({ includedHiddenTypes: hiddenTypes }); | ||
|
||
const result = await soClient.delete(type, id, { force: true }); | ||
return res.ok({ body: result }); | ||
}) | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { IRouter } from '@kbn/core/server'; | ||
import { schema } from '@kbn/config-schema'; | ||
import { KBN_CLIENT_API_PREFIX, listHiddenTypes, catchAndReturnBoomErrors } from './utils'; | ||
|
||
export const registerFindRoute = (router: IRouter) => { | ||
router.get( | ||
{ | ||
path: `${KBN_CLIENT_API_PREFIX}/_find`, | ||
options: { | ||
tags: ['access:ftrApis'], | ||
}, | ||
validate: { | ||
query: schema.object({ | ||
per_page: schema.number({ min: 0, defaultValue: 20 }), | ||
page: schema.number({ min: 0, defaultValue: 1 }), | ||
type: schema.oneOf([schema.string(), schema.arrayOf(schema.string())]), | ||
search: schema.maybe(schema.string()), | ||
fields: schema.maybe(schema.oneOf([schema.string(), schema.arrayOf(schema.string())])), | ||
}), | ||
}, | ||
}, | ||
catchAndReturnBoomErrors(async (ctx, req, res) => { | ||
const query = req.query; | ||
|
||
const { savedObjects } = await ctx.core; | ||
const hiddenTypes = listHiddenTypes(savedObjects.typeRegistry); | ||
const soClient = savedObjects.getClient({ includedHiddenTypes: hiddenTypes }); | ||
|
||
const result = await soClient.find({ | ||
perPage: query.per_page, | ||
page: query.page, | ||
type: Array.isArray(query.type) ? query.type : [query.type], | ||
search: query.search, | ||
fields: typeof query.fields === 'string' ? [query.fields] : query.fields, | ||
}); | ||
|
||
return res.ok({ body: result }); | ||
}) | ||
); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: We should be more specific about what APIs these are and that they are only for ftr testing. e.g.
Set of APIs for the kbn server's saved object's client used internally by the functional test runner
or, more concisely:
Set of kbnServer saved objects' client APIs used internally by the functional test runner