-
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.
Merge branch 'main' into reset-preconfig
- Loading branch information
Showing
41 changed files
with
606 additions
and
177 deletions.
There are no files selected for viewing
28 changes: 14 additions & 14 deletions
28
...settings/core-ui-settings-browser-internal/src/__snapshots__/ui_settings_api.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
68 changes: 68 additions & 0 deletions
68
packages/core/ui-settings/core-ui-settings-server-internal/src/routes/internal/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,68 @@ | ||
/* | ||
* 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 } from '@kbn/config-schema'; | ||
|
||
import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-server'; | ||
import { IUiSettingsClient } from '@kbn/core-ui-settings-server'; | ||
import { KibanaRequest, KibanaResponseFactory } from '@kbn/core-http-server'; | ||
import type { InternalUiSettingsRouter } from '../../internal_types'; | ||
import { CannotOverrideError } from '../../ui_settings_errors'; | ||
import { InternalUiSettingsRequestHandlerContext } from '../../internal_types'; | ||
|
||
const validate = { | ||
params: schema.object({ | ||
key: schema.string(), | ||
}), | ||
}; | ||
|
||
export function registerInternalDeleteRoute(router: InternalUiSettingsRouter) { | ||
const deleteFromRequest = async ( | ||
uiSettingsClient: IUiSettingsClient, | ||
context: InternalUiSettingsRequestHandlerContext, | ||
request: KibanaRequest<Readonly<{} & { key: string }>, unknown, unknown, 'delete'>, | ||
response: KibanaResponseFactory | ||
) => { | ||
try { | ||
await uiSettingsClient.remove(request.params.key); | ||
|
||
return response.ok({ | ||
body: { | ||
settings: await uiSettingsClient.getUserProvided(), | ||
}, | ||
}); | ||
} catch (error) { | ||
if (SavedObjectsErrorHelpers.isSavedObjectsClientError(error)) { | ||
return response.customError({ | ||
body: error, | ||
statusCode: error.output.statusCode, | ||
}); | ||
} | ||
|
||
if (error instanceof CannotOverrideError) { | ||
return response.badRequest({ body: error }); | ||
} | ||
|
||
throw error; | ||
} | ||
}; | ||
router.delete( | ||
{ path: '/internal/kibana/settings/{key}', validate, options: { access: 'internal' } }, | ||
async (context, request, response) => { | ||
const uiSettingsClient = (await context.core).uiSettings.client; | ||
return await deleteFromRequest(uiSettingsClient, context, request, response); | ||
} | ||
); | ||
router.delete( | ||
{ path: '/internal/kibana/global_settings/{key}', validate, options: { access: 'internal' } }, | ||
async (context, request, response) => { | ||
const uiSettingsClient = (await context.core).uiSettings.globalClient; | ||
return await deleteFromRequest(uiSettingsClient, context, request, response); | ||
} | ||
); | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/core/ui-settings/core-ui-settings-server-internal/src/routes/internal/get.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,53 @@ | ||
/* | ||
* 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 { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-server'; | ||
import { IUiSettingsClient } from '@kbn/core-ui-settings-server'; | ||
import { KibanaRequest, KibanaResponseFactory } from '@kbn/core-http-server'; | ||
import { InternalUiSettingsRequestHandlerContext } from '../../internal_types'; | ||
import type { InternalUiSettingsRouter } from '../../internal_types'; | ||
|
||
export function registerInternalGetRoute(router: InternalUiSettingsRouter) { | ||
const getFromRequest = async ( | ||
uiSettingsClient: IUiSettingsClient, | ||
context: InternalUiSettingsRequestHandlerContext, | ||
request: KibanaRequest<unknown, unknown, unknown, 'get'>, | ||
response: KibanaResponseFactory | ||
) => { | ||
try { | ||
return response.ok({ | ||
body: { | ||
settings: await uiSettingsClient.getUserProvided(), | ||
}, | ||
}); | ||
} catch (error) { | ||
if (SavedObjectsErrorHelpers.isSavedObjectsClientError(error)) { | ||
return response.customError({ | ||
body: error, | ||
statusCode: error.output.statusCode, | ||
}); | ||
} | ||
|
||
throw error; | ||
} | ||
}; | ||
router.get( | ||
{ path: '/internal/kibana/settings', validate: false, options: { access: 'internal' } }, | ||
async (context, request, response) => { | ||
const uiSettingsClient = (await context.core).uiSettings.client; | ||
return await getFromRequest(uiSettingsClient, context, request, response); | ||
} | ||
); | ||
router.get( | ||
{ path: '/internal/kibana/global_settings', validate: false, options: { access: 'internal' } }, | ||
async (context, request, response) => { | ||
const uiSettingsClient = (await context.core).uiSettings.globalClient; | ||
return await getFromRequest(uiSettingsClient, context, request, response); | ||
} | ||
); | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/core/ui-settings/core-ui-settings-server-internal/src/routes/internal/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,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 type { InternalUiSettingsRouter } from '../../internal_types'; | ||
import { registerInternalDeleteRoute } from './delete'; | ||
import { registerInternalGetRoute } from './get'; | ||
import { registerInternalSetManyRoute } from './set_many'; | ||
import { registerInternalSetRoute } from './set'; | ||
|
||
export function registerInternalRoutes(router: InternalUiSettingsRouter) { | ||
registerInternalGetRoute(router); | ||
registerInternalDeleteRoute(router); | ||
registerInternalSetRoute(router); | ||
registerInternalSetManyRoute(router); | ||
} |
80 changes: 80 additions & 0 deletions
80
packages/core/ui-settings/core-ui-settings-server-internal/src/routes/internal/set.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,80 @@ | ||
/* | ||
* 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, ValidationError } from '@kbn/config-schema'; | ||
import { KibanaRequest, KibanaResponseFactory } from '@kbn/core-http-server'; | ||
import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-server'; | ||
import { IUiSettingsClient } from '@kbn/core-ui-settings-server'; | ||
import type { | ||
InternalUiSettingsRequestHandlerContext, | ||
InternalUiSettingsRouter, | ||
} from '../../internal_types'; | ||
import { CannotOverrideError } from '../../ui_settings_errors'; | ||
|
||
const validate = { | ||
params: schema.object({ | ||
key: schema.string(), | ||
}), | ||
body: schema.object({ | ||
value: schema.any(), | ||
}), | ||
}; | ||
|
||
export function registerInternalSetRoute(router: InternalUiSettingsRouter) { | ||
const setFromRequest = async ( | ||
uiSettingsClient: IUiSettingsClient, | ||
context: InternalUiSettingsRequestHandlerContext, | ||
request: KibanaRequest< | ||
Readonly<{} & { key: string }>, | ||
unknown, | ||
Readonly<{ value?: any } & {}>, | ||
'post' | ||
>, | ||
response: KibanaResponseFactory | ||
) => { | ||
try { | ||
const { key } = request.params; | ||
const { value } = request.body; | ||
|
||
await uiSettingsClient.set(key, value); | ||
|
||
return response.ok({ | ||
body: { | ||
settings: await uiSettingsClient.getUserProvided(), | ||
}, | ||
}); | ||
} catch (error) { | ||
if (SavedObjectsErrorHelpers.isSavedObjectsClientError(error)) { | ||
return response.customError({ | ||
body: error, | ||
statusCode: error.output.statusCode, | ||
}); | ||
} | ||
|
||
if (error instanceof CannotOverrideError || error instanceof ValidationError) { | ||
return response.badRequest({ body: error }); | ||
} | ||
|
||
throw error; | ||
} | ||
}; | ||
router.post( | ||
{ path: '/internal/kibana/settings/{key}', validate, options: { access: 'internal' } }, | ||
async (context, request, response) => { | ||
const uiSettingsClient = (await context.core).uiSettings.client; | ||
return await setFromRequest(uiSettingsClient, context, request, response); | ||
} | ||
); | ||
router.post( | ||
{ path: '/internal/kibana/global_settings/{key}', validate, options: { access: 'internal' } }, | ||
async (context, request, response) => { | ||
const uiSettingsClient = (await context.core).uiSettings.globalClient; | ||
return await setFromRequest(uiSettingsClient, context, request, response); | ||
} | ||
); | ||
} |
Oops, something went wrong.