-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Lens] Add internal CRUD api routes #223296
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7f86834
feat: add internal lens api routes
nickofthyme 9c9754d
chore: update api specs and error handling
nickofthyme 058f4b2
test: add basic lens api integration tests
nickofthyme 6e2df00
Merge branch 'main' into new-lens-api
nickofthyme 30a61d2
chore: fix test title
nickofthyme baef217
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine fb73fc2
update codeowners file
markov00 fe1b2d4
chore: assign vis team as fixture CO
nickofthyme 11baffc
Merge branch 'main' into new-lens-api
nickofthyme cabf404
Merge remote-tracking branch 'origin/new-lens-api' into new-lens-api
nickofthyme 4cab983
chore: fix bad CO merge
nickofthyme 38a5438
chore: fix bad CO merge
nickofthyme 6cefe39
chore: move lens api tests under x-pack
nickofthyme 8ce00c8
chore: update COs again
nickofthyme 06a6a19
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine 2cac74c
[CI] Auto-commit changed files from 'node scripts/styled_components_m…
kibanamachine 812c299
Merge branch 'main' into new-lens-api
nickofthyme af410d9
chore: remove co presentation review changes
nickofthyme 9fdc36b
Merge remote-tracking branch 'origin/new-lens-api' into new-lens-api
nickofthyme 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 hidden or 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 hidden or 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 hidden or 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
11 changes: 11 additions & 0 deletions
11
x-pack/platform/plugins/shared/lens/server/api/constants.ts
This file contains hidden or 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 @@ | ||
| /* | ||
| * 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; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| export const PUBLIC_API_VERSION = '1'; | ||
| export const PUBLIC_API_CONTENT_MANAGEMENT_VERSION = 1; | ||
| export const PUBLIC_API_PATH = '/api/lens'; | ||
| export const PUBLIC_API_ACCESS = 'internal'; |
13 changes: 13 additions & 0 deletions
13
x-pack/platform/plugins/shared/lens/server/api/routes/index.ts
This file contains hidden or 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,13 @@ | ||
| /* | ||
| * 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; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import { RegisterAPIRoutesArgs } from '../types'; | ||
| import { registerLensVisualizationsAPIRoutes } from './visualizations'; | ||
|
|
||
| export function registerLensAPIRoutes(args: RegisterAPIRoutesArgs) { | ||
| registerLensVisualizationsAPIRoutes(args); | ||
| } |
99 changes: 99 additions & 0 deletions
99
x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/create.ts
This file contains hidden or 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,99 @@ | ||
| /* | ||
| * 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; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import { schema } from '@kbn/config-schema'; | ||
|
|
||
| import { boomify, isBoom } from '@hapi/boom'; | ||
| import { CONTENT_ID, type LensSavedObject } from '../../../../common/content_management'; | ||
| import { | ||
| PUBLIC_API_PATH, | ||
| PUBLIC_API_VERSION, | ||
| PUBLIC_API_CONTENT_MANAGEMENT_VERSION, | ||
| PUBLIC_API_ACCESS, | ||
| } from '../../constants'; | ||
| import { | ||
| lensAttributesSchema, | ||
| lensCreateOptionsSchema, | ||
| lensSavedObjectSchema, | ||
| } from '../../../content_management/v1'; | ||
| import { RegisterAPIRouteFn } from '../../types'; | ||
|
|
||
| export const registerLensVisualizationsCreateAPIRoute: RegisterAPIRouteFn = ( | ||
| router, | ||
| { contentManagement } | ||
| ) => { | ||
| const createRoute = router.post({ | ||
| path: `${PUBLIC_API_PATH}/visualizations`, | ||
| access: PUBLIC_API_ACCESS, | ||
| enableQueryVersion: true, | ||
| summary: 'Create Lens visualization', | ||
| description: 'Create a new Lens visualization.', | ||
| options: { | ||
| tags: ['oas-tag:Lens'], | ||
| availability: { | ||
| stability: 'experimental', | ||
| }, | ||
| }, | ||
| security: { | ||
| authz: { | ||
| enabled: false, | ||
| reason: 'Relies on Content Client for authorization', | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| createRoute.addVersion( | ||
| { | ||
| version: PUBLIC_API_VERSION, | ||
| validate: { | ||
| request: { | ||
| body: schema.object({ | ||
| options: lensCreateOptionsSchema, | ||
| data: lensAttributesSchema, | ||
| }), | ||
| }, | ||
| response: { | ||
| 201: { | ||
| body: () => lensSavedObjectSchema, | ||
| description: 'Created', | ||
| }, | ||
| 400: { | ||
| description: 'Malformed request', | ||
| }, | ||
| 401: { | ||
| description: 'Unauthorized', | ||
| }, | ||
| 403: { | ||
| description: 'Forbidden', | ||
| }, | ||
| 500: { | ||
| description: 'Internal Server Error', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| async (ctx, req, res) => { | ||
| let result; | ||
| const { data, options } = req.body; | ||
| const client = contentManagement.contentClient | ||
| .getForRequest({ request: req, requestHandlerContext: ctx }) | ||
| .for<LensSavedObject>(CONTENT_ID, PUBLIC_API_CONTENT_MANAGEMENT_VERSION); | ||
|
|
||
| try { | ||
| ({ result } = await client.create(data, options)); | ||
| } catch (error) { | ||
| if (isBoom(error) && error.output.statusCode === 403) { | ||
| return res.forbidden(); | ||
| } | ||
|
|
||
| return boomify(error); // forward unknown error | ||
| } | ||
|
|
||
| return res.created({ body: result.item }); | ||
| } | ||
| ); | ||
| }; | ||
106 changes: 106 additions & 0 deletions
106
x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/delete.ts
This file contains hidden or 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,106 @@ | ||
| /* | ||
| * 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; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import { schema } from '@kbn/config-schema'; | ||
|
|
||
| import { boomify, isBoom } from '@hapi/boom'; | ||
| import { CONTENT_ID, type LensSavedObject } from '../../../../common/content_management'; | ||
| import { | ||
| PUBLIC_API_PATH, | ||
| PUBLIC_API_VERSION, | ||
| PUBLIC_API_CONTENT_MANAGEMENT_VERSION, | ||
| PUBLIC_API_ACCESS, | ||
| } from '../../constants'; | ||
| import { RegisterAPIRouteFn } from '../../types'; | ||
|
|
||
| export const registerLensVisualizationsDeleteAPIRoute: RegisterAPIRouteFn = ( | ||
| router, | ||
| { contentManagement } | ||
| ) => { | ||
| const deleteRoute = router.delete({ | ||
| path: `${PUBLIC_API_PATH}/visualizations/{id}`, | ||
| access: PUBLIC_API_ACCESS, | ||
| enableQueryVersion: true, | ||
| summary: 'Delete Lens visualization', | ||
| description: 'Delete a Lens visualization by id.', | ||
| options: { | ||
| tags: ['oas-tag:Lens'], | ||
| availability: { | ||
| stability: 'experimental', | ||
| }, | ||
| }, | ||
| security: { | ||
| authz: { | ||
| enabled: false, | ||
| reason: 'Relies on Content Client for authorization', | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| deleteRoute.addVersion( | ||
| { | ||
| version: PUBLIC_API_VERSION, | ||
| validate: { | ||
| request: { | ||
| params: schema.object({ | ||
| id: schema.string({ | ||
| meta: { | ||
| description: 'The saved object id of a Lens visualization.', | ||
| }, | ||
| }), | ||
| }), | ||
| }, | ||
| response: { | ||
| 204: { | ||
| description: 'No Content', | ||
| }, | ||
| 400: { | ||
| description: 'Malformed request', | ||
| }, | ||
| 401: { | ||
| description: 'Unauthorized', | ||
| }, | ||
| 403: { | ||
| description: 'Forbidden', | ||
| }, | ||
| 404: { | ||
| description: 'Resource not found', | ||
| }, | ||
| 500: { | ||
| description: 'Internal Server Error', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| async (ctx, req, res) => { | ||
| const client = contentManagement.contentClient | ||
| .getForRequest({ request: req, requestHandlerContext: ctx }) | ||
| .for<LensSavedObject>(CONTENT_ID, PUBLIC_API_CONTENT_MANAGEMENT_VERSION); | ||
|
|
||
| try { | ||
| await client.delete(req.params.id); | ||
| } catch (error) { | ||
| if (isBoom(error)) { | ||
| if (error.output.statusCode === 404) { | ||
| return res.notFound({ | ||
| body: { | ||
| message: `A Lens visualization with saved object id [${req.params.id}] was not found.`, | ||
| }, | ||
| }); | ||
| } | ||
| if (error.output.statusCode === 403) { | ||
| return res.forbidden(); | ||
| } | ||
| } | ||
|
|
||
| return boomify(error); // forward unknown error | ||
| } | ||
|
|
||
| return res.noContent(); | ||
| } | ||
| ); | ||
| }; |
109 changes: 109 additions & 0 deletions
109
x-pack/platform/plugins/shared/lens/server/api/routes/visualizations/get.ts
This file contains hidden or 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,109 @@ | ||
| /* | ||
| * 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; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import { schema } from '@kbn/config-schema'; | ||
|
|
||
| import { boomify, isBoom } from '@hapi/boom'; | ||
| import { CONTENT_ID, type LensSavedObject } from '../../../../common/content_management'; | ||
| import { | ||
| PUBLIC_API_PATH, | ||
| PUBLIC_API_VERSION, | ||
| PUBLIC_API_CONTENT_MANAGEMENT_VERSION, | ||
| PUBLIC_API_ACCESS, | ||
| } from '../../constants'; | ||
| import { lensSavedObjectSchema } from '../../../content_management/v1'; | ||
| import { RegisterAPIRouteFn } from '../../types'; | ||
|
|
||
| export const registerLensVisualizationsGetAPIRoute: RegisterAPIRouteFn = ( | ||
| router, | ||
| { contentManagement } | ||
| ) => { | ||
| const getRoute = router.get({ | ||
| path: `${PUBLIC_API_PATH}/visualizations/{id}`, | ||
| access: PUBLIC_API_ACCESS, | ||
| enableQueryVersion: true, | ||
| summary: 'Get Lens visualization', | ||
| description: 'Get a Lens visualization from id.', | ||
| options: { | ||
| tags: ['oas-tag:Lens'], | ||
| availability: { | ||
| stability: 'experimental', | ||
| }, | ||
| }, | ||
| security: { | ||
| authz: { | ||
| enabled: false, | ||
| reason: 'Relies on Content Client for authorization', | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| getRoute.addVersion( | ||
| { | ||
| version: PUBLIC_API_VERSION, | ||
| validate: { | ||
| request: { | ||
| params: schema.object({ | ||
| id: schema.string({ | ||
| meta: { | ||
| description: 'The saved object id of a Lens visualization.', | ||
| }, | ||
| }), | ||
| }), | ||
| }, | ||
| response: { | ||
| 200: { | ||
| body: () => lensSavedObjectSchema, | ||
| description: 'Ok', | ||
| }, | ||
| 400: { | ||
| description: 'Malformed request', | ||
| }, | ||
| 401: { | ||
| description: 'Unauthorized', | ||
| }, | ||
| 403: { | ||
| description: 'Forbidden', | ||
| }, | ||
| 404: { | ||
| description: 'Resource not found', | ||
| }, | ||
| 500: { | ||
| description: 'Internal Server Error', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| async (ctx, req, res) => { | ||
| let result; | ||
| const client = contentManagement.contentClient | ||
| .getForRequest({ request: req, requestHandlerContext: ctx }) | ||
| .for<LensSavedObject>(CONTENT_ID, PUBLIC_API_CONTENT_MANAGEMENT_VERSION); | ||
|
|
||
| try { | ||
| ({ result } = await client.get(req.params.id)); | ||
| } catch (error) { | ||
| if (isBoom(error)) { | ||
| if (error.output.statusCode === 404) { | ||
| return res.notFound({ | ||
| body: { | ||
| message: `A Lens visualization with saved object id [${req.params.id}] was not found.`, | ||
| }, | ||
| }); | ||
| } | ||
| if (error.output.statusCode === 403) { | ||
| return res.forbidden(); | ||
| } | ||
| } | ||
|
|
||
| return boomify(error); // forward unknown error | ||
| } | ||
|
|
||
| return res.ok({ body: result.item }); | ||
| } | ||
| ); | ||
| }; |
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.
Uh oh!
There was an error while loading. Please reload this page.