mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Actions] Sub actions framework: Get Service
instance with a function (#169484)
This commit is contained in:
parent
96b1829a44
commit
3587c20835
14 changed files with 25 additions and 34 deletions
|
@ -350,7 +350,7 @@ plugins.actions.registerSubActionConnectorType({
|
|||
name: 'Test: Sub action connector',
|
||||
minimumLicenseRequired: 'platinum' as const,
|
||||
schema: { config: TestConfigSchema, secrets: TestSecretsSchema },
|
||||
Service: TestSubActionConnector,
|
||||
getService: (params) => new TestSubActionConnector(params),
|
||||
renderParameterTemplates: renderTestTemplate
|
||||
});
|
||||
```
|
||||
|
@ -368,6 +368,6 @@ plugins.actions.registerSubActionConnectorType({
|
|||
minimumLicenseRequired: 'platinum' as const,
|
||||
schema: { config: TestConfigSchema, secrets: TestSecretsSchema },
|
||||
validators: [{type: ValidatorType.CONFIG, validate: urlAllowListValidator('url')}]
|
||||
Service: TestSubActionConnector,
|
||||
getService: (params) => new TestSubActionConnector(params),
|
||||
});
|
||||
```
|
||||
|
|
|
@ -19,7 +19,7 @@ import {
|
|||
TestSecrets,
|
||||
TestExecutor,
|
||||
} from './mocks';
|
||||
import { IService } from './types';
|
||||
import { IService, ServiceParams } from './types';
|
||||
|
||||
describe('Executor', () => {
|
||||
const actionId = 'test-action-id';
|
||||
|
@ -40,7 +40,8 @@ describe('Executor', () => {
|
|||
config: TestConfigSchema,
|
||||
secrets: TestSecretsSchema,
|
||||
},
|
||||
Service,
|
||||
getService: (serviceParams: ServiceParams<TestConfig, TestSecrets>) =>
|
||||
new Service(serviceParams),
|
||||
};
|
||||
|
||||
return buildExecutor({ configurationUtilities: mockedActionsConfig, logger, connector });
|
||||
|
|
|
@ -33,7 +33,7 @@ export const buildExecutor = <
|
|||
const subAction = params.subAction;
|
||||
const subActionParams = params.subActionParams;
|
||||
|
||||
const service = new connector.Service({
|
||||
const service = connector.getService({
|
||||
connector: { id: actionId, type: connector.id },
|
||||
config,
|
||||
secrets,
|
||||
|
|
|
@ -16,6 +16,7 @@ import {
|
|||
TestSubActionConnector,
|
||||
} from './mocks';
|
||||
import { register } from './register';
|
||||
import { ServiceParams } from './types';
|
||||
|
||||
describe('Registration', () => {
|
||||
const renderedVariables = { body: '' };
|
||||
|
@ -30,7 +31,8 @@ describe('Registration', () => {
|
|||
config: TestConfigSchema,
|
||||
secrets: TestSecretsSchema,
|
||||
},
|
||||
Service: TestSubActionConnector,
|
||||
getService: (serviceParams: ServiceParams<TestConfig, TestSecrets>) =>
|
||||
new TestSubActionConnector(serviceParams),
|
||||
renderParameterTemplates: mockRenderParameterTemplates,
|
||||
};
|
||||
|
||||
|
|
|
@ -9,24 +9,11 @@ import { PublicMethodsOf } from '@kbn/utility-types';
|
|||
import { Logger } from '@kbn/core/server';
|
||||
import { ActionsConfigurationUtilities } from '../actions_config';
|
||||
import { ActionTypeRegistry } from '../action_type_registry';
|
||||
import { SubActionConnector } from './sub_action_connector';
|
||||
import { CaseConnector } from './case';
|
||||
import { ActionTypeConfig, ActionTypeSecrets } from '../types';
|
||||
import { buildExecutor } from './executor';
|
||||
import { ExecutorParams, SubActionConnectorType, IService } from './types';
|
||||
import { ExecutorParams, SubActionConnectorType } from './types';
|
||||
import { buildValidators } from './validators';
|
||||
|
||||
const validateService = <Config, Secrets>(Service: IService<Config, Secrets>) => {
|
||||
if (
|
||||
!(Service.prototype instanceof CaseConnector) &&
|
||||
!(Service.prototype instanceof SubActionConnector)
|
||||
) {
|
||||
throw new Error(
|
||||
'Service must be extend one of the abstract classes: SubActionConnector or CaseConnector'
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export const register = <Config extends ActionTypeConfig, Secrets extends ActionTypeSecrets>({
|
||||
actionTypeRegistry,
|
||||
connector,
|
||||
|
@ -38,8 +25,6 @@ export const register = <Config extends ActionTypeConfig, Secrets extends Action
|
|||
connector: SubActionConnectorType<Config, Secrets>;
|
||||
logger: Logger;
|
||||
}) => {
|
||||
validateService(connector.Service);
|
||||
|
||||
const validators = buildValidators<Config, Secrets>({ connector, configurationUtilities });
|
||||
const executor = buildExecutor({
|
||||
connector,
|
||||
|
|
|
@ -79,7 +79,7 @@ export interface SubActionConnectorType<Config, Secrets> {
|
|||
secrets: Type<Secrets>;
|
||||
};
|
||||
validators?: Array<ConfigValidator<Config> | SecretsValidator<Secrets>>;
|
||||
Service: IService<Config, Secrets>;
|
||||
getService: (params: ServiceParams<Config, Secrets>) => SubActionConnector<Config, Secrets>;
|
||||
renderParameterTemplates?: RenderParameterTemplates<ExecutorParams>;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import {
|
|||
TestSecrets,
|
||||
TestSubActionConnector,
|
||||
} from './mocks';
|
||||
import { IService, SubActionConnectorType, ValidatorType } from './types';
|
||||
import { IService, ServiceParams, SubActionConnectorType, ValidatorType } from './types';
|
||||
import { buildValidators } from './validators';
|
||||
|
||||
describe('Validators', () => {
|
||||
|
@ -30,7 +30,8 @@ describe('Validators', () => {
|
|||
config: TestConfigSchema,
|
||||
secrets: TestSecretsSchema,
|
||||
},
|
||||
Service,
|
||||
getService: (serviceParams: ServiceParams<TestConfig, TestSecrets>) =>
|
||||
new Service(serviceParams),
|
||||
};
|
||||
|
||||
return buildValidators({ configurationUtilities: mockedActionsConfig, connector });
|
||||
|
@ -59,7 +60,8 @@ describe('Validators', () => {
|
|||
validator: secretsValidator,
|
||||
},
|
||||
],
|
||||
Service,
|
||||
getService: (serviceParams: ServiceParams<TestConfig, TestSecrets>) =>
|
||||
new Service(serviceParams),
|
||||
};
|
||||
|
||||
return {
|
||||
|
|
|
@ -23,7 +23,7 @@ import { renderParameterTemplates } from './render';
|
|||
export const getConnectorType = (): SubActionConnectorType<Config, Secrets> => ({
|
||||
id: BEDROCK_CONNECTOR_ID,
|
||||
name: BEDROCK_TITLE,
|
||||
Service: BedrockConnector,
|
||||
getService: (params) => new BedrockConnector(params),
|
||||
schema: {
|
||||
config: ConfigSchema,
|
||||
secrets: SecretsSchema,
|
||||
|
|
|
@ -26,7 +26,7 @@ export function getConnectorType(): D3SecurityConnectorType {
|
|||
id: D3_SECURITY_CONNECTOR_ID,
|
||||
minimumLicenseRequired: 'gold',
|
||||
name: D3_SECURITY_TITLE,
|
||||
Service: D3SecurityConnector,
|
||||
getService: (params) => new D3SecurityConnector(params),
|
||||
supportedFeatureIds: [AlertingConnectorFeatureId, SecurityConnectorFeatureId],
|
||||
schema: {
|
||||
config: D3SecurityConfigSchema,
|
||||
|
|
|
@ -27,7 +27,7 @@ import { renderParameterTemplates } from './render';
|
|||
export const getConnectorType = (): SubActionConnectorType<Config, Secrets> => ({
|
||||
id: OPENAI_CONNECTOR_ID,
|
||||
name: OPENAI_TITLE,
|
||||
Service: OpenAIConnector,
|
||||
getService: (params) => new OpenAIConnector(params),
|
||||
schema: {
|
||||
config: ConfigSchema,
|
||||
secrets: SecretsSchema,
|
||||
|
|
|
@ -24,7 +24,7 @@ import { renderParameterTemplates } from './render_template_variables';
|
|||
|
||||
export const getOpsgenieConnectorType = (): SubActionConnectorType<Config, Secrets> => {
|
||||
return {
|
||||
Service: OpsgenieConnector,
|
||||
getService: (params) => new OpsgenieConnector(params),
|
||||
minimumLicenseRequired: 'platinum',
|
||||
name: i18n.OPSGENIE_NAME,
|
||||
id: OpsgenieConnectorTypeId,
|
||||
|
|
|
@ -26,7 +26,7 @@ export const getSentinelOneConnectorType = (): SubActionConnectorType<
|
|||
> => ({
|
||||
id: SENTINELONE_CONNECTOR_ID,
|
||||
name: SENTINELONE_TITLE,
|
||||
Service: SentinelOneConnector,
|
||||
getService: (params) => new SentinelOneConnector(params),
|
||||
schema: {
|
||||
config: SentinelOneConfigSchema,
|
||||
secrets: SentinelOneSecretsSchema,
|
||||
|
|
|
@ -20,7 +20,7 @@ import { renderParameterTemplates } from './render';
|
|||
export const getTinesConnectorType = (): SubActionConnectorType<TinesConfig, TinesSecrets> => ({
|
||||
id: TINES_CONNECTOR_ID,
|
||||
name: TINES_TITLE,
|
||||
Service: TinesConnector,
|
||||
getService: (params) => new TinesConnector(params),
|
||||
schema: {
|
||||
config: TinesConfigSchema,
|
||||
secrets: TinesSecretsSchema,
|
||||
|
|
|
@ -79,13 +79,14 @@ export const getTestSubActionConnector = (
|
|||
|
||||
public async noData() {}
|
||||
}
|
||||
|
||||
return {
|
||||
id: 'test.sub-action-connector',
|
||||
name: 'Test: Sub action connector',
|
||||
minimumLicenseRequired: 'platinum' as const,
|
||||
supportedFeatureIds: ['alerting'],
|
||||
schema: { config: TestConfigSchema, secrets: TestSecretsSchema },
|
||||
Service: TestSubActionConnector,
|
||||
getService: (params) => new TestSubActionConnector(params),
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -106,6 +107,6 @@ export const getTestSubActionConnectorWithoutSubActions = (
|
|||
minimumLicenseRequired: 'platinum' as const,
|
||||
supportedFeatureIds: ['alerting'],
|
||||
schema: { config: TestConfigSchema, secrets: TestSecretsSchema },
|
||||
Service: TestNoSubActions,
|
||||
getService: (params) => new TestNoSubActions(params),
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue