Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/platform/plugins/shared/actions/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ dependsOn:
- '@kbn/zod'
- '@kbn/connector-schemas'
- '@kbn/connector-specs'
- '@kbn/encrypted-saved-objects-shared'
tags:
- plugin
- prod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ const getEventLogClient = jest.fn();
const preSaveHook = jest.fn();
const postSaveHook = jest.fn();
const postDeleteHook = jest.fn();
const encryptedSavedObjectsClient = encryptedSavedObjectsMock.createClient();
const getAxiosInstanceWithAuth = jest.fn();
const isESOCanEncrypt = true;

let actionsClient: ActionsClient;
let mockedLicenseState: jest.Mocked<ILicenseState>;
Expand Down Expand Up @@ -147,6 +150,9 @@ beforeEach(() => {
usageCounter: mockUsageCounter,
connectorTokenClient,
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});
(getOAuthJwtAccessToken as jest.Mock).mockResolvedValue(`Bearer jwttokentokentoken`);
(getOAuthClientCredentialsAccessToken as jest.Mock).mockResolvedValue(
Expand Down Expand Up @@ -564,6 +570,9 @@ describe('create()', () => {
authorization: authorization as unknown as ActionsAuthorization,
connectorTokenClient: connectorTokenClientMock.create(),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

const savedObjectCreateResult = {
Expand Down Expand Up @@ -647,7 +656,9 @@ describe('create()', () => {
},
}),
],

encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
actionExecutor,
bulkExecutionEnqueuer,
request,
Expand Down Expand Up @@ -718,6 +729,9 @@ describe('create()', () => {
],
connectorTokenClient: connectorTokenClientMock.create(),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

await expect(
Expand Down Expand Up @@ -780,6 +794,9 @@ describe('get()', () => {
],
connectorTokenClient: connectorTokenClientMock.create(),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

await actionsClient.get({ id: 'testPreconfigured' });
Expand Down Expand Up @@ -808,6 +825,9 @@ describe('get()', () => {
],
connectorTokenClient: connectorTokenClientMock.create(),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

await expect(actionsClient.get({ id: 'system-connector-.cases' })).rejects.toThrow();
Expand Down Expand Up @@ -866,6 +886,9 @@ describe('get()', () => {
],
connectorTokenClient: connectorTokenClientMock.create(),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

authorization.ensureAuthorized.mockRejectedValue(
Expand Down Expand Up @@ -900,6 +923,9 @@ describe('get()', () => {
],
connectorTokenClient: connectorTokenClientMock.create(),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

authorization.ensureAuthorized.mockRejectedValue(
Expand Down Expand Up @@ -1026,6 +1052,9 @@ describe('get()', () => {
],
connectorTokenClient: connectorTokenClientMock.create(),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

const result = await actionsClient.get({ id: 'testPreconfigured' });
Expand Down Expand Up @@ -1060,6 +1089,9 @@ describe('get()', () => {
],
connectorTokenClient: connectorTokenClientMock.create(),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

await expect(
Expand Down Expand Up @@ -1088,6 +1120,9 @@ describe('get()', () => {
],
connectorTokenClient: connectorTokenClientMock.create(),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

expect(
Expand Down Expand Up @@ -1154,6 +1189,9 @@ describe('getBulk()', () => {
],
connectorTokenClient: connectorTokenClientMock.create(),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});
return actionsClient.getBulk({ ids: ['1', 'testPreconfigured'] });
}
Expand Down Expand Up @@ -1299,6 +1337,9 @@ describe('getBulk()', () => {
],
connectorTokenClient: connectorTokenClientMock.create(),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

const result = await actionsClient.getBulk({ ids: ['1', 'testPreconfigured'] });
Expand Down Expand Up @@ -1378,6 +1419,9 @@ describe('getBulk()', () => {
],
connectorTokenClient: connectorTokenClientMock.create(),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

await expect(
Expand Down Expand Up @@ -1444,6 +1488,9 @@ describe('getBulk()', () => {
],
connectorTokenClient: connectorTokenClientMock.create(),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

expect(
Expand Down Expand Up @@ -1502,6 +1549,9 @@ describe('getOAuthAccessToken()', () => {
],
connectorTokenClient: connectorTokenClientMock.create(),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});
return actionsClient.getOAuthAccessToken(requestBody, configurationUtilities);
}
Expand Down Expand Up @@ -1910,6 +1960,9 @@ describe('delete()', () => {
authorization: authorization as unknown as ActionsAuthorization,
connectorTokenClient: connectorTokenClientMock.create(),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

await expect(
Expand Down Expand Up @@ -1940,6 +1993,9 @@ describe('delete()', () => {
authorization: authorization as unknown as ActionsAuthorization,
connectorTokenClient: connectorTokenClientMock.create(),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

await expect(
Expand Down Expand Up @@ -2431,6 +2487,9 @@ describe('update()', () => {
authorization: authorization as unknown as ActionsAuthorization,
connectorTokenClient: connectorTokenClientMock.create(),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

await expect(
Expand Down Expand Up @@ -2468,6 +2527,9 @@ describe('update()', () => {
authorization: authorization as unknown as ActionsAuthorization,
connectorTokenClient: connectorTokenClientMock.create(),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

await expect(
Expand Down Expand Up @@ -2550,6 +2612,9 @@ describe('execute()', () => {
usageCounter: mockUsageCounter,
connectorTokenClient,
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

actionTypeRegistry.register(
Expand Down Expand Up @@ -2606,6 +2671,9 @@ describe('execute()', () => {
usageCounter: mockUsageCounter,
connectorTokenClient,
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

actionTypeRegistry.register(
Expand Down Expand Up @@ -2658,6 +2726,9 @@ describe('execute()', () => {
usageCounter: mockUsageCounter,
connectorTokenClient,
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

actionTypeRegistry.register(
Expand Down Expand Up @@ -2942,6 +3013,9 @@ describe('isPreconfigured()', () => {
logger,
}),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

expect(actionsClient.isPreconfigured('testPreconfigured')).toEqual(true);
Expand Down Expand Up @@ -2984,6 +3058,9 @@ describe('isPreconfigured()', () => {
logger,
}),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

expect(actionsClient.isPreconfigured(uuidv4())).toEqual(false);
Expand Down Expand Up @@ -3028,6 +3105,9 @@ describe('isSystemAction()', () => {
logger,
}),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

expect(actionsClient.isSystemAction('system-connector-.cases')).toEqual(true);
Expand Down Expand Up @@ -3070,6 +3150,9 @@ describe('isSystemAction()', () => {
logger,
}),
getEventLogClient,
encryptedSavedObjectsClient,
isESOCanEncrypt,
getAxiosInstanceWithAuth,
});

expect(actionsClient.isSystemAction(uuidv4())).toEqual(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import type {
import type { AuditLogger } from '@kbn/security-plugin/server';
import type { IEventLogClient } from '@kbn/event-log-plugin/server';
import type { KueryNode } from '@kbn/es-query';
import type { AxiosInstance } from 'axios';
import type { SpacesServiceSetup } from '@kbn/spaces-plugin/server';
import type { EncryptedSavedObjectsClient } from '@kbn/encrypted-saved-objects-shared';
import type { Connector, ConnectorWithExtraFindData } from '../application/connector/types';
import type { ConnectorType } from '../application/connector/types';
import { get } from '../application/connector/methods/get';
Expand Down Expand Up @@ -81,12 +84,14 @@ import { isPreconfigured } from '../lib/is_preconfigured';
import { isSystemAction } from '../lib/is_system_action';
import type { ConnectorExecuteParams } from '../application/connector/methods/execute/types';
import { connectorFromInMemoryConnector } from '../application/connector/lib/connector_from_in_memory_connector';
import { getAxiosInstance } from '../application/connector/methods/get_axios_instance';

export interface ConstructorOptions {
logger: Logger;
kibanaIndices: string[];
scopedClusterClient: IScopedClusterClient;
actionTypeRegistry: ActionTypeRegistry;
encryptedSavedObjectsClient: EncryptedSavedObjectsClient;
unsecuredSavedObjectsClient: SavedObjectsClientContract;
inMemoryConnectors: InMemoryConnector[];
actionExecutor: ActionExecutorContract;
Expand All @@ -97,12 +102,16 @@ export interface ConstructorOptions {
usageCounter?: UsageCounter;
connectorTokenClient: ConnectorTokenClientContract;
getEventLogClient: () => Promise<IEventLogClient>;
getAxiosInstanceWithAuth: (validatedSecrets: Record<string, unknown>) => Promise<AxiosInstance>;
spaces?: SpacesServiceSetup;
isESOCanEncrypt: boolean;
}

export interface ActionsClientContext {
logger: Logger;
kibanaIndices: string[];
scopedClusterClient: IScopedClusterClient;
encryptedSavedObjectsClient: EncryptedSavedObjectsClient;
unsecuredSavedObjectsClient: SavedObjectsClientContract;
actionTypeRegistry: ActionTypeRegistry;
inMemoryConnectors: InMemoryConnector[];
Expand All @@ -114,6 +123,9 @@ export interface ActionsClientContext {
usageCounter?: UsageCounter;
connectorTokenClient: ConnectorTokenClientContract;
getEventLogClient: () => Promise<IEventLogClient>;
getAxiosInstanceWithAuth: (validatedSecrets: Record<string, unknown>) => Promise<AxiosInstance>;
spaces?: SpacesServiceSetup;
isESOCanEncrypt: boolean;
}

export class ActionsClient {
Expand All @@ -124,6 +136,7 @@ export class ActionsClient {
actionTypeRegistry,
kibanaIndices,
scopedClusterClient,
encryptedSavedObjectsClient,
unsecuredSavedObjectsClient,
inMemoryConnectors,
actionExecutor,
Expand All @@ -134,10 +147,14 @@ export class ActionsClient {
usageCounter,
connectorTokenClient,
getEventLogClient,
getAxiosInstanceWithAuth,
spaces,
isESOCanEncrypt,
}: ConstructorOptions) {
this.context = {
logger,
actionTypeRegistry,
encryptedSavedObjectsClient,
unsecuredSavedObjectsClient,
scopedClusterClient,
kibanaIndices,
Expand All @@ -150,6 +167,9 @@ export class ActionsClient {
usageCounter,
connectorTokenClient,
getEventLogClient,
getAxiosInstanceWithAuth,
spaces,
isESOCanEncrypt,
};
}

Expand Down Expand Up @@ -499,6 +519,10 @@ export class ActionsClient {
return execute(this.context, connectorExecuteParams);
}

public async getAxiosInstance(actionId: string): Promise<AxiosInstance> {
return getAxiosInstance(this.context, actionId);
}

public async bulkEnqueueExecution(
options: EnqueueExecutionOptions[]
): Promise<ExecutionResponse> {
Expand Down
Loading