Skip to content

Commit

Permalink
[Response Ops][Connectors] Add unsecured actions client to allow syst…
Browse files Browse the repository at this point in the history
…em to schedule email action (#143282)

* Adding unsecured actions client

* Removing isESOCanEncrypt check

* Only getting actions client when needed in executor

* Changing to feature id allowlist. Adding unit tests

* Removing execution id

* Cleanup

* Fixing unit tests

* Removing slack from allowlist

* Make getUnsecuredActionsClient synchronous

* Add comment

* Adding functional tests

* Fixing types

* Fixing tests

* Removing unnecessary Promise.all

* Cleanup

* PR feedback

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
ymao1 and kibanamachine authored Oct 26, 2022
1 parent faa10dc commit 21806ca
Show file tree
Hide file tree
Showing 21 changed files with 1,463 additions and 76 deletions.
81 changes: 37 additions & 44 deletions x-pack/plugins/actions/server/create_execute_function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
import { ACTION_TASK_PARAMS_SAVED_OBJECT_TYPE } from './constants/saved_objects';
import { ExecuteOptions as ActionExecutorOptions } from './lib/action_executor';
import { extractSavedObjectReferences, isSavedObjectExecutionSource } from './lib';
import { RelatedSavedObjects } from './lib/related_saved_objects';

interface CreateExecuteFunctionOptions {
taskManager: TaskManagerStartContract;
Expand All @@ -25,21 +24,18 @@ interface CreateExecuteFunctionOptions {
preconfiguredActions: PreConfiguredAction[];
}

export interface ExecuteOptions extends Pick<ActionExecutorOptions, 'params' | 'source'> {
export interface ExecuteOptions
extends Pick<ActionExecutorOptions, 'params' | 'source' | 'relatedSavedObjects' | 'consumer'> {
id: string;
spaceId: string;
apiKey: string | null;
executionId: string;
consumer?: string;
relatedSavedObjects?: RelatedSavedObjects;
}

export interface ActionTaskParams extends Pick<ActionExecutorOptions, 'params'> {
actionId: string;
interface ActionTaskParams
extends Pick<ActionExecutorOptions, 'actionId' | 'params' | 'consumer' | 'relatedSavedObjects'> {
apiKey: string | null;
executionId: string;
consumer?: string;
relatedSavedObjects?: RelatedSavedObjects;
}

export interface GetConnectorsResult {
Expand Down Expand Up @@ -176,43 +172,40 @@ export function createBulkExecutionEnqueuerFunction({
connectorIsPreconfigured[id] = isPreconfigured;
});

const actions = await Promise.all(
actionsToExecute.map(async (actionToExecute) => {
// Get saved object references from action ID and relatedSavedObjects
const { references, relatedSavedObjectWithRefs } = extractSavedObjectReferences(
actionToExecute.id,
connectorIsPreconfigured[actionToExecute.id],
actionToExecute.relatedSavedObjects
);
const executionSourceReference = executionSourceAsSavedObjectReferences(
actionToExecute.source
);

const taskReferences = [];
if (executionSourceReference.references) {
taskReferences.push(...executionSourceReference.references);
}
if (references) {
taskReferences.push(...references);
}

spaceIds[actionToExecute.id] = actionToExecute.spaceId;

return {
type: ACTION_TASK_PARAMS_SAVED_OBJECT_TYPE,
attributes: {
actionId: actionToExecute.id,
params: actionToExecute.params,
apiKey: actionToExecute.apiKey,
executionId: actionToExecute.executionId,
consumer: actionToExecute.consumer,
relatedSavedObjects: relatedSavedObjectWithRefs,
},
references: taskReferences,
};
})
);
const actions = actionsToExecute.map((actionToExecute) => {
// Get saved object references from action ID and relatedSavedObjects
const { references, relatedSavedObjectWithRefs } = extractSavedObjectReferences(
actionToExecute.id,
connectorIsPreconfigured[actionToExecute.id],
actionToExecute.relatedSavedObjects
);
const executionSourceReference = executionSourceAsSavedObjectReferences(
actionToExecute.source
);

const taskReferences = [];
if (executionSourceReference.references) {
taskReferences.push(...executionSourceReference.references);
}
if (references) {
taskReferences.push(...references);
}

spaceIds[actionToExecute.id] = actionToExecute.spaceId;

return {
type: ACTION_TASK_PARAMS_SAVED_OBJECT_TYPE,
attributes: {
actionId: actionToExecute.id,
params: actionToExecute.params,
apiKey: actionToExecute.apiKey,
executionId: actionToExecute.executionId,
consumer: actionToExecute.consumer,
relatedSavedObjects: relatedSavedObjectWithRefs,
},
references: taskReferences,
};
});
const actionTaskParamsRecords: SavedObjectsBulkResponse<ActionTaskParams> =
await unsecuredSavedObjectsClient.bulkCreate(actions);
const taskInstances = actionTaskParamsRecords.saved_objects.map((so) => {
Expand Down
Loading

0 comments on commit 21806ca

Please sign in to comment.