forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create the ftrSoApis FTR plugin (elastic#149188)
## Summary Fix elastic#148412 More and more SO types will not be accessible from the HTTP APIs (either `hidden:true` or `hiddenFromHTTPApis: true`). However, the FTR SO client (`KbnClientSavedObjects`) still needs to be able to access and manipulate all SO types. This PR introduces a `ftrSoApis` plugin that is loaded for all FTR suites. This plugin exposes SO APIs that are used by the FTR client instead of the public SO HTTP APIs. These APIs are configured to know about all types, even hidden ones. Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
d9644fc
commit fe2bf9a
Showing
36 changed files
with
1,657 additions
and
12 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
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,8 @@ | ||
# ftrApis plugin | ||
|
||
This plugin exposes a set of APIs used internally during functional tests by the FTR. | ||
|
||
The APIs currently exposed are: | ||
1. APIs used by the `KbnClientSavedObjects` (SO service of the FTR) | ||
|
||
**Remark: these APIs shouldn't be called directly for any reason** |
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,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}'], | ||
}; |
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,11 @@ | ||
{ | ||
"id": "ftrApis", | ||
"owner": { | ||
"name": "Core", | ||
"githubTeam": "kibana-core" | ||
}, | ||
"version": "kibana", | ||
"configPath": ["ftr_apis"], | ||
"server": true, | ||
"ui": false | ||
} |
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,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, | ||
}; |
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,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'; |
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,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() {} | ||
} |
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,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); | ||
}; |
38 changes: 38 additions & 0 deletions
38
src/plugins/ftr_apis/server/routes/kbn_client_so/bulk_delete.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,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) => { | ||
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 }); | ||
}) | ||
); | ||
}; |
62 changes: 62 additions & 0 deletions
62
src/plugins/ftr_apis/server/routes/kbn_client_so/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,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 }); | ||
}) | ||
); | ||
}; |
38 changes: 38 additions & 0 deletions
38
src/plugins/ftr_apis/server/routes/kbn_client_so/delete.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,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 }); | ||
}) | ||
); | ||
}; |
Oops, something went wrong.