-
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.
[ResponseOps] Prepare the connector
execute
HTTP API for versioning (…
…#194481) Towards elastic/response-ops-team#125 ## Summary Preparing the `POST ${BASE_ACTION_API_PATH}/connector/{id}/_execute` HTTP API for versioning --------- Co-authored-by: Ying Mao <[email protected]>
- Loading branch information
Showing
33 changed files
with
426 additions
and
164 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
x-pack/plugins/actions/common/routes/connector/apis/execute/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,21 @@ | ||
/* | ||
* 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 { | ||
executeConnectorRequestParamsSchema, | ||
executeConnectorRequestBodySchema, | ||
} from './schemas/latest'; | ||
export type { ExecuteConnectorRequestParams, ExecuteConnectorRequestBody } from './types/latest'; | ||
|
||
export { | ||
executeConnectorRequestParamsSchema as executeConnectorRequestParamsSchemaV1, | ||
executeConnectorRequestBodySchema as executeConnectorRequestBodySchemaV1, | ||
} from './schemas/v1'; | ||
export type { | ||
ExecuteConnectorRequestParams as ExecuteConnectorRequestParamsV1, | ||
ExecuteConnectorRequestBody as ExecuteConnectorRequestBodyV1, | ||
} from './types/v1'; |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/actions/common/routes/connector/apis/execute/schemas/latest.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,8 @@ | ||
/* | ||
* 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 * from './v1'; |
20 changes: 20 additions & 0 deletions
20
x-pack/plugins/actions/common/routes/connector/apis/execute/schemas/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,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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { schema } from '@kbn/config-schema'; | ||
|
||
export const executeConnectorRequestParamsSchema = schema.object({ | ||
id: schema.string({ | ||
meta: { | ||
description: 'An identifier for the connector.', | ||
}, | ||
}), | ||
}); | ||
|
||
export const executeConnectorRequestBodySchema = schema.object({ | ||
params: schema.recordOf(schema.string(), schema.any()), | ||
}); |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/actions/common/routes/connector/apis/execute/types/latest.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,8 @@ | ||
/* | ||
* 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 * from './v1'; |
12 changes: 12 additions & 0 deletions
12
x-pack/plugins/actions/common/routes/connector/apis/execute/types/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,12 @@ | ||
/* | ||
* 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 type { TypeOf } from '@kbn/config-schema'; | ||
import { executeConnectorRequestParamsSchemaV1, executeConnectorRequestBodySchemaV1 } from '..'; | ||
|
||
export type ExecuteConnectorRequestParams = TypeOf<typeof executeConnectorRequestParamsSchemaV1>; | ||
export type ExecuteConnectorRequestBody = TypeOf<typeof executeConnectorRequestBodySchemaV1>; |
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
73 changes: 73 additions & 0 deletions
73
x-pack/plugins/actions/server/application/connector/methods/execute/execute.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,73 @@ | ||
/* | ||
* 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 { v4 as uuidv4 } from 'uuid'; | ||
import { RawAction, ActionTypeExecutorResult } from '../../../../types'; | ||
import { getSystemActionKibanaPrivileges } from '../../../../lib/get_system_action_kibana_privileges'; | ||
import { isPreconfigured } from '../../../../lib/is_preconfigured'; | ||
import { isSystemAction } from '../../../../lib/is_system_action'; | ||
import { | ||
getAuthorizationModeBySource, | ||
AuthorizationMode, | ||
} from '../../../../authorization/get_authorization_mode_by_source'; | ||
import { trackLegacyRBACExemption } from '../../../../lib/track_legacy_rbac_exemption'; | ||
import { ConnectorExecuteParams } from './types'; | ||
import { ACTION_SAVED_OBJECT_TYPE } from '../../../../constants/saved_objects'; | ||
import { ActionsClientContext } from '../../../../actions_client'; | ||
|
||
export async function execute( | ||
context: ActionsClientContext, | ||
connectorExecuteParams: ConnectorExecuteParams | ||
): Promise<ActionTypeExecutorResult<unknown>> { | ||
const log = context.logger; | ||
const { actionId, params, source, relatedSavedObjects } = connectorExecuteParams; | ||
|
||
if ( | ||
(await getAuthorizationModeBySource(context.unsecuredSavedObjectsClient, source)) === | ||
AuthorizationMode.RBAC | ||
) { | ||
const additionalPrivileges = getSystemActionKibanaPrivileges(context, actionId, params); | ||
let actionTypeId: string | undefined; | ||
|
||
try { | ||
if (isPreconfigured(context, actionId) || isSystemAction(context, actionId)) { | ||
const connector = context.inMemoryConnectors.find( | ||
(inMemoryConnector) => inMemoryConnector.id === actionId | ||
); | ||
|
||
actionTypeId = connector?.actionTypeId; | ||
} else { | ||
// TODO: Optimize so we don't do another get on top of getAuthorizationModeBySource and within the actionExecutor.execute | ||
const { attributes } = await context.unsecuredSavedObjectsClient.get<RawAction>( | ||
ACTION_SAVED_OBJECT_TYPE, | ||
actionId | ||
); | ||
|
||
actionTypeId = attributes.actionTypeId; | ||
} | ||
} catch (err) { | ||
log.debug(`Failed to retrieve actionTypeId for action [${actionId}]`, err); | ||
} | ||
|
||
await context.authorization.ensureAuthorized({ | ||
operation: 'execute', | ||
additionalPrivileges, | ||
actionTypeId, | ||
}); | ||
} else { | ||
trackLegacyRBACExemption('execute', context.usageCounter); | ||
} | ||
|
||
return context.actionExecutor.execute({ | ||
actionId, | ||
params, | ||
source, | ||
request: context.request, | ||
relatedSavedObjects, | ||
actionExecutionId: uuidv4(), | ||
}); | ||
} |
Oops, something went wrong.