Skip to content

Commit f376471

Browse files
committed
Fix tests and in memory connectors bug
1 parent ad06f30 commit f376471

File tree

19 files changed

+162
-36
lines changed

19 files changed

+162
-36
lines changed

x-pack/platform/plugins/shared/actions/server/actions_client/actions_client.test.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,12 +1398,8 @@ describe('getBulk()', () => {
13981398
{
13991399
id: 'testPreconfigured',
14001400
actionTypeId: '.slack',
1401-
secrets: {
1402-
test: 'test1',
1403-
},
14041401
isPreconfigured: true,
14051402
name: 'test',
1406-
config: { foo: 'bar' },
14071403
},
14081404
{
14091405
id: '1',
@@ -1549,20 +1545,15 @@ describe('getBulk()', () => {
15491545
).toContainConnectors([
15501546
{
15511547
actionTypeId: '.slack',
1552-
config: { foo: 'bar' },
15531548
id: 'testPreconfigured',
15541549
isPreconfigured: true,
15551550
name: 'test',
1556-
secrets: {},
15571551
},
15581552
{
15591553
actionTypeId: '.cases',
1560-
config: {},
15611554
id: 'system-connector-.cases',
1562-
isMissingSecrets: false,
15631555
isSystemAction: true,
15641556
name: 'System action: .cases',
1565-
secrets: {},
15661557
},
15671558
{
15681559
actionTypeId: 'test',

x-pack/platform/plugins/shared/actions/server/actions_client/actions_client.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import type { ConnectorCreateParams } from '../application/connector/methods/cre
8080
import { isPreconfigured } from '../lib/is_preconfigured';
8181
import { isSystemAction } from '../lib/is_system_action';
8282
import type { ConnectorExecuteParams } from '../application/connector/methods/execute/types';
83+
import { connectorFromInMemoryConnector } from '../application/connector/lib/connector_from_in_memory_connector';
8384

8485
export interface ConstructorOptions {
8586
logger: Logger;
@@ -228,22 +229,28 @@ export class ActionsClient {
228229

229230
const actionResults = new Array<ActionResult>();
230231

231-
for (const actionId of ids) {
232-
const action = this.context.inMemoryConnectors.find(
233-
(inMemoryConnector) => inMemoryConnector.id === actionId
232+
for (const connectorId of ids) {
233+
const inMemoryConnector = this.context.inMemoryConnectors.find(
234+
(connector) => connector.id === connectorId
234235
);
235236

236-
/**
237-
* Getting system connector is not allowed
238-
* if throwIfSystemAction is set to true.
239-
* Default behavior is to throw
240-
*/
241-
if (action !== undefined && action.isSystemAction && throwIfSystemAction) {
242-
throw Boom.notFound(`Connector ${action.id} not found`);
243-
}
237+
if (inMemoryConnector !== undefined) {
238+
const connector = connectorFromInMemoryConnector({
239+
inMemoryConnector,
240+
id: connectorId,
241+
actionTypeRegistry: this.context.actionTypeRegistry,
242+
});
243+
244+
/**
245+
* Getting system connector is not allowed
246+
* if throwIfSystemAction is set to true.
247+
* Default behavior is to throw
248+
*/
249+
if (connector.isSystemAction && throwIfSystemAction) {
250+
throw Boom.notFound(`Connector ${connector.id} not found`);
251+
}
244252

245-
if (action !== undefined) {
246-
actionResults.push(action);
253+
actionResults.push(connector);
247254
}
248255
}
249256

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import type { ActionTypeRegistry } from '../../../action_type_registry';
9+
import type { InMemoryConnector } from '../../../types';
10+
import type { Connector } from '../types';
11+
import { isConnectorDeprecated } from './is_connector_deprecated';
12+
13+
export function connectorFromInMemoryConnector({
14+
id,
15+
inMemoryConnector,
16+
actionTypeRegistry,
17+
}: {
18+
id: string;
19+
inMemoryConnector: InMemoryConnector;
20+
actionTypeRegistry: ActionTypeRegistry;
21+
}): Connector {
22+
const connector: Connector = {
23+
id,
24+
actionTypeId: inMemoryConnector.actionTypeId,
25+
name: inMemoryConnector.name,
26+
isPreconfigured: inMemoryConnector.isPreconfigured,
27+
isSystemAction: inMemoryConnector.isSystemAction,
28+
isDeprecated: isConnectorDeprecated(inMemoryConnector),
29+
isConnectorTypeDeprecated: actionTypeRegistry.isDeprecated(inMemoryConnector.actionTypeId),
30+
};
31+
32+
if (inMemoryConnector.exposeConfig) {
33+
connector.config = inMemoryConnector.config;
34+
}
35+
return connector;
36+
}

x-pack/platform/plugins/shared/actions/server/application/connector/methods/get/get.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type { Connector } from '../../types';
1212
import { ConnectorAuditAction, connectorAuditEvent } from '../../../../lib/audit_events';
1313
import { isConnectorDeprecated } from '../../lib';
1414
import type { GetParams } from './types';
15+
import { connectorFromInMemoryConnector } from '../../lib/connector_from_in_memory_connector';
1516

1617
export async function get({
1718
context,
@@ -59,21 +60,11 @@ export async function get({
5960
})
6061
);
6162

62-
connector = {
63+
connector = connectorFromInMemoryConnector({
6364
id,
64-
actionTypeId: foundInMemoryConnector.actionTypeId,
65-
name: foundInMemoryConnector.name,
66-
isPreconfigured: foundInMemoryConnector.isPreconfigured,
67-
isSystemAction: foundInMemoryConnector.isSystemAction,
68-
isDeprecated: isConnectorDeprecated(foundInMemoryConnector),
69-
isConnectorTypeDeprecated: actionTypeRegistry.isDeprecated(
70-
foundInMemoryConnector.actionTypeId
71-
),
72-
};
73-
74-
if (foundInMemoryConnector.exposeConfig) {
75-
connector.config = foundInMemoryConnector.config;
76-
}
65+
inMemoryConnector: foundInMemoryConnector,
66+
actionTypeRegistry,
67+
});
7768
} else {
7869
const result = await getConnectorSo({
7970
unsecuredSavedObjectsClient: context.unsecuredSavedObjectsClient,

x-pack/platform/plugins/shared/actions/server/application/connector/methods/list_types/list_types.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ describe('listTypes()', () => {
115115
enabledInLicense: true,
116116
supportedFeatureIds: ['alerting'],
117117
isSystemActionType: false,
118+
isDeprecated: false,
118119
},
119120
]);
120121
});
@@ -172,6 +173,7 @@ describe('listTypes()', () => {
172173
enabledInLicense: true,
173174
supportedFeatureIds: ['alerting'],
174175
isSystemActionType: false,
176+
isDeprecated: false,
175177
},
176178
{
177179
id: 'my-action-type-2',
@@ -182,6 +184,7 @@ describe('listTypes()', () => {
182184
enabled: true,
183185
enabledInConfig: true,
184186
enabledInLicense: true,
187+
isDeprecated: false,
185188
},
186189
]);
187190
});
@@ -226,6 +229,7 @@ describe('listTypes()', () => {
226229
enabledInLicense: true,
227230
supportedFeatureIds: ['alerting'],
228231
isSystemActionType: false,
232+
isDeprecated: false,
229233
},
230234
{
231235
id: '.cases',
@@ -236,6 +240,7 @@ describe('listTypes()', () => {
236240
enabled: true,
237241
enabledInConfig: true,
238242
enabledInLicense: true,
243+
isDeprecated: false,
239244
},
240245
]);
241246
});

x-pack/platform/plugins/shared/actions/server/routes/connector/create/create.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ describe('createConnectorRoute', () => {
5151
'isDeprecated',
5252
'isMissingSecrets',
5353
'isSystemAction',
54+
'isConnectorTypeDeprecated',
5455
]),
5556
connector_type_id: createResult.actionTypeId,
5657
is_preconfigured: createResult.isPreconfigured,
5758
is_deprecated: createResult.isDeprecated,
5859
is_missing_secrets: createResult.isMissingSecrets,
5960
is_system_action: createResult.isSystemAction,
61+
is_connector_type_deprecated: createResult.isConnectorTypeDeprecated,
6062
};
6163

6264
const actionsClient = actionsClientMock.create();

x-pack/platform/plugins/shared/actions/server/routes/connector/get/get.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe('getConnectorRoute', () => {
3737
id: '1',
3838
actionTypeId: '2',
3939
name: 'action name',
40+
isMissingSecrets: false,
4041
});
4142

4243
const actionsClient = actionsClientMock.create();

x-pack/platform/plugins/shared/actions/server/routes/connector/get_all_system/get_all_system.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe('getAllConnectorsIncludingSystemRoute', () => {
4141
name: 'my system action',
4242
actionTypeId: '.system-action-type',
4343
isMissingSecrets: false,
44+
config: {},
4445
}),
4546
]);
4647

@@ -53,6 +54,7 @@ describe('getAllConnectorsIncludingSystemRoute', () => {
5354
"config": Object {},
5455
"connector_type_id": ".system-action-type",
5556
"id": ".system-action-id",
57+
"is_connector_type_deprecated": false,
5658
"is_deprecated": false,
5759
"is_missing_secrets": false,
5860
"is_preconfigured": false,
@@ -78,6 +80,7 @@ describe('getAllConnectorsIncludingSystemRoute', () => {
7880
is_system_action: true,
7981
name: 'my system action',
8082
referenced_by_count: 0,
83+
is_connector_type_deprecated: false,
8184
},
8285
],
8386
});

x-pack/platform/plugins/shared/actions/server/routes/connector/list_types_system/list_types_system.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ describe('listTypesWithSystemRoute', () => {
5858
"enabled_in_config": true,
5959
"enabled_in_license": true,
6060
"id": "1",
61+
"is_deprecated": false,
6162
"is_system_action_type": true,
6263
"minimum_license_required": "gold",
6364
"name": "name",
@@ -82,6 +83,7 @@ describe('listTypesWithSystemRoute', () => {
8283
minimum_license_required: 'gold',
8384
is_system_action_type: true,
8485
sub_feature: 'endpointSecurity',
86+
is_deprecated: false,
8587
},
8688
],
8789
});
@@ -126,6 +128,7 @@ describe('listTypesWithSystemRoute', () => {
126128
"enabled_in_config": true,
127129
"enabled_in_license": true,
128130
"id": "1",
131+
"is_deprecated": false,
129132
"is_system_action_type": false,
130133
"minimum_license_required": "gold",
131134
"name": "name",
@@ -159,6 +162,7 @@ describe('listTypesWithSystemRoute', () => {
159162
supported_feature_ids: ['alerting'],
160163
minimum_license_required: 'gold',
161164
is_system_action_type: false,
165+
is_deprecated: false,
162166
},
163167
],
164168
});

x-pack/platform/test/alerting_api_integration/security_and_spaces/group2/tests/actions/get.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export default function getConnectorTests({ getService }: FtrProviderContext) {
6565
is_system_action: false,
6666
connector_type_id: 'test.index-record',
6767
is_deprecated: false,
68+
is_connector_type_deprecated: false,
6869
is_missing_secrets: false,
6970
name: 'My Connector',
7071
config: {

0 commit comments

Comments
 (0)