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.
Remove include_system_actions query from get_all
- Loading branch information
Showing
12 changed files
with
192 additions
and
56 deletions.
There are no files selected for viewing
12 changes: 0 additions & 12 deletions
12
x-pack/plugins/actions/common/routes/connector/apis/connectors/index.ts
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
x-pack/plugins/actions/common/routes/connector/apis/connectors/schemas/v1.ts
This file was deleted.
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
96 changes: 96 additions & 0 deletions
96
x-pack/plugins/actions/server/routes/connector/get_all_system/get_all_system.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,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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { getAllConnectorsRoute } from './get_all'; | ||
import { httpServiceMock } from '@kbn/core/server/mocks'; | ||
import { licenseStateMock } from '../../../lib/license_state.mock'; | ||
import { mockHandlerArguments } from '../../legacy/_mock_handler_arguments'; | ||
import { verifyAccessAndContext } from '../../verify_access_and_context'; | ||
import { actionsClientMock } from '../../../actions_client/actions_client.mock'; | ||
|
||
jest.mock('../../verify_access_and_context', () => ({ | ||
verifyAccessAndContext: jest.fn(), | ||
})); | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
(verifyAccessAndContext as jest.Mock).mockImplementation((license, handler) => handler); | ||
}); | ||
|
||
describe('getAllConnectorsRoute', () => { | ||
it('get all connectors with proper parameters', async () => { | ||
const licenseState = licenseStateMock.create(); | ||
const router = httpServiceMock.createRouter(); | ||
|
||
getAllConnectorsRoute(router, licenseState); | ||
|
||
const [config, handler] = router.get.mock.calls[0]; | ||
|
||
expect(config.path).toMatchInlineSnapshot(`"/api/actions/connectors"`); | ||
|
||
const actionsClient = actionsClientMock.create(); | ||
actionsClient.getAll.mockResolvedValueOnce([]); | ||
|
||
const [context, req, res] = mockHandlerArguments({ actionsClient }, {}, ['ok']); | ||
|
||
expect(await handler(context, req, res)).toMatchInlineSnapshot(` | ||
Object { | ||
"body": Array [], | ||
} | ||
`); | ||
|
||
expect(actionsClient.getAll).toHaveBeenCalledTimes(1); | ||
|
||
expect(res.ok).toHaveBeenCalledWith({ | ||
body: [], | ||
}); | ||
}); | ||
|
||
it('ensures the license allows getting all connectors', async () => { | ||
const licenseState = licenseStateMock.create(); | ||
const router = httpServiceMock.createRouter(); | ||
|
||
getAllConnectorsRoute(router, licenseState); | ||
|
||
const [config, handler] = router.get.mock.calls[0]; | ||
|
||
expect(config.path).toMatchInlineSnapshot(`"/api/actions/connectors"`); | ||
|
||
const actionsClient = actionsClientMock.create(); | ||
actionsClient.getAll.mockResolvedValueOnce([]); | ||
|
||
const [context, req, res] = mockHandlerArguments({ actionsClient }, {}, ['ok']); | ||
|
||
await handler(context, req, res); | ||
|
||
expect(verifyAccessAndContext).toHaveBeenCalledWith(licenseState, expect.any(Function)); | ||
}); | ||
|
||
it('ensures the license check prevents getting all connectors', async () => { | ||
const licenseState = licenseStateMock.create(); | ||
const router = httpServiceMock.createRouter(); | ||
|
||
(verifyAccessAndContext as jest.Mock).mockImplementation(() => async () => { | ||
throw new Error('OMG'); | ||
}); | ||
|
||
getAllConnectorsRoute(router, licenseState); | ||
|
||
const [config, handler] = router.get.mock.calls[0]; | ||
|
||
expect(config.path).toMatchInlineSnapshot(`"/api/actions/connectors"`); | ||
|
||
const actionsClient = actionsClientMock.create(); | ||
actionsClient.getAll.mockResolvedValueOnce([]); | ||
|
||
const [context, req, res] = mockHandlerArguments({ actionsClient }, {}, ['ok']); | ||
|
||
expect(handler(context, req, res)).rejects.toMatchInlineSnapshot(`[Error: OMG]`); | ||
|
||
expect(verifyAccessAndContext).toHaveBeenCalledWith(licenseState, expect.any(Function)); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
x-pack/plugins/actions/server/routes/connector/get_all_system/get_all_system.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,37 @@ | ||
/* | ||
* 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 { IRouter } from '@kbn/core/server'; | ||
import { AllConnectorsResponseV1 } from '../../../../common/routes/connector/response'; | ||
import { transformGetAllConnectorsResponseV1 } from './transforms'; | ||
import { ActionsRequestHandlerContext } from '../../../types'; | ||
import { INTERNAL_BASE_ACTION_API_PATH } from '../../../../common'; | ||
import { ILicenseState } from '../../../lib'; | ||
import { verifyAccessAndContext } from '../../verify_access_and_context'; | ||
|
||
export const getAllSystemConnectorsRoute = ( | ||
router: IRouter<ActionsRequestHandlerContext>, | ||
licenseState: ILicenseState | ||
) => { | ||
router.get( | ||
{ | ||
path: `${INTERNAL_BASE_ACTION_API_PATH}/connectors/system`, | ||
validate: {}, | ||
}, | ||
router.handleLegacyErrors( | ||
verifyAccessAndContext(licenseState, async function (context, req, res) { | ||
const actionsClient = (await context.actions).getActionsClient(); | ||
const result = await actionsClient.getAll({ | ||
includeSystemActions: true, | ||
}); | ||
|
||
const responseBody: AllConnectorsResponseV1[] = transformGetAllConnectorsResponseV1(result); | ||
return res.ok({ body: responseBody }); | ||
}) | ||
) | ||
); | ||
}; |
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 |
---|---|---|
|
@@ -5,4 +5,4 @@ | |
* 2.0. | ||
*/ | ||
|
||
export * from './v1'; | ||
export { getAllSystemConnectorsRoute } from './get_all_system'; |
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 |
---|---|---|
|
@@ -5,4 +5,4 @@ | |
* 2.0. | ||
*/ | ||
|
||
export * from './v1'; | ||
export { transformGetAllConnectorsResponse } from './v1'; |
37 changes: 37 additions & 0 deletions
37
...ons/server/routes/connector/get_all_system/transforms/transform_connectors_response/v1.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,37 @@ | ||
/* | ||
* 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 { ConnectorWithExtraFindData } from '../../../../../application/connector/types'; | ||
import { AllConnectorsResponseV1 } from '../../../../../../common/routes/connector/response'; | ||
|
||
export const transformGetAllConnectorsResponse = ( | ||
results: ConnectorWithExtraFindData[] | ||
): AllConnectorsResponseV1[] => { | ||
return results.map( | ||
({ | ||
id, | ||
name, | ||
config, | ||
actionTypeId, | ||
isPreconfigured, | ||
isDeprecated, | ||
referencedByCount, | ||
isMissingSecrets, | ||
isSystemAction, | ||
}) => ({ | ||
id, | ||
name, | ||
config, | ||
connector_type_id: actionTypeId, | ||
is_preconfigured: isPreconfigured, | ||
is_deprecated: isDeprecated, | ||
referenced_by_count: referencedByCount, | ||
is_missing_secrets: isMissingSecrets, | ||
is_system_action: isSystemAction, | ||
}) | ||
); | ||
}; |
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