forked from elastic/kibana
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into task/olm-7053-serve…
…rless-pli-authz # Conflicts: # x-pack/plugins/security_solution_serverless/server/plugin.ts
- Loading branch information
Showing
529 changed files
with
6,240 additions
and
5,061 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
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
23 changes: 23 additions & 0 deletions
23
packages/core/i18n/core-i18n-server-internal/src/routes/translations.test.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,23 @@ | ||
/* | ||
* 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 { mockRouter } from '@kbn/core-http-router-server-mocks'; | ||
import { registerTranslationsRoute } from './translations'; | ||
|
||
describe('registerTranslationsRoute', () => { | ||
test('registers route with expected options', () => { | ||
const router = mockRouter.create(); | ||
registerTranslationsRoute(router, 'en'); | ||
expect(router.get).toHaveBeenCalledTimes(1); | ||
expect(router.get).toHaveBeenNthCalledWith( | ||
1, | ||
expect.objectContaining({ options: { access: 'public', authRequired: false } }), | ||
expect.any(Function) | ||
); | ||
}); | ||
}); |
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
31 changes: 31 additions & 0 deletions
31
...e/rendering/core-rendering-server-internal/src/bootstrap/register_bootstrap_route.test.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,31 @@ | ||
/* | ||
* 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 { registerBootstrapRoute } from './register_bootstrap_route'; | ||
import { mockRouter } from '@kbn/core-http-router-server-mocks'; | ||
|
||
describe('registerBootstrapRoute', () => { | ||
test('register with expected options', () => { | ||
const router = mockRouter.create(); | ||
const renderer = jest.fn(); | ||
registerBootstrapRoute({ router, renderer }); | ||
expect(router.get).toHaveBeenCalledTimes(2); | ||
expect(router.get).toHaveBeenNthCalledWith( | ||
1, | ||
expect.objectContaining({ options: { access: 'public', tags: ['api'] } }), | ||
expect.any(Function) | ||
); | ||
expect(router.get).toHaveBeenNthCalledWith( | ||
2, | ||
expect.objectContaining({ | ||
options: { access: 'public', tags: ['api'], authRequired: 'optional' }, | ||
}), | ||
expect.any(Function) | ||
); | ||
}); | ||
}); |
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
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,96 @@ | ||
/* | ||
* 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 Boom from '@hapi/boom'; | ||
import { pick } from 'lodash'; | ||
|
||
import type { StorageContext } from '@kbn/content-management-plugin/server'; | ||
|
||
import type { | ||
SavedObjectsFindResult, | ||
SavedObject, | ||
SavedObjectReference, | ||
} from '@kbn/core-saved-objects-api-server'; | ||
|
||
import type { ServicesDefinitionSet, SOWithMetadata, SOWithMetadataPartial } from './types'; | ||
|
||
type PartialSavedObject<T> = Omit<SavedObject<Partial<T>>, 'references'> & { | ||
references: SavedObjectReference[] | undefined; | ||
}; | ||
|
||
interface GetMSearchParams { | ||
savedObjectType: string; | ||
cmServicesDefinition: ServicesDefinitionSet; | ||
allowedSavedObjectAttributes: string[]; | ||
} | ||
|
||
function savedObjectToItem<Attributes extends object>( | ||
savedObject: SavedObject<Attributes> | PartialSavedObject<Attributes>, | ||
allowedSavedObjectAttributes: string[] | ||
): SOWithMetadata | SOWithMetadataPartial { | ||
const { | ||
id, | ||
type, | ||
updated_at: updatedAt, | ||
created_at: createdAt, | ||
attributes, | ||
references, | ||
error, | ||
namespaces, | ||
version, | ||
} = savedObject; | ||
|
||
return { | ||
id, | ||
type, | ||
updatedAt, | ||
createdAt, | ||
attributes: pick(attributes, allowedSavedObjectAttributes), | ||
references, | ||
error, | ||
namespaces, | ||
version, | ||
}; | ||
} | ||
|
||
export interface GetMSearchType<ReturnItem> { | ||
savedObjectType: string; | ||
toItemResult: (ctx: StorageContext, savedObject: SavedObjectsFindResult) => ReturnItem; | ||
} | ||
|
||
export const getMSearch = <ReturnItem, SOAttributes extends object>({ | ||
savedObjectType, | ||
cmServicesDefinition, | ||
allowedSavedObjectAttributes, | ||
}: GetMSearchParams) => { | ||
return { | ||
savedObjectType, | ||
toItemResult: (ctx: StorageContext, savedObject: SavedObjectsFindResult): ReturnItem => { | ||
const transforms = ctx.utils.getTransforms(cmServicesDefinition); | ||
|
||
// Validate DB response and DOWN transform to the request version | ||
const { value, error: resultError } = transforms.mSearch.out.result.down< | ||
ReturnItem, | ||
ReturnItem | ||
>( | ||
// Ran into a case where a schema was broken by a SO attribute that wasn't part of the definition | ||
// so we specify which attributes are allowed | ||
savedObjectToItem<SOAttributes>( | ||
savedObject as SavedObjectsFindResult<SOAttributes>, | ||
allowedSavedObjectAttributes | ||
) | ||
); | ||
|
||
if (resultError) { | ||
throw Boom.badRequest(`Invalid response. ${resultError.message}`); | ||
} | ||
|
||
return value; | ||
}, | ||
}; | ||
}; |
Oops, something went wrong.