-
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
Merged
pgayvallet
merged 18 commits into
elastic:main
from
pgayvallet:kbn-148412-ftr-kbn-client-plugin
Jan 26, 2023
Merged
Create the ftrSoApis FTR plugin #149188
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
fceb917
Create the kbnSoApis FTR plugin
pgayvallet 90136ae
update config base
pgayvallet 959f3fd
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 122916b
use inline strings
pgayvallet 13db670
converting boom errors
pgayvallet 9384667
fix description
pgayvallet 12c6470
Merge branch 'main' into kbn-148412-ftr-kbn-client-plugin
kibanamachine 87db010
start moving plugin to src
pgayvallet 1bf8ba1
split APIs per file
pgayvallet 6bfd5a5
add access tag
pgayvallet 1c829b5
updating config file
pgayvallet 74e2717
[CI] Auto-commit changed files from 'node scripts/build_plugin_list_d…
kibanamachine f24e7d4
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 63cafed
preparing api integ tests
pgayvallet f9f1e1f
adapt the FTR tests
pgayvallet 934fef3
update doc
pgayvallet 46a9a6b
Merge remote-tracking branch 'upstream/main' into kbn-148412-ftr-kbn-…
pgayvallet ab041e7
[CI] Auto-commit changed files from 'node scripts/build_plugin_list_d…
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
FYI: I asked about
catchAndReturnBoomErrors
and apparently it should be dead / unecessary code and safe to remove. We're probably less likely to replace these APIs in the short to medium term so should we remove it?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.
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.