Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Actions] Introduce the isSystemAction property to actions #160753

Merged
merged 13 commits into from
Jun 30, 2023
21 changes: 21 additions & 0 deletions x-pack/plugins/actions/server/action_type_registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('actionTypeRegistry', () => {
secrets: {},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
},
],
};
Expand Down Expand Up @@ -215,6 +216,26 @@ describe('actionTypeRegistry', () => {
});
expect(actionTypeRegistryParams.licensing.featureUsage.register).not.toHaveBeenCalled();
});

test('does not allows registering system actions', () => {
const actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);

expect(() =>
actionTypeRegistry.register({
id: 'my-action-type',
name: 'My action type',
minimumLicenseRequired: 'basic',
supportedFeatureIds: ['alerting'],
isSystemAction: true,
validate: {
config: { schema: schema.object({}) },
secrets: { schema: schema.object({}) },
params: { schema: schema.object({}) },
},
executor,
})
).toThrowErrorMatchingInlineSnapshot(`"System actions are not supported"`);
});
});

describe('get()', () => {
Expand Down
12 changes: 12 additions & 0 deletions x-pack/plugins/actions/server/action_type_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ export class ActionTypeRegistry {
Params extends ActionTypeParams = ActionTypeParams,
ExecutorResultData = void
>(actionType: ActionType<Config, Secrets, Params, ExecutorResultData>) {
// TODO: Remove when system action are supported
if (actionType.isSystemAction) {
throw new Error(
i18n.translate(
'xpack.actions.actionTypeRegistry.register.systemActionsNotSupportedErrorMessage',
{
defaultMessage: 'System actions are not supported',
}
)
);
}

if (this.has(actionType.id)) {
throw new Error(
i18n.translate(
Expand Down
22 changes: 22 additions & 0 deletions x-pack/plugins/actions/server/actions_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ describe('create()', () => {
expect(result).toEqual({
id: '1',
isPreconfigured: false,
isSystemAction: false,
isDeprecated: false,
name: 'my name',
actionTypeId: 'my-action-type',
Expand Down Expand Up @@ -532,6 +533,7 @@ describe('create()', () => {
expect(result).toEqual({
id: '1',
isPreconfigured: false,
isSystemAction: false,
isDeprecated: false,
name: 'my name',
actionTypeId: 'my-action-type',
Expand Down Expand Up @@ -722,6 +724,7 @@ describe('create()', () => {
},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'test',
config: {
foo: 'bar',
Expand Down Expand Up @@ -799,6 +802,7 @@ describe('get()', () => {
},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'test',
config: {
foo: 'bar',
Expand Down Expand Up @@ -860,6 +864,7 @@ describe('get()', () => {
},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'test',
config: {
foo: 'bar',
Expand Down Expand Up @@ -950,6 +955,7 @@ describe('get()', () => {
expect(result).toEqual({
id: '1',
isPreconfigured: false,
isSystemAction: false,
isDeprecated: false,
});
expect(unsecuredSavedObjectsClient.get).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -983,6 +989,7 @@ describe('get()', () => {
},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'test',
config: {
foo: 'bar',
Expand All @@ -999,6 +1006,7 @@ describe('get()', () => {
actionTypeId: '.slack',
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'test',
});
expect(unsecuredSavedObjectsClient.get).not.toHaveBeenCalled();
Expand Down Expand Up @@ -1057,6 +1065,7 @@ describe('getAll()', () => {
secrets: {},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'test',
config: {
foo: 'bar',
Expand Down Expand Up @@ -1200,6 +1209,7 @@ describe('getAll()', () => {
secrets: {},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'test',
config: {
foo: 'bar',
Expand All @@ -1214,6 +1224,7 @@ describe('getAll()', () => {
{
id: '1',
isPreconfigured: false,
isSystemAction: false,
isDeprecated: false,
name: 'test',
config: {
Expand All @@ -1226,6 +1237,7 @@ describe('getAll()', () => {
id: 'testPreconfigured',
actionTypeId: '.slack',
isPreconfigured: true,
isSystemAction: false,
isDeprecated: false,
name: 'test',
referencedByCount: 2,
Expand Down Expand Up @@ -1283,6 +1295,7 @@ describe('getBulk()', () => {
secrets: {},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'test',
config: {
foo: 'bar',
Expand Down Expand Up @@ -1420,6 +1433,7 @@ describe('getBulk()', () => {
secrets: {},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'test',
config: {
foo: 'bar',
Expand All @@ -1438,6 +1452,7 @@ describe('getBulk()', () => {
},
id: 'testPreconfigured',
isPreconfigured: true,
isSystemAction: false,
isDeprecated: false,
name: 'test',
secrets: {},
Expand All @@ -1450,6 +1465,7 @@ describe('getBulk()', () => {
id: '1',
isMissingSecrets: false,
isPreconfigured: false,
isSystemAction: false,
isDeprecated: false,
name: 'test',
},
Expand Down Expand Up @@ -1479,6 +1495,7 @@ describe('getOAuthAccessToken()', () => {
actionTypeId: '.slack',
secrets: {},
isPreconfigured: true,
isSystemAction: false,
isDeprecated: false,
name: 'test',
config: {
Expand Down Expand Up @@ -1982,6 +1999,7 @@ describe('update()', () => {
expect(result).toEqual({
id: 'my-action',
isPreconfigured: false,
isSystemAction: false,
isDeprecated: false,
actionTypeId: 'my-action-type',
isMissingSecrets: false,
Expand Down Expand Up @@ -2060,6 +2078,7 @@ describe('update()', () => {
expect(result).toEqual({
id: 'my-action',
isPreconfigured: false,
isSystemAction: false,
isDeprecated: false,
actionTypeId: 'my-action-type',
isMissingSecrets: true,
Expand Down Expand Up @@ -2217,6 +2236,7 @@ describe('update()', () => {
expect(result).toEqual({
id: 'my-action',
isPreconfigured: false,
isSystemAction: false,
isDeprecated: false,
actionTypeId: 'my-action-type',
isMissingSecrets: true,
Expand Down Expand Up @@ -2703,6 +2723,7 @@ describe('isPreconfigured()', () => {
},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'test',
config: {
foo: 'bar',
Expand Down Expand Up @@ -2742,6 +2763,7 @@ describe('isPreconfigured()', () => {
},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'test',
config: {
foo: 'bar',
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/actions/server/actions_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ export class ActionsClient {
name: result.attributes.name,
config: result.attributes.config,
isPreconfigured: false,
isSystemAction: false,
isDeprecated: isConnectorDeprecated(result.attributes),
};
}
Expand Down Expand Up @@ -357,6 +358,7 @@ export class ActionsClient {
name: result.attributes.name as string,
config: result.attributes.config as Record<string, unknown>,
isPreconfigured: false,
isSystemAction: false,
isDeprecated: isConnectorDeprecated(result.attributes),
};
}
Expand Down Expand Up @@ -394,6 +396,7 @@ export class ActionsClient {
actionTypeId: preconfiguredActionsList.actionTypeId,
name: preconfiguredActionsList.name,
isPreconfigured: true,
isSystemAction: false,
isDeprecated: isConnectorDeprecated(preconfiguredActionsList),
};
}
Expand All @@ -414,6 +417,7 @@ export class ActionsClient {
name: result.attributes.name,
config: result.attributes.config,
isPreconfigured: false,
isSystemAction: false,
isDeprecated: isConnectorDeprecated(result.attributes),
};
}
Expand Down Expand Up @@ -460,6 +464,7 @@ export class ActionsClient {
name: preconfiguredAction.name,
isPreconfigured: true,
isDeprecated: isConnectorDeprecated(preconfiguredAction),
isSystemAction: false,
})),
].sort((a, b) => a.name.localeCompare(b.name));
return await injectExtraFindData(this.kibanaIndices, this.scopedClusterClient, mergedResult);
Expand Down Expand Up @@ -893,6 +898,7 @@ function actionFromSavedObject(
...savedObject.attributes,
isPreconfigured: false,
isDeprecated,
isSystemAction: false,
};
}

Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/actions/server/create_execute_function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ describe('execute()', () => {
config: {},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'x',
secrets: {},
},
Expand Down Expand Up @@ -333,6 +334,7 @@ describe('execute()', () => {
config: {},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'x',
secrets: {},
},
Expand Down Expand Up @@ -519,6 +521,7 @@ describe('execute()', () => {
name: 'Slack #xyz',
secrets: {},
isPreconfigured: true,
isSystemAction: false,
isDeprecated: false,
},
],
Expand Down Expand Up @@ -829,6 +832,7 @@ describe('bulkExecute()', () => {
config: {},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'x',
secrets: {},
},
Expand Down Expand Up @@ -925,6 +929,7 @@ describe('bulkExecute()', () => {
config: {},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'x',
secrets: {},
},
Expand Down Expand Up @@ -1143,6 +1148,7 @@ describe('bulkExecute()', () => {
secrets: {},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
},
],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('bulkExecute()', () => {
config: {},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'x',
secrets: {},
},
Expand Down Expand Up @@ -137,6 +138,7 @@ describe('bulkExecute()', () => {
config: {},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'x',
secrets: {},
},
Expand Down Expand Up @@ -254,6 +256,7 @@ describe('bulkExecute()', () => {
config: {},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'x',
secrets: {},
},
Expand Down Expand Up @@ -395,6 +398,7 @@ describe('bulkExecute()', () => {
config: {},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'x',
secrets: {},
},
Expand Down Expand Up @@ -430,6 +434,7 @@ describe('bulkExecute()', () => {
config: {},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'x',
secrets: {},
},
Expand Down Expand Up @@ -466,6 +471,7 @@ describe('bulkExecute()', () => {
config: {},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'x',
secrets: {},
},
Expand All @@ -475,6 +481,7 @@ describe('bulkExecute()', () => {
config: {},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
name: 'x',
secrets: {},
},
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/actions/server/lib/action_executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ actionExecutor.initialize({
},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
},
],
});
Expand Down Expand Up @@ -988,6 +989,7 @@ test('should not throw error if action is preconfigured and isESOCanEncrypt is f
},
isPreconfigured: true,
isDeprecated: false,
isSystemAction: false,
},
],
});
Expand Down
Loading