Skip to content

Commit

Permalink
[ResponseOps][Alerting] Remove unused enqueueExecution function (elas…
Browse files Browse the repository at this point in the history
…tic#165120)

## Summary

We don't use this function anywhere, so this pr removes
`enqueueExecution` function in favor of the bulk function.
  • Loading branch information
doakalexi authored and eokoneyo committed Aug 31, 2023
1 parent fc59816 commit d133f09
Show file tree
Hide file tree
Showing 13 changed files with 1 addition and 1,505 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const createActionsClientMock = () => {
getBulk: jest.fn(),
getOAuthAccessToken: jest.fn(),
execute: jest.fn(),
enqueueExecution: jest.fn(),
ephemeralEnqueuedExecution: jest.fn(),
bulkEnqueueExecution: jest.fn(),
listTypes: jest.fn(),
Expand Down
107 changes: 0 additions & 107 deletions x-pack/plugins/actions/server/actions_client/actions_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ const unsecuredSavedObjectsClient = savedObjectsClientMock.create();
const scopedClusterClient = elasticsearchServiceMock.createScopedClusterClient();
const actionExecutor = actionExecutorMock.create();
const authorization = actionsAuthorizationMock.create();
const executionEnqueuer = jest.fn();
const ephemeralExecutionEnqueuer = jest.fn();
const bulkExecutionEnqueuer = jest.fn();
const request = httpServerMock.createKibanaRequest();
Expand Down Expand Up @@ -144,7 +143,6 @@ beforeEach(() => {
kibanaIndices,
inMemoryConnectors: [],
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -612,7 +610,6 @@ describe('create()', () => {
kibanaIndices,
inMemoryConnectors: [],
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -739,7 +736,6 @@ describe('create()', () => {
],

actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -802,7 +798,6 @@ describe('create()', () => {
scopedClusterClient,
kibanaIndices,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -864,7 +859,6 @@ describe('get()', () => {
scopedClusterClient,
kibanaIndices,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -902,7 +896,6 @@ describe('get()', () => {
scopedClusterClient,
kibanaIndices,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -960,7 +953,6 @@ describe('get()', () => {
scopedClusterClient,
kibanaIndices,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -1004,7 +996,6 @@ describe('get()', () => {
scopedClusterClient,
kibanaIndices,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -1127,7 +1118,6 @@ describe('get()', () => {
scopedClusterClient,
kibanaIndices,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -1172,7 +1162,6 @@ describe('get()', () => {
scopedClusterClient,
kibanaIndices,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -1207,7 +1196,6 @@ describe('get()', () => {
scopedClusterClient,
kibanaIndices,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -1279,7 +1267,6 @@ describe('getBulk()', () => {
scopedClusterClient,
kibanaIndices,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -1418,7 +1405,6 @@ describe('getBulk()', () => {
scopedClusterClient,
kibanaIndices,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -1514,7 +1500,6 @@ describe('getBulk()', () => {
scopedClusterClient,
kibanaIndices,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -1589,7 +1574,6 @@ describe('getBulk()', () => {
scopedClusterClient,
kibanaIndices,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -1675,7 +1659,6 @@ describe('getOAuthAccessToken()', () => {
scopedClusterClient,
kibanaIndices,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -2058,7 +2041,6 @@ describe('delete()', () => {
},
],
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -2095,7 +2077,6 @@ describe('delete()', () => {
},
],
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -2611,7 +2592,6 @@ describe('update()', () => {
},
],
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -2655,7 +2635,6 @@ describe('update()', () => {
},
],
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -2764,7 +2743,6 @@ describe('execute()', () => {
scopedClusterClient,
kibanaIndices,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -2829,7 +2807,6 @@ describe('execute()', () => {
scopedClusterClient,
kibanaIndices,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -2893,7 +2870,6 @@ describe('execute()', () => {
scopedClusterClient,
kibanaIndices,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -3029,85 +3005,6 @@ describe('execute()', () => {
});
});

describe('enqueueExecution()', () => {
describe('authorization', () => {
test('ensures user is authorised to excecute actions', async () => {
(getAuthorizationModeBySource as jest.Mock).mockImplementationOnce(() => {
return AuthorizationMode.RBAC;
});
await actionsClient.enqueueExecution({
id: uuidv4(),
params: {},
spaceId: 'default',
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
});
expect(authorization.ensureAuthorized).toHaveBeenCalledWith({
operation: 'execute',
});
});

test('throws when user is not authorised to create the type of action', async () => {
(getAuthorizationModeBySource as jest.Mock).mockImplementationOnce(() => {
return AuthorizationMode.RBAC;
});
authorization.ensureAuthorized.mockRejectedValue(
new Error(`Unauthorized to execute all actions`)
);

await expect(
actionsClient.enqueueExecution({
id: uuidv4(),
params: {},
spaceId: 'default',
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
})
).rejects.toMatchInlineSnapshot(`[Error: Unauthorized to execute all actions]`);

expect(authorization.ensureAuthorized).toHaveBeenCalledWith({
operation: 'execute',
});
});

test('tracks legacy RBAC', async () => {
(getAuthorizationModeBySource as jest.Mock).mockImplementationOnce(() => {
return AuthorizationMode.Legacy;
});

await actionsClient.enqueueExecution({
id: uuidv4(),
params: {},
spaceId: 'default',
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
});

expect(trackLegacyRBACExemption as jest.Mock).toBeCalledWith(
'enqueueExecution',
mockUsageCounter
);
});
});

test('calls the executionEnqueuer with the appropriate parameters', async () => {
const opts = {
id: uuidv4(),
params: { baz: false },
spaceId: 'default',
executionId: '123abc',
apiKey: Buffer.from('123:abc').toString('base64'),
source: asHttpRequestExecutionSource(request),
};
await expect(actionsClient.enqueueExecution(opts)).resolves.toMatchInlineSnapshot(`undefined`);

expect(executionEnqueuer).toHaveBeenCalledWith(unsecuredSavedObjectsClient, opts);
});
});

describe('bulkEnqueueExecution()', () => {
describe('authorization', () => {
test('ensures user is authorised to excecute actions', async () => {
Expand Down Expand Up @@ -3276,7 +3173,6 @@ describe('isPreconfigured()', () => {
scopedClusterClient,
kibanaIndices,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -3327,7 +3223,6 @@ describe('isPreconfigured()', () => {
scopedClusterClient,
kibanaIndices,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -3380,7 +3275,6 @@ describe('isSystemAction()', () => {
scopedClusterClient,
kibanaIndices,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -3431,7 +3325,6 @@ describe('isSystemAction()', () => {
scopedClusterClient,
kibanaIndices,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down
23 changes: 0 additions & 23 deletions x-pack/plugins/actions/server/actions_client/actions_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export interface ConstructorOptions {
unsecuredSavedObjectsClient: SavedObjectsClientContract;
inMemoryConnectors: InMemoryConnector[];
actionExecutor: ActionExecutorContract;
executionEnqueuer: ExecutionEnqueuer<void>;
ephemeralExecutionEnqueuer: ExecutionEnqueuer<RunNowResult>;
bulkExecutionEnqueuer: BulkExecutionEnqueuer<void>;
request: KibanaRequest;
Expand All @@ -139,7 +138,6 @@ export interface ActionsClientContext {
actionExecutor: ActionExecutorContract;
request: KibanaRequest;
authorization: ActionsAuthorization;
executionEnqueuer: ExecutionEnqueuer<void>;
ephemeralExecutionEnqueuer: ExecutionEnqueuer<RunNowResult>;
bulkExecutionEnqueuer: BulkExecutionEnqueuer<void>;
auditLogger?: AuditLogger;
Expand All @@ -159,7 +157,6 @@ export class ActionsClient {
unsecuredSavedObjectsClient,
inMemoryConnectors,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand All @@ -177,7 +174,6 @@ export class ActionsClient {
kibanaIndices,
inMemoryConnectors,
actionExecutor,
executionEnqueuer,
ephemeralExecutionEnqueuer,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -770,25 +766,6 @@ export class ActionsClient {
});
}

public async enqueueExecution(options: EnqueueExecutionOptions): Promise<void> {
const { source } = options;
if (
(await getAuthorizationModeBySource(this.context.unsecuredSavedObjectsClient, source)) ===
AuthorizationMode.RBAC
) {
/**
* For scheduled executions the additional authorization check
* for system actions (kibana privileges) will be performed
* inside the ActionExecutor at execution time
*/

await this.context.authorization.ensureAuthorized({ operation: 'execute' });
} else {
trackLegacyRBACExemption('enqueueExecution', this.context.usageCounter);
}
return this.context.executionEnqueuer(this.context.unsecuredSavedObjectsClient, options);
}

public async bulkEnqueueExecution(options: EnqueueExecutionOptions[]): Promise<void> {
const sources: Array<ActionExecutionSource<unknown>> = [];
options.forEach((option) => {
Expand Down
Loading

0 comments on commit d133f09

Please sign in to comment.