resolved conflicts (#107009)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
b2196b8b73
commit
2c3734073d
|
@ -701,7 +701,7 @@
|
|||
"description": [],
|
||||
"signature": [
|
||||
"() => Set<",
|
||||
"RegistryAlertType",
|
||||
"RegistryRuleType",
|
||||
">"
|
||||
],
|
||||
"source": {
|
||||
|
@ -1330,7 +1330,7 @@
|
|||
"description": [],
|
||||
"signature": [
|
||||
"() => Set<",
|
||||
"RegistryAlertType",
|
||||
"RegistryRuleType",
|
||||
">"
|
||||
],
|
||||
"source": {
|
||||
|
|
|
@ -2187,10 +2187,10 @@
|
|||
},
|
||||
{
|
||||
"parentPluginId": "triggersActionsUi",
|
||||
"id": "def-public.TriggersAndActionsUiServices.alertTypeRegistry",
|
||||
"id": "def-public.TriggersAndActionsUiServices.ruleTypeRegistry",
|
||||
"type": "Object",
|
||||
"tags": [],
|
||||
"label": "alertTypeRegistry",
|
||||
"label": "ruleTypeRegistry",
|
||||
"description": [],
|
||||
"signature": [
|
||||
"{ get: (id: string) => ",
|
||||
|
@ -2535,10 +2535,10 @@
|
|||
},
|
||||
{
|
||||
"parentPluginId": "triggersActionsUi",
|
||||
"id": "def-public.AlertTypeRegistryContract",
|
||||
"id": "def-public.RuleTypeRegistryContract",
|
||||
"type": "Type",
|
||||
"tags": [],
|
||||
"label": "AlertTypeRegistryContract",
|
||||
"label": "RuleTypeRegistryContract",
|
||||
"description": [],
|
||||
"signature": [
|
||||
"{ get: (id: string) => ",
|
||||
|
@ -3623,10 +3623,10 @@
|
|||
},
|
||||
{
|
||||
"parentPluginId": "triggersActionsUi",
|
||||
"id": "def-public.TriggersAndActionsUIPublicPluginSetup.alertTypeRegistry",
|
||||
"id": "def-public.TriggersAndActionsUIPublicPluginSetup.ruleTypeRegistry",
|
||||
"type": "Object",
|
||||
"tags": [],
|
||||
"label": "alertTypeRegistry",
|
||||
"label": "ruleTypeRegistry",
|
||||
"description": [],
|
||||
"signature": [
|
||||
"TypeRegistry",
|
||||
|
@ -3684,10 +3684,10 @@
|
|||
},
|
||||
{
|
||||
"parentPluginId": "triggersActionsUi",
|
||||
"id": "def-public.TriggersAndActionsUIPublicPluginStart.alertTypeRegistry",
|
||||
"id": "def-public.TriggersAndActionsUIPublicPluginStart.ruleTypeRegistry",
|
||||
"type": "Object",
|
||||
"tags": [],
|
||||
"label": "alertTypeRegistry",
|
||||
"label": "ruleTypeRegistry",
|
||||
"description": [],
|
||||
"signature": [
|
||||
"TypeRegistry",
|
||||
|
|
|
@ -55,8 +55,8 @@ export class AlertingExamplePlugin implements Plugin<Setup, Start, AlertingExamp
|
|||
},
|
||||
});
|
||||
|
||||
triggersActionsUi.alertTypeRegistry.register(getAlwaysFiringAlertType());
|
||||
triggersActionsUi.alertTypeRegistry.register(getPeopleInSpaceAlertType());
|
||||
triggersActionsUi.ruleTypeRegistry.register(getAlwaysFiringAlertType());
|
||||
triggersActionsUi.ruleTypeRegistry.register(getPeopleInSpaceAlertType());
|
||||
|
||||
registerNavigation(alerting);
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import { Request } from '@hapi/hapi';
|
||||
import { alertTypeRegistryMock } from './alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from './rule_type_registry.mock';
|
||||
import { KibanaRequest } from '../../../../src/core/server';
|
||||
import { savedObjectsClientMock } from '../../../../src/core/server/mocks';
|
||||
import { securityMock } from '../../security/server/mocks';
|
||||
|
@ -27,7 +27,7 @@ const securityPluginSetup = securityMock.createSetup();
|
|||
const securityPluginStart = securityMock.createStart();
|
||||
|
||||
const alertingAuthorizationClientFactoryParams: jest.Mocked<AlertingAuthorizationClientFactoryOpts> = {
|
||||
alertTypeRegistry: alertTypeRegistryMock.create(),
|
||||
ruleTypeRegistry: ruleTypeRegistryMock.create(),
|
||||
getSpace: jest.fn(),
|
||||
features,
|
||||
};
|
||||
|
@ -69,7 +69,7 @@ test('creates an alerting authorization client with proper constructor arguments
|
|||
expect(AlertingAuthorization).toHaveBeenCalledWith({
|
||||
request,
|
||||
authorization: securityPluginStart.authz,
|
||||
alertTypeRegistry: alertingAuthorizationClientFactoryParams.alertTypeRegistry,
|
||||
ruleTypeRegistry: alertingAuthorizationClientFactoryParams.ruleTypeRegistry,
|
||||
features: alertingAuthorizationClientFactoryParams.features,
|
||||
auditLogger: expect.any(AlertingAuthorizationAuditLogger),
|
||||
getSpace: expect.any(Function),
|
||||
|
@ -96,7 +96,7 @@ test('creates an alerting authorization client with proper constructor arguments
|
|||
expect(AlertingAuthorization).toHaveBeenCalledWith({
|
||||
request,
|
||||
authorization: securityPluginStart.authz,
|
||||
alertTypeRegistry: alertingAuthorizationClientFactoryParams.alertTypeRegistry,
|
||||
ruleTypeRegistry: alertingAuthorizationClientFactoryParams.ruleTypeRegistry,
|
||||
features: alertingAuthorizationClientFactoryParams.features,
|
||||
auditLogger: expect.any(AlertingAuthorizationAuditLogger),
|
||||
getSpace: expect.any(Function),
|
||||
|
@ -118,7 +118,7 @@ test('creates an alerting authorization client with proper constructor arguments
|
|||
const { AlertingAuthorization } = jest.requireMock('./authorization/alerting_authorization');
|
||||
expect(AlertingAuthorization).toHaveBeenCalledWith({
|
||||
request,
|
||||
alertTypeRegistry: alertingAuthorizationClientFactoryParams.alertTypeRegistry,
|
||||
ruleTypeRegistry: alertingAuthorizationClientFactoryParams.ruleTypeRegistry,
|
||||
features: alertingAuthorizationClientFactoryParams.features,
|
||||
auditLogger: expect.any(AlertingAuthorizationAuditLogger),
|
||||
getSpace: expect.any(Function),
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import { KibanaRequest } from 'src/core/server';
|
||||
import { ALERTS_FEATURE_ID } from '../common';
|
||||
import { AlertTypeRegistry } from './types';
|
||||
import { RuleTypeRegistry } from './types';
|
||||
import { SecurityPluginSetup, SecurityPluginStart } from '../../security/server';
|
||||
import { PluginStartContract as FeaturesPluginStart } from '../../features/server';
|
||||
import { AlertingAuthorization } from './authorization/alerting_authorization';
|
||||
|
@ -15,7 +15,7 @@ import { AlertingAuthorizationAuditLogger } from './authorization/audit_logger';
|
|||
import { Space } from '../../spaces/server';
|
||||
|
||||
export interface AlertingAuthorizationClientFactoryOpts {
|
||||
alertTypeRegistry: AlertTypeRegistry;
|
||||
ruleTypeRegistry: RuleTypeRegistry;
|
||||
securityPluginSetup?: SecurityPluginSetup;
|
||||
securityPluginStart?: SecurityPluginStart;
|
||||
getSpace: (request: KibanaRequest) => Promise<Space | undefined>;
|
||||
|
@ -24,7 +24,7 @@ export interface AlertingAuthorizationClientFactoryOpts {
|
|||
|
||||
export class AlertingAuthorizationClientFactory {
|
||||
private isInitialized = false;
|
||||
private alertTypeRegistry!: AlertTypeRegistry;
|
||||
private ruleTypeRegistry!: RuleTypeRegistry;
|
||||
private securityPluginStart?: SecurityPluginStart;
|
||||
private securityPluginSetup?: SecurityPluginSetup;
|
||||
private features!: FeaturesPluginStart;
|
||||
|
@ -36,7 +36,7 @@ export class AlertingAuthorizationClientFactory {
|
|||
}
|
||||
this.isInitialized = true;
|
||||
this.getSpace = options.getSpace;
|
||||
this.alertTypeRegistry = options.alertTypeRegistry;
|
||||
this.ruleTypeRegistry = options.ruleTypeRegistry;
|
||||
this.securityPluginSetup = options.securityPluginSetup;
|
||||
this.securityPluginStart = options.securityPluginStart;
|
||||
this.features = options.features;
|
||||
|
@ -48,7 +48,7 @@ export class AlertingAuthorizationClientFactory {
|
|||
authorization: securityPluginStart?.authz,
|
||||
request,
|
||||
getSpace: this.getSpace,
|
||||
alertTypeRegistry: this.alertTypeRegistry,
|
||||
ruleTypeRegistry: this.ruleTypeRegistry,
|
||||
features: features!,
|
||||
auditLogger: new AlertingAuthorizationAuditLogger(
|
||||
securityPluginSetup?.audit.getLogger(ALERTS_FEATURE_ID)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import { KibanaRequest } from 'kibana/server';
|
||||
import { alertTypeRegistryMock } from '../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../rule_type_registry.mock';
|
||||
import { securityMock } from '../../../../plugins/security/server/mocks';
|
||||
import {
|
||||
PluginStartContract as FeaturesStartContract,
|
||||
|
@ -23,11 +23,11 @@ import { alertingAuthorizationAuditLoggerMock } from './audit_logger.mock';
|
|||
import { AlertingAuthorizationAuditLogger, AuthorizationResult } from './audit_logger';
|
||||
import uuid from 'uuid';
|
||||
import { RecoveredActionGroup } from '../../common';
|
||||
import { RegistryAlertType } from '../alert_type_registry';
|
||||
import { RegistryRuleType } from '../rule_type_registry';
|
||||
import { esKuery } from '../../../../../src/plugins/data/server';
|
||||
import { AlertingAuthorizationFilterType } from './alerting_authorization_kuery';
|
||||
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
const features: jest.Mocked<FeaturesStartContract> = featuresPluginMock.createStart();
|
||||
const request = {} as KibanaRequest;
|
||||
|
||||
|
@ -197,7 +197,7 @@ beforeEach(() => {
|
|||
auditLogger.logUnscopedAuthorizationFailure.mockImplementation(
|
||||
(username, operation) => `Unauthorized ${username}/${operation}`
|
||||
);
|
||||
alertTypeRegistry.get.mockImplementation((id) => ({
|
||||
ruleTypeRegistry.get.mockImplementation((id) => ({
|
||||
id,
|
||||
name: 'My Alert Type',
|
||||
actionGroups: [{ id: 'default', name: 'Default' }],
|
||||
|
@ -229,7 +229,7 @@ describe('AlertingAuthorization', () => {
|
|||
|
||||
new AlertingAuthorization({
|
||||
request,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
|
@ -244,7 +244,7 @@ describe('AlertingAuthorization', () => {
|
|||
test('is a no-op when there is no authorization api', async () => {
|
||||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
|
@ -258,7 +258,7 @@ describe('AlertingAuthorization', () => {
|
|||
entity: AlertingAuthorizationEntity.Rule,
|
||||
});
|
||||
|
||||
expect(alertTypeRegistry.get).toHaveBeenCalledTimes(0);
|
||||
expect(ruleTypeRegistry.get).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test('is a no-op when the security license is disabled', async () => {
|
||||
|
@ -266,7 +266,7 @@ describe('AlertingAuthorization', () => {
|
|||
authorization.mode.useRbacForRequest.mockReturnValue(false);
|
||||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
authorization,
|
||||
features,
|
||||
auditLogger,
|
||||
|
@ -281,7 +281,7 @@ describe('AlertingAuthorization', () => {
|
|||
entity: AlertingAuthorizationEntity.Rule,
|
||||
});
|
||||
|
||||
expect(alertTypeRegistry.get).toHaveBeenCalledTimes(0);
|
||||
expect(ruleTypeRegistry.get).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test('ensures the user has privileges to execute rules for the specified rule type and operation without consumer when producer and consumer are the same', async () => {
|
||||
|
@ -293,7 +293,7 @@ describe('AlertingAuthorization', () => {
|
|||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
authorization,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
|
@ -313,7 +313,7 @@ describe('AlertingAuthorization', () => {
|
|||
entity: AlertingAuthorizationEntity.Rule,
|
||||
});
|
||||
|
||||
expect(alertTypeRegistry.get).toHaveBeenCalledWith('myType');
|
||||
expect(ruleTypeRegistry.get).toHaveBeenCalledWith('myType');
|
||||
|
||||
expect(authorization.actions.alerting.get).toHaveBeenCalledTimes(2);
|
||||
expect(authorization.actions.alerting.get).toHaveBeenCalledWith(
|
||||
|
@ -349,7 +349,7 @@ describe('AlertingAuthorization', () => {
|
|||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
authorization,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
|
@ -369,7 +369,7 @@ describe('AlertingAuthorization', () => {
|
|||
entity: AlertingAuthorizationEntity.Alert,
|
||||
});
|
||||
|
||||
expect(alertTypeRegistry.get).toHaveBeenCalledWith('myType');
|
||||
expect(ruleTypeRegistry.get).toHaveBeenCalledWith('myType');
|
||||
|
||||
expect(authorization.actions.alerting.get).toHaveBeenCalledTimes(2);
|
||||
expect(authorization.actions.alerting.get).toHaveBeenCalledWith(
|
||||
|
@ -405,7 +405,7 @@ describe('AlertingAuthorization', () => {
|
|||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
authorization,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
|
@ -425,7 +425,7 @@ describe('AlertingAuthorization', () => {
|
|||
entity: AlertingAuthorizationEntity.Rule,
|
||||
});
|
||||
|
||||
expect(alertTypeRegistry.get).toHaveBeenCalledWith('myType');
|
||||
expect(ruleTypeRegistry.get).toHaveBeenCalledWith('myType');
|
||||
|
||||
expect(authorization.actions.alerting.get).toHaveBeenCalledTimes(2);
|
||||
expect(authorization.actions.alerting.get).toHaveBeenCalledWith(
|
||||
|
@ -467,7 +467,7 @@ describe('AlertingAuthorization', () => {
|
|||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
authorization,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
|
@ -487,7 +487,7 @@ describe('AlertingAuthorization', () => {
|
|||
entity: AlertingAuthorizationEntity.Alert,
|
||||
});
|
||||
|
||||
expect(alertTypeRegistry.get).toHaveBeenCalledWith('myType');
|
||||
expect(ruleTypeRegistry.get).toHaveBeenCalledWith('myType');
|
||||
|
||||
expect(authorization.actions.alerting.get).toHaveBeenCalledTimes(2);
|
||||
expect(authorization.actions.alerting.get).toHaveBeenCalledWith(
|
||||
|
@ -535,7 +535,7 @@ describe('AlertingAuthorization', () => {
|
|||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
authorization,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
|
@ -549,7 +549,7 @@ describe('AlertingAuthorization', () => {
|
|||
entity: AlertingAuthorizationEntity.Rule,
|
||||
});
|
||||
|
||||
expect(alertTypeRegistry.get).toHaveBeenCalledWith('myType');
|
||||
expect(ruleTypeRegistry.get).toHaveBeenCalledWith('myType');
|
||||
|
||||
expect(authorization.actions.alerting.get).toHaveBeenCalledTimes(2);
|
||||
expect(authorization.actions.alerting.get).toHaveBeenCalledWith(
|
||||
|
@ -600,7 +600,7 @@ describe('AlertingAuthorization', () => {
|
|||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
authorization,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
|
@ -614,7 +614,7 @@ describe('AlertingAuthorization', () => {
|
|||
entity: AlertingAuthorizationEntity.Alert,
|
||||
});
|
||||
|
||||
expect(alertTypeRegistry.get).toHaveBeenCalledWith('myType');
|
||||
expect(ruleTypeRegistry.get).toHaveBeenCalledWith('myType');
|
||||
|
||||
expect(authorization.actions.alerting.get).toHaveBeenCalledTimes(2);
|
||||
expect(authorization.actions.alerting.get).toHaveBeenCalledWith(
|
||||
|
@ -659,7 +659,7 @@ describe('AlertingAuthorization', () => {
|
|||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
authorization,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
|
@ -717,7 +717,7 @@ describe('AlertingAuthorization', () => {
|
|||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
authorization,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
|
@ -779,7 +779,7 @@ describe('AlertingAuthorization', () => {
|
|||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
authorization,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
|
@ -837,7 +837,7 @@ describe('AlertingAuthorization', () => {
|
|||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
authorization,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
|
@ -888,7 +888,7 @@ describe('AlertingAuthorization', () => {
|
|||
});
|
||||
|
||||
describe('getFindAuthorizationFilter', () => {
|
||||
const myOtherAppAlertType: RegistryAlertType = {
|
||||
const myOtherAppAlertType: RegistryRuleType = {
|
||||
actionGroups: [],
|
||||
actionVariables: undefined,
|
||||
defaultActionGroupId: 'default',
|
||||
|
@ -900,7 +900,7 @@ describe('AlertingAuthorization', () => {
|
|||
producer: 'alerts',
|
||||
enabledInLicense: true,
|
||||
};
|
||||
const myAppAlertType: RegistryAlertType = {
|
||||
const myAppAlertType: RegistryRuleType = {
|
||||
actionGroups: [],
|
||||
actionVariables: undefined,
|
||||
defaultActionGroupId: 'default',
|
||||
|
@ -912,7 +912,7 @@ describe('AlertingAuthorization', () => {
|
|||
producer: 'myApp',
|
||||
enabledInLicense: true,
|
||||
};
|
||||
const mySecondAppAlertType: RegistryAlertType = {
|
||||
const mySecondAppAlertType: RegistryRuleType = {
|
||||
actionGroups: [],
|
||||
actionVariables: undefined,
|
||||
defaultActionGroupId: 'default',
|
||||
|
@ -928,7 +928,7 @@ describe('AlertingAuthorization', () => {
|
|||
test('omits filter when there is no authorization api', async () => {
|
||||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
|
@ -950,7 +950,7 @@ describe('AlertingAuthorization', () => {
|
|||
test('ensureRuleTypeIsAuthorized is no-op when there is no authorization api', async () => {
|
||||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
|
@ -984,13 +984,13 @@ describe('AlertingAuthorization', () => {
|
|||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
authorization,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
exemptConsumerIds,
|
||||
});
|
||||
alertTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
expect(
|
||||
(
|
||||
await alertAuthorization.getFindAuthorizationFilter(AlertingAuthorizationEntity.Rule, {
|
||||
|
@ -1046,13 +1046,13 @@ describe('AlertingAuthorization', () => {
|
|||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
authorization,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
exemptConsumerIds,
|
||||
});
|
||||
alertTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
const { ensureRuleTypeIsAuthorized } = await alertAuthorization.getFindAuthorizationFilter(
|
||||
AlertingAuthorizationEntity.Alert,
|
||||
{
|
||||
|
@ -1119,13 +1119,13 @@ describe('AlertingAuthorization', () => {
|
|||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
authorization,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
exemptConsumerIds,
|
||||
});
|
||||
alertTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
const { ensureRuleTypeIsAuthorized } = await alertAuthorization.getFindAuthorizationFilter(
|
||||
AlertingAuthorizationEntity.Rule,
|
||||
{
|
||||
|
@ -1193,13 +1193,13 @@ describe('AlertingAuthorization', () => {
|
|||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
authorization,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
exemptConsumerIds,
|
||||
});
|
||||
alertTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
const {
|
||||
ensureRuleTypeIsAuthorized,
|
||||
logSuccessfulAuthorization,
|
||||
|
@ -1241,7 +1241,7 @@ describe('AlertingAuthorization', () => {
|
|||
});
|
||||
|
||||
describe('filterByRuleTypeAuthorization', () => {
|
||||
const myOtherAppAlertType: RegistryAlertType = {
|
||||
const myOtherAppAlertType: RegistryRuleType = {
|
||||
actionGroups: [],
|
||||
actionVariables: undefined,
|
||||
defaultActionGroupId: 'default',
|
||||
|
@ -1253,7 +1253,7 @@ describe('AlertingAuthorization', () => {
|
|||
producer: 'myOtherApp',
|
||||
enabledInLicense: true,
|
||||
};
|
||||
const myAppAlertType: RegistryAlertType = {
|
||||
const myAppAlertType: RegistryRuleType = {
|
||||
actionGroups: [],
|
||||
actionVariables: undefined,
|
||||
defaultActionGroupId: 'default',
|
||||
|
@ -1270,13 +1270,13 @@ describe('AlertingAuthorization', () => {
|
|||
test('augments a list of types with all features when there is no authorization api', async () => {
|
||||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
exemptConsumerIds,
|
||||
});
|
||||
alertTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
|
||||
await expect(
|
||||
alertAuthorization.filterByRuleTypeAuthorization(
|
||||
|
@ -1351,13 +1351,13 @@ describe('AlertingAuthorization', () => {
|
|||
test('augments a list of types with all features and exempt consumer ids when there is no authorization api', async () => {
|
||||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
exemptConsumerIds: ['exemptConsumerA', 'exemptConsumerB'],
|
||||
});
|
||||
alertTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
|
||||
await expect(
|
||||
alertAuthorization.filterByRuleTypeAuthorization(
|
||||
|
@ -1484,13 +1484,13 @@ describe('AlertingAuthorization', () => {
|
|||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
authorization,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
exemptConsumerIds,
|
||||
});
|
||||
alertTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
|
||||
await expect(
|
||||
alertAuthorization.filterByRuleTypeAuthorization(
|
||||
|
@ -1589,13 +1589,13 @@ describe('AlertingAuthorization', () => {
|
|||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
authorization,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
exemptConsumerIds: ['exemptConsumerA'],
|
||||
});
|
||||
alertTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
|
||||
await expect(
|
||||
alertAuthorization.filterByRuleTypeAuthorization(
|
||||
|
@ -1685,13 +1685,13 @@ describe('AlertingAuthorization', () => {
|
|||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
authorization,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
exemptConsumerIds: ['exemptConsumerA'],
|
||||
});
|
||||
alertTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
|
||||
await expect(
|
||||
alertAuthorization.filterByRuleTypeAuthorization(
|
||||
|
@ -1790,13 +1790,13 @@ describe('AlertingAuthorization', () => {
|
|||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
authorization,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
exemptConsumerIds,
|
||||
});
|
||||
alertTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
|
||||
await expect(
|
||||
alertAuthorization.filterByRuleTypeAuthorization(
|
||||
|
@ -1899,13 +1899,13 @@ describe('AlertingAuthorization', () => {
|
|||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
authorization,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
exemptConsumerIds,
|
||||
});
|
||||
alertTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
|
||||
await expect(
|
||||
alertAuthorization.filterByRuleTypeAuthorization(
|
||||
|
@ -1946,7 +1946,7 @@ describe('AlertingAuthorization', () => {
|
|||
});
|
||||
|
||||
describe('getAugmentedRuleTypesWithAuthorization', () => {
|
||||
const myOtherAppAlertType: RegistryAlertType = {
|
||||
const myOtherAppAlertType: RegistryRuleType = {
|
||||
actionGroups: [],
|
||||
actionVariables: undefined,
|
||||
defaultActionGroupId: 'default',
|
||||
|
@ -1958,7 +1958,7 @@ describe('AlertingAuthorization', () => {
|
|||
enabledInLicense: true,
|
||||
isExportable: true,
|
||||
};
|
||||
const myAppAlertType: RegistryAlertType = {
|
||||
const myAppAlertType: RegistryRuleType = {
|
||||
actionGroups: [],
|
||||
actionVariables: undefined,
|
||||
defaultActionGroupId: 'default',
|
||||
|
@ -1970,7 +1970,7 @@ describe('AlertingAuthorization', () => {
|
|||
enabledInLicense: true,
|
||||
isExportable: true,
|
||||
};
|
||||
const mySecondAppAlertType: RegistryAlertType = {
|
||||
const mySecondAppAlertType: RegistryRuleType = {
|
||||
actionGroups: [],
|
||||
actionVariables: undefined,
|
||||
defaultActionGroupId: 'default',
|
||||
|
@ -2005,13 +2005,13 @@ describe('AlertingAuthorization', () => {
|
|||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
authorization,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
exemptConsumerIds,
|
||||
});
|
||||
alertTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
|
||||
await expect(
|
||||
alertAuthorization.getAugmentedRuleTypesWithAuthorization(
|
||||
|
@ -2079,13 +2079,13 @@ describe('AlertingAuthorization', () => {
|
|||
const alertAuthorization = new AlertingAuthorization({
|
||||
request,
|
||||
authorization,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
features,
|
||||
auditLogger,
|
||||
getSpace,
|
||||
exemptConsumerIds,
|
||||
});
|
||||
alertTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
|
||||
await expect(
|
||||
alertAuthorization.getAugmentedRuleTypesWithAuthorization(
|
||||
|
|
|
@ -9,9 +9,9 @@ import Boom from '@hapi/boom';
|
|||
import { map, mapValues, fromPairs, has } from 'lodash';
|
||||
import { KibanaRequest } from 'src/core/server';
|
||||
import { JsonObject } from '@kbn/common-utils';
|
||||
import { AlertTypeRegistry } from '../types';
|
||||
import { RuleTypeRegistry } from '../types';
|
||||
import { SecurityPluginSetup } from '../../../security/server';
|
||||
import { RegistryAlertType } from '../alert_type_registry';
|
||||
import { RegistryRuleType } from '../rule_type_registry';
|
||||
import { PluginStartContract as FeaturesPluginStart } from '../../../features/server';
|
||||
import { AlertingAuthorizationAuditLogger, ScopeType } from './audit_logger';
|
||||
import { Space } from '../../../spaces/server';
|
||||
|
@ -58,13 +58,13 @@ interface HasPrivileges {
|
|||
all: boolean;
|
||||
}
|
||||
type AuthorizedConsumers = Record<string, HasPrivileges>;
|
||||
export interface RegistryAlertTypeWithAuth extends RegistryAlertType {
|
||||
export interface RegistryAlertTypeWithAuth extends RegistryRuleType {
|
||||
authorizedConsumers: AuthorizedConsumers;
|
||||
}
|
||||
|
||||
type IsAuthorizedAtProducerLevel = boolean;
|
||||
export interface ConstructorOptions {
|
||||
alertTypeRegistry: AlertTypeRegistry;
|
||||
ruleTypeRegistry: RuleTypeRegistry;
|
||||
request: KibanaRequest;
|
||||
features: FeaturesPluginStart;
|
||||
getSpace: (request: KibanaRequest) => Promise<Space | undefined>;
|
||||
|
@ -74,7 +74,7 @@ export interface ConstructorOptions {
|
|||
}
|
||||
|
||||
export class AlertingAuthorization {
|
||||
private readonly alertTypeRegistry: AlertTypeRegistry;
|
||||
private readonly ruleTypeRegistry: RuleTypeRegistry;
|
||||
private readonly request: KibanaRequest;
|
||||
private readonly authorization?: SecurityPluginSetup['authz'];
|
||||
private readonly auditLogger: AlertingAuthorizationAuditLogger;
|
||||
|
@ -84,7 +84,7 @@ export class AlertingAuthorization {
|
|||
private readonly spaceId: Promise<string | undefined>;
|
||||
|
||||
constructor({
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
request,
|
||||
authorization,
|
||||
features,
|
||||
|
@ -94,7 +94,7 @@ export class AlertingAuthorization {
|
|||
}: ConstructorOptions) {
|
||||
this.request = request;
|
||||
this.authorization = authorization;
|
||||
this.alertTypeRegistry = alertTypeRegistry;
|
||||
this.ruleTypeRegistry = ruleTypeRegistry;
|
||||
this.auditLogger = auditLogger;
|
||||
|
||||
// List of consumer ids that are exempt from privilege check. This should be used sparingly.
|
||||
|
@ -159,7 +159,7 @@ export class AlertingAuthorization {
|
|||
authorizedRuleTypes: Set<RegistryAlertTypeWithAuth>;
|
||||
}> {
|
||||
return this.augmentRuleTypesWithAuthorization(
|
||||
this.alertTypeRegistry.list(),
|
||||
this.ruleTypeRegistry.list(),
|
||||
operations,
|
||||
authorizationEntity,
|
||||
new Set(featureIds)
|
||||
|
@ -171,7 +171,7 @@ export class AlertingAuthorization {
|
|||
|
||||
const isAvailableConsumer = has(await this.allPossibleConsumers, consumer);
|
||||
if (authorization && this.shouldCheckAuthorization()) {
|
||||
const ruleType = this.alertTypeRegistry.get(ruleTypeId);
|
||||
const ruleType = this.ruleTypeRegistry.get(ruleTypeId);
|
||||
const requiredPrivilegesByScope = {
|
||||
consumer: authorization.actions.alerting.get(ruleTypeId, consumer, entity, operation),
|
||||
producer: authorization.actions.alerting.get(
|
||||
|
@ -281,7 +281,7 @@ export class AlertingAuthorization {
|
|||
}> {
|
||||
if (this.authorization && this.shouldCheckAuthorization()) {
|
||||
const { username, authorizedRuleTypes } = await this.augmentRuleTypesWithAuthorization(
|
||||
this.alertTypeRegistry.list(),
|
||||
this.ruleTypeRegistry.list(),
|
||||
[ReadOperations.Find],
|
||||
authorizationEntity
|
||||
);
|
||||
|
@ -352,7 +352,7 @@ export class AlertingAuthorization {
|
|||
}
|
||||
|
||||
public async filterByRuleTypeAuthorization(
|
||||
ruleTypes: Set<RegistryAlertType>,
|
||||
ruleTypes: Set<RegistryRuleType>,
|
||||
operations: Array<ReadOperations | WriteOperations>,
|
||||
authorizationEntity: AlertingAuthorizationEntity
|
||||
): Promise<Set<RegistryAlertTypeWithAuth>> {
|
||||
|
@ -365,7 +365,7 @@ export class AlertingAuthorization {
|
|||
}
|
||||
|
||||
private async augmentRuleTypesWithAuthorization(
|
||||
ruleTypes: Set<RegistryAlertType>,
|
||||
ruleTypes: Set<RegistryRuleType>,
|
||||
operations: Array<ReadOperations | WriteOperations>,
|
||||
authorizationEntity: AlertingAuthorizationEntity,
|
||||
featuresIds?: Set<string>
|
||||
|
@ -457,7 +457,7 @@ export class AlertingAuthorization {
|
|||
}
|
||||
|
||||
private augmentWithAuthorizedConsumers(
|
||||
ruleTypes: Set<RegistryAlertType>,
|
||||
ruleTypes: Set<RegistryRuleType>,
|
||||
authorizedConsumers: AuthorizedConsumers
|
||||
): Set<RegistryAlertTypeWithAuth> {
|
||||
return new Set(
|
||||
|
|
|
@ -18,7 +18,7 @@ import {
|
|||
import { TaskManagerSetupContract, TaskManagerStartContract } from '../../task_manager/server';
|
||||
import { SpacesPluginStart } from '../../spaces/server';
|
||||
import { RulesClient } from './rules_client';
|
||||
import { AlertTypeRegistry } from './alert_type_registry';
|
||||
import { RuleTypeRegistry } from './rule_type_registry';
|
||||
import { TaskRunnerFactory } from './task_runner';
|
||||
import { RulesClientFactory } from './rules_client_factory';
|
||||
import { ILicenseState, LicenseState } from './lib/license_state';
|
||||
|
@ -107,7 +107,7 @@ export interface PluginSetupContract {
|
|||
}
|
||||
|
||||
export interface PluginStartContract {
|
||||
listTypes: AlertTypeRegistry['list'];
|
||||
listTypes: RuleTypeRegistry['list'];
|
||||
getRulesClientWithRequest(request: KibanaRequest): PublicMethodsOf<RulesClient>;
|
||||
getAlertingAuthorizationWithRequest(
|
||||
request: KibanaRequest
|
||||
|
@ -139,7 +139,7 @@ export interface AlertingPluginsStart {
|
|||
export class AlertingPlugin {
|
||||
private readonly config: Promise<AlertsConfig>;
|
||||
private readonly logger: Logger;
|
||||
private alertTypeRegistry?: AlertTypeRegistry;
|
||||
private ruleTypeRegistry?: RuleTypeRegistry;
|
||||
private readonly taskRunnerFactory: TaskRunnerFactory;
|
||||
private licenseState: ILicenseState | null = null;
|
||||
private isESOCanEncrypt?: boolean;
|
||||
|
@ -197,13 +197,13 @@ export class AlertingPlugin {
|
|||
this.eventLogService = plugins.eventLog;
|
||||
plugins.eventLog.registerProviderActions(EVENT_LOG_PROVIDER, Object.values(EVENT_LOG_ACTIONS));
|
||||
|
||||
const alertTypeRegistry = new AlertTypeRegistry({
|
||||
const ruleTypeRegistry = new RuleTypeRegistry({
|
||||
taskManager: plugins.taskManager,
|
||||
taskRunnerFactory: this.taskRunnerFactory,
|
||||
licenseState: this.licenseState,
|
||||
licensing: plugins.licensing,
|
||||
});
|
||||
this.alertTypeRegistry = alertTypeRegistry;
|
||||
this.ruleTypeRegistry = ruleTypeRegistry;
|
||||
|
||||
const usageCollection = plugins.usageCollection;
|
||||
if (usageCollection) {
|
||||
|
@ -224,7 +224,7 @@ export class AlertingPlugin {
|
|||
setupSavedObjects(
|
||||
core.savedObjects,
|
||||
plugins.encryptedSavedObjects,
|
||||
this.alertTypeRegistry,
|
||||
this.ruleTypeRegistry,
|
||||
this.logger
|
||||
);
|
||||
|
||||
|
@ -299,7 +299,7 @@ export class AlertingPlugin {
|
|||
if (!(alertType.minimumLicenseRequired in LICENSE_TYPE)) {
|
||||
throw new Error(`"${alertType.minimumLicenseRequired}" is not a valid license type`);
|
||||
}
|
||||
alertTypeRegistry.register(alertType);
|
||||
ruleTypeRegistry.register(alertType);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -309,7 +309,7 @@ export class AlertingPlugin {
|
|||
isESOCanEncrypt,
|
||||
logger,
|
||||
taskRunnerFactory,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
rulesClientFactory,
|
||||
alertingAuthorizationClientFactory,
|
||||
security,
|
||||
|
@ -329,7 +329,7 @@ export class AlertingPlugin {
|
|||
};
|
||||
|
||||
alertingAuthorizationClientFactory.initialize({
|
||||
alertTypeRegistry: alertTypeRegistry!,
|
||||
ruleTypeRegistry: ruleTypeRegistry!,
|
||||
securityPluginSetup: security,
|
||||
securityPluginStart: plugins.security,
|
||||
async getSpace(request: KibanaRequest) {
|
||||
|
@ -339,7 +339,7 @@ export class AlertingPlugin {
|
|||
});
|
||||
|
||||
rulesClientFactory.initialize({
|
||||
alertTypeRegistry: alertTypeRegistry!,
|
||||
ruleTypeRegistry: ruleTypeRegistry!,
|
||||
logger,
|
||||
taskManager: plugins.taskManager,
|
||||
securityPluginSetup: security,
|
||||
|
@ -378,7 +378,7 @@ export class AlertingPlugin {
|
|||
basePathService: core.http.basePath,
|
||||
eventLogger: this.eventLogger!,
|
||||
internalSavedObjectsRepository: core.savedObjects.createInternalRepository(['alert']),
|
||||
alertTypeRegistry: this.alertTypeRegistry!,
|
||||
ruleTypeRegistry: this.ruleTypeRegistry!,
|
||||
kibanaBaseUrl: this.kibanaBaseUrl,
|
||||
supportsEphemeralTasks: plugins.taskManager.supportsEphemeralTasks(),
|
||||
maxEphemeralActionsPerAlert: this.config.then((config) => config.maxEphemeralActionsPerAlert),
|
||||
|
@ -398,7 +398,7 @@ export class AlertingPlugin {
|
|||
scheduleApiKeyInvalidatorTask(this.telemetryLogger, this.config, plugins.taskManager);
|
||||
|
||||
return {
|
||||
listTypes: alertTypeRegistry!.list.bind(this.alertTypeRegistry!),
|
||||
listTypes: ruleTypeRegistry!.list.bind(this.ruleTypeRegistry!),
|
||||
getAlertingAuthorizationWithRequest,
|
||||
getRulesClientWithRequest,
|
||||
getFrameworkHealth: async () =>
|
||||
|
@ -409,14 +409,14 @@ export class AlertingPlugin {
|
|||
private createRouteHandlerContext = (
|
||||
core: CoreSetup<AlertingPluginsStart, unknown>
|
||||
): IContextProvider<AlertingRequestHandlerContext, 'alerting'> => {
|
||||
const { alertTypeRegistry, rulesClientFactory } = this;
|
||||
const { ruleTypeRegistry, rulesClientFactory } = this;
|
||||
return async function alertsRouteHandlerContext(context, request) {
|
||||
const [{ savedObjects }] = await core.getStartServices();
|
||||
return {
|
||||
getRulesClient: () => {
|
||||
return rulesClientFactory!.create(request, savedObjects);
|
||||
},
|
||||
listTypes: alertTypeRegistry!.list.bind(alertTypeRegistry!),
|
||||
listTypes: ruleTypeRegistry!.list.bind(ruleTypeRegistry!),
|
||||
getFrameworkHealth: async () =>
|
||||
await getHealth(savedObjects.createInternalRepository(['alert'])),
|
||||
areApiKeysEnabled: async () => {
|
||||
|
|
|
@ -6,21 +6,21 @@
|
|||
*/
|
||||
|
||||
import type { PublicMethodsOf } from '@kbn/utility-types';
|
||||
import { AlertTypeRegistry } from './alert_type_registry';
|
||||
import { RuleTypeRegistry } from './rule_type_registry';
|
||||
|
||||
type Schema = PublicMethodsOf<AlertTypeRegistry>;
|
||||
type Schema = PublicMethodsOf<RuleTypeRegistry>;
|
||||
|
||||
const createAlertTypeRegistryMock = () => {
|
||||
const createRuleTypeRegistryMock = () => {
|
||||
const mocked: jest.Mocked<Schema> = {
|
||||
has: jest.fn(),
|
||||
register: jest.fn(),
|
||||
get: jest.fn(),
|
||||
list: jest.fn(),
|
||||
ensureAlertTypeEnabled: jest.fn(),
|
||||
ensureRuleTypeEnabled: jest.fn(),
|
||||
};
|
||||
return mocked;
|
||||
};
|
||||
|
||||
export const alertTypeRegistryMock = {
|
||||
create: createAlertTypeRegistryMock,
|
||||
export const ruleTypeRegistryMock = {
|
||||
create: createRuleTypeRegistryMock,
|
||||
};
|
|
@ -6,21 +6,21 @@
|
|||
*/
|
||||
|
||||
import { TaskRunnerFactory } from './task_runner';
|
||||
import { AlertTypeRegistry, ConstructorOptions } from './alert_type_registry';
|
||||
import { RuleTypeRegistry, ConstructorOptions } from './rule_type_registry';
|
||||
import { ActionGroup, AlertType } from './types';
|
||||
import { taskManagerMock } from '../../task_manager/server/mocks';
|
||||
import { ILicenseState } from './lib/license_state';
|
||||
import { licenseStateMock } from './lib/license_state.mock';
|
||||
import { licensingMock } from '../../licensing/server/mocks';
|
||||
let mockedLicenseState: jest.Mocked<ILicenseState>;
|
||||
let alertTypeRegistryParams: ConstructorOptions;
|
||||
let ruleTypeRegistryParams: ConstructorOptions;
|
||||
|
||||
const taskManager = taskManagerMock.createSetup();
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
mockedLicenseState = licenseStateMock.create();
|
||||
alertTypeRegistryParams = {
|
||||
ruleTypeRegistryParams = {
|
||||
taskManager,
|
||||
taskRunnerFactory: new TaskRunnerFactory(),
|
||||
licenseState: mockedLicenseState,
|
||||
|
@ -29,13 +29,13 @@ beforeEach(() => {
|
|||
});
|
||||
|
||||
describe('has()', () => {
|
||||
test('returns false for unregistered alert types', () => {
|
||||
const registry = new AlertTypeRegistry(alertTypeRegistryParams);
|
||||
test('returns false for unregistered rule types', () => {
|
||||
const registry = new RuleTypeRegistry(ruleTypeRegistryParams);
|
||||
expect(registry.has('foo')).toEqual(false);
|
||||
});
|
||||
|
||||
test('returns true for registered alert types', () => {
|
||||
const registry = new AlertTypeRegistry(alertTypeRegistryParams);
|
||||
test('returns true for registered rule types', () => {
|
||||
const registry = new RuleTypeRegistry(ruleTypeRegistryParams);
|
||||
registry.register({
|
||||
id: 'foo',
|
||||
name: 'Foo',
|
||||
|
@ -72,7 +72,7 @@ describe('register()', () => {
|
|||
executor: jest.fn(),
|
||||
producer: 'alerts',
|
||||
};
|
||||
const registry = new AlertTypeRegistry(alertTypeRegistryParams);
|
||||
const registry = new RuleTypeRegistry(ruleTypeRegistryParams);
|
||||
|
||||
const invalidCharacters = [' ', ':', '*', '*', '/'];
|
||||
for (const char of invalidCharacters) {
|
||||
|
@ -105,14 +105,14 @@ describe('register()', () => {
|
|||
executor: jest.fn(),
|
||||
producer: 'alerts',
|
||||
};
|
||||
const registry = new AlertTypeRegistry(alertTypeRegistryParams);
|
||||
const registry = new RuleTypeRegistry(ruleTypeRegistryParams);
|
||||
|
||||
expect(() => registry.register(alertType)).toThrowError(
|
||||
new Error(`expected value of type [string] but got [number]`)
|
||||
);
|
||||
});
|
||||
|
||||
test('throws if AlertType action groups contains reserved group id', () => {
|
||||
test('throws if RuleType action groups contains reserved group id', () => {
|
||||
const alertType: AlertType<never, never, never, never, never, 'default' | 'NotReserved'> = {
|
||||
id: 'test',
|
||||
name: 'Test',
|
||||
|
@ -136,11 +136,11 @@ describe('register()', () => {
|
|||
executor: jest.fn(),
|
||||
producer: 'alerts',
|
||||
};
|
||||
const registry = new AlertTypeRegistry(alertTypeRegistryParams);
|
||||
const registry = new RuleTypeRegistry(ruleTypeRegistryParams);
|
||||
|
||||
expect(() => registry.register(alertType)).toThrowError(
|
||||
new Error(
|
||||
`Alert type [id="${alertType.id}"] cannot be registered. Action groups [recovered] are reserved by the framework.`
|
||||
`Rule type [id="${alertType.id}"] cannot be registered. Action groups [recovered] are reserved by the framework.`
|
||||
)
|
||||
);
|
||||
});
|
||||
|
@ -165,7 +165,7 @@ describe('register()', () => {
|
|||
minimumLicenseRequired: 'basic',
|
||||
isExportable: true,
|
||||
};
|
||||
const registry = new AlertTypeRegistry(alertTypeRegistryParams);
|
||||
const registry = new RuleTypeRegistry(ruleTypeRegistryParams);
|
||||
registry.register(alertType);
|
||||
expect(registry.get('test').actionGroups).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
|
@ -213,11 +213,11 @@ describe('register()', () => {
|
|||
executor: jest.fn(),
|
||||
producer: 'alerts',
|
||||
};
|
||||
const registry = new AlertTypeRegistry(alertTypeRegistryParams);
|
||||
const registry = new RuleTypeRegistry(ruleTypeRegistryParams);
|
||||
|
||||
expect(() => registry.register(alertType)).toThrowError(
|
||||
new Error(
|
||||
`Alert type [id="${alertType.id}"] cannot be registered. Action group [backToAwesome] cannot be used as both a recovery and an active action group.`
|
||||
`Rule type [id="${alertType.id}"] cannot be registered. Action group [backToAwesome] cannot be used as both a recovery and an active action group.`
|
||||
)
|
||||
);
|
||||
});
|
||||
|
@ -238,7 +238,7 @@ describe('register()', () => {
|
|||
executor: jest.fn(),
|
||||
producer: 'alerts',
|
||||
};
|
||||
const registry = new AlertTypeRegistry(alertTypeRegistryParams);
|
||||
const registry = new RuleTypeRegistry(ruleTypeRegistryParams);
|
||||
registry.register(alertType);
|
||||
expect(taskManager.registerTaskDefinitions).toHaveBeenCalledTimes(1);
|
||||
expect(taskManager.registerTaskDefinitions.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
|
@ -253,7 +253,7 @@ describe('register()', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('shallow clones the given alert type', () => {
|
||||
test('shallow clones the given rule type', () => {
|
||||
const alertType: AlertType<never, never, never, never, never, 'default'> = {
|
||||
id: 'test',
|
||||
name: 'Test',
|
||||
|
@ -269,14 +269,14 @@ describe('register()', () => {
|
|||
executor: jest.fn(),
|
||||
producer: 'alerts',
|
||||
};
|
||||
const registry = new AlertTypeRegistry(alertTypeRegistryParams);
|
||||
const registry = new RuleTypeRegistry(ruleTypeRegistryParams);
|
||||
registry.register(alertType);
|
||||
alertType.name = 'Changed';
|
||||
expect(registry.get('test').name).toEqual('Test');
|
||||
});
|
||||
|
||||
test('should throw an error if type is already registered', () => {
|
||||
const registry = new AlertTypeRegistry(alertTypeRegistryParams);
|
||||
const registry = new RuleTypeRegistry(ruleTypeRegistryParams);
|
||||
registry.register({
|
||||
id: 'test',
|
||||
name: 'Test',
|
||||
|
@ -308,13 +308,13 @@ describe('register()', () => {
|
|||
executor: jest.fn(),
|
||||
producer: 'alerts',
|
||||
})
|
||||
).toThrowErrorMatchingInlineSnapshot(`"Alert type \\"test\\" is already registered."`);
|
||||
).toThrowErrorMatchingInlineSnapshot(`"Rule type \\"test\\" is already registered."`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('get()', () => {
|
||||
test('should return registered type', () => {
|
||||
const registry = new AlertTypeRegistry(alertTypeRegistryParams);
|
||||
const registry = new RuleTypeRegistry(ruleTypeRegistryParams);
|
||||
registry.register({
|
||||
id: 'test',
|
||||
name: 'Test',
|
||||
|
@ -364,22 +364,22 @@ describe('get()', () => {
|
|||
});
|
||||
|
||||
test(`should throw an error if type isn't registered`, () => {
|
||||
const registry = new AlertTypeRegistry(alertTypeRegistryParams);
|
||||
const registry = new RuleTypeRegistry(ruleTypeRegistryParams);
|
||||
expect(() => registry.get('test')).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Alert type \\"test\\" is not registered."`
|
||||
`"Rule type \\"test\\" is not registered."`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('list()', () => {
|
||||
test('should return empty when nothing is registered', () => {
|
||||
const registry = new AlertTypeRegistry(alertTypeRegistryParams);
|
||||
const registry = new RuleTypeRegistry(ruleTypeRegistryParams);
|
||||
const result = registry.list();
|
||||
expect(result).toMatchInlineSnapshot(`Set {}`);
|
||||
});
|
||||
|
||||
test('should return registered types', () => {
|
||||
const registry = new AlertTypeRegistry(alertTypeRegistryParams);
|
||||
const registry = new RuleTypeRegistry(ruleTypeRegistryParams);
|
||||
registry.register({
|
||||
id: 'test',
|
||||
name: 'Test',
|
||||
|
@ -431,7 +431,7 @@ describe('list()', () => {
|
|||
});
|
||||
|
||||
test('should return action variables state and empty context', () => {
|
||||
const registry = new AlertTypeRegistry(alertTypeRegistryParams);
|
||||
const registry = new RuleTypeRegistry(ruleTypeRegistryParams);
|
||||
registry.register(alertTypeWithVariables('x', '', 's'));
|
||||
const alertType = registry.get('x');
|
||||
expect(alertType.actionVariables).toBeTruthy();
|
||||
|
@ -448,7 +448,7 @@ describe('list()', () => {
|
|||
});
|
||||
|
||||
test('should return action variables context and empty state', () => {
|
||||
const registry = new AlertTypeRegistry(alertTypeRegistryParams);
|
||||
const registry = new RuleTypeRegistry(ruleTypeRegistryParams);
|
||||
registry.register(alertTypeWithVariables('x', 'c', ''));
|
||||
const alertType = registry.get('x');
|
||||
expect(alertType.actionVariables).toBeTruthy();
|
||||
|
@ -465,12 +465,12 @@ describe('list()', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('ensureAlertTypeEnabled', () => {
|
||||
let alertTypeRegistry: AlertTypeRegistry;
|
||||
describe('ensureRuleTypeEnabled', () => {
|
||||
let ruleTypeRegistry: RuleTypeRegistry;
|
||||
|
||||
beforeEach(() => {
|
||||
alertTypeRegistry = new AlertTypeRegistry(alertTypeRegistryParams);
|
||||
alertTypeRegistry.register({
|
||||
ruleTypeRegistry = new RuleTypeRegistry(ruleTypeRegistryParams);
|
||||
ruleTypeRegistry.register({
|
||||
id: 'test',
|
||||
name: 'Test',
|
||||
actionGroups: [
|
||||
|
@ -489,7 +489,7 @@ describe('ensureAlertTypeEnabled', () => {
|
|||
});
|
||||
|
||||
test('should call ensureLicenseForAlertType on the license state', async () => {
|
||||
alertTypeRegistry.ensureAlertTypeEnabled('test');
|
||||
ruleTypeRegistry.ensureRuleTypeEnabled('test');
|
||||
expect(mockedLicenseState.ensureLicenseForAlertType).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
@ -497,9 +497,9 @@ describe('ensureAlertTypeEnabled', () => {
|
|||
mockedLicenseState.ensureLicenseForAlertType.mockImplementation(() => {
|
||||
throw new Error('Fail');
|
||||
});
|
||||
expect(() =>
|
||||
alertTypeRegistry.ensureAlertTypeEnabled('test')
|
||||
).toThrowErrorMatchingInlineSnapshot(`"Fail"`);
|
||||
expect(() => ruleTypeRegistry.ensureRuleTypeEnabled('test')).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Fail"`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
@ -36,7 +36,7 @@ export interface ConstructorOptions {
|
|||
licensing: LicensingPluginSetup;
|
||||
}
|
||||
|
||||
export interface RegistryAlertType
|
||||
export interface RegistryRuleType
|
||||
extends Pick<
|
||||
UntypedNormalizedAlertType,
|
||||
| 'name'
|
||||
|
@ -119,9 +119,9 @@ export type UntypedNormalizedAlertType = NormalizedAlertType<
|
|||
string
|
||||
>;
|
||||
|
||||
export class AlertTypeRegistry {
|
||||
export class RuleTypeRegistry {
|
||||
private readonly taskManager: TaskManagerSetupContract;
|
||||
private readonly alertTypes: Map<string, UntypedNormalizedAlertType> = new Map();
|
||||
private readonly ruleTypes: Map<string, UntypedNormalizedAlertType> = new Map();
|
||||
private readonly taskRunnerFactory: TaskRunnerFactory;
|
||||
private readonly licenseState: ILicenseState;
|
||||
private readonly licensing: LicensingPluginSetup;
|
||||
|
@ -134,10 +134,10 @@ export class AlertTypeRegistry {
|
|||
}
|
||||
|
||||
public has(id: string) {
|
||||
return this.alertTypes.has(id);
|
||||
return this.ruleTypes.has(id);
|
||||
}
|
||||
|
||||
public ensureAlertTypeEnabled(id: string) {
|
||||
public ensureRuleTypeEnabled(id: string) {
|
||||
this.licenseState.ensureLicenseForAlertType(this.get(id));
|
||||
}
|
||||
|
||||
|
@ -162,8 +162,8 @@ export class AlertTypeRegistry {
|
|||
) {
|
||||
if (this.has(alertType.id)) {
|
||||
throw new Error(
|
||||
i18n.translate('xpack.alerting.alertTypeRegistry.register.duplicateAlertTypeError', {
|
||||
defaultMessage: 'Alert type "{id}" is already registered.',
|
||||
i18n.translate('xpack.alerting.ruleTypeRegistry.register.duplicateAlertTypeError', {
|
||||
defaultMessage: 'Rule type "{id}" is already registered.',
|
||||
values: {
|
||||
id: alertType.id,
|
||||
},
|
||||
|
@ -182,7 +182,7 @@ export class AlertTypeRegistry {
|
|||
RecoveryActionGroupId
|
||||
>(alertType);
|
||||
|
||||
this.alertTypes.set(
|
||||
this.ruleTypes.set(
|
||||
alertIdSchema.validate(alertType.id),
|
||||
/** stripping the typing is required in order to store the AlertTypes in a Map */
|
||||
(normalizedAlertType as unknown) as UntypedNormalizedAlertType
|
||||
|
@ -232,8 +232,8 @@ export class AlertTypeRegistry {
|
|||
> {
|
||||
if (!this.has(id)) {
|
||||
throw Boom.badRequest(
|
||||
i18n.translate('xpack.alerting.alertTypeRegistry.get.missingAlertTypeError', {
|
||||
defaultMessage: 'Alert type "{id}" is not registered.',
|
||||
i18n.translate('xpack.alerting.ruleTypeRegistry.get.missingAlertTypeError', {
|
||||
defaultMessage: 'Rule type "{id}" is not registered.',
|
||||
values: {
|
||||
id,
|
||||
},
|
||||
|
@ -245,7 +245,7 @@ export class AlertTypeRegistry {
|
|||
* This means that returning a typed AlertType in `get` is an inherently
|
||||
* unsafe operation. Down casting to `unknown` is the only way to achieve this.
|
||||
*/
|
||||
return (this.alertTypes.get(id)! as unknown) as NormalizedAlertType<
|
||||
return (this.ruleTypes.get(id)! as unknown) as NormalizedAlertType<
|
||||
Params,
|
||||
ExtractedParams,
|
||||
State,
|
||||
|
@ -256,9 +256,9 @@ export class AlertTypeRegistry {
|
|||
>;
|
||||
}
|
||||
|
||||
public list(): Set<RegistryAlertType> {
|
||||
public list(): Set<RegistryRuleType> {
|
||||
return new Set(
|
||||
Array.from(this.alertTypes).map(
|
||||
Array.from(this.ruleTypes).map(
|
||||
([
|
||||
id,
|
||||
{
|
||||
|
@ -338,10 +338,10 @@ function augmentActionGroupsWithReserved<
|
|||
if (recoveryActionGroup && activeActionGroups.has(recoveryActionGroup.id)) {
|
||||
throw new Error(
|
||||
i18n.translate(
|
||||
'xpack.alerting.alertTypeRegistry.register.customRecoveryActionGroupUsageError',
|
||||
'xpack.alerting.ruleTypeRegistry.register.customRecoveryActionGroupUsageError',
|
||||
{
|
||||
defaultMessage:
|
||||
'Alert type [id="{id}"] cannot be registered. Action group [{actionGroup}] cannot be used as both a recovery and an active action group.',
|
||||
'Rule type [id="{id}"] cannot be registered. Action group [{actionGroup}] cannot be used as both a recovery and an active action group.',
|
||||
values: {
|
||||
actionGroup: recoveryActionGroup.id,
|
||||
id,
|
||||
|
@ -351,9 +351,9 @@ function augmentActionGroupsWithReserved<
|
|||
);
|
||||
} else if (intersectingReservedActionGroups.length > 0) {
|
||||
throw new Error(
|
||||
i18n.translate('xpack.alerting.alertTypeRegistry.register.reservedActionGroupUsageError', {
|
||||
i18n.translate('xpack.alerting.ruleTypeRegistry.register.reservedActionGroupUsageError', {
|
||||
defaultMessage:
|
||||
'Alert type [id="{id}"] cannot be registered. Action groups [{actionGroups}] are reserved by the framework.',
|
||||
'Rule type [id="{id}"] cannot be registered. Action groups [{actionGroups}] are reserved by the framework.',
|
||||
values: {
|
||||
actionGroups: intersectingReservedActionGroups.join(', '),
|
||||
id,
|
|
@ -24,7 +24,7 @@ import {
|
|||
Alert,
|
||||
PartialAlert,
|
||||
RawAlert,
|
||||
AlertTypeRegistry,
|
||||
RuleTypeRegistry,
|
||||
AlertAction,
|
||||
IntervalSchedule,
|
||||
SanitizedAlert,
|
||||
|
@ -46,7 +46,7 @@ import {
|
|||
import { EncryptedSavedObjectsClient } from '../../../encrypted_saved_objects/server';
|
||||
import { TaskManagerStartContract } from '../../../task_manager/server';
|
||||
import { taskInstanceToAlertTaskInstance } from '../task_runner/alert_task_instance';
|
||||
import { RegistryAlertType, UntypedNormalizedAlertType } from '../alert_type_registry';
|
||||
import { RegistryRuleType, UntypedNormalizedAlertType } from '../rule_type_registry';
|
||||
import {
|
||||
AlertingAuthorization,
|
||||
WriteOperations,
|
||||
|
@ -69,7 +69,7 @@ import { KueryNode, nodeBuilder } from '../../../../../src/plugins/data/common';
|
|||
import { mapSortField } from './lib';
|
||||
import { getAlertExecutionStatusPending } from '../lib/alert_execution_status';
|
||||
|
||||
export interface RegistryAlertTypeWithAuth extends RegistryAlertType {
|
||||
export interface RegistryAlertTypeWithAuth extends RegistryRuleType {
|
||||
authorizedConsumers: string[];
|
||||
}
|
||||
type NormalizedAlertAction = Omit<AlertAction, 'actionTypeId'>;
|
||||
|
@ -86,7 +86,7 @@ export interface ConstructorOptions {
|
|||
unsecuredSavedObjectsClient: SavedObjectsClientContract;
|
||||
authorization: AlertingAuthorization;
|
||||
actionsAuthorization: ActionsAuthorization;
|
||||
alertTypeRegistry: AlertTypeRegistry;
|
||||
ruleTypeRegistry: RuleTypeRegistry;
|
||||
encryptedSavedObjectsClient: EncryptedSavedObjectsClient;
|
||||
spaceId?: string;
|
||||
namespace?: string;
|
||||
|
@ -199,7 +199,7 @@ export class RulesClient {
|
|||
private readonly taskManager: TaskManagerStartContract;
|
||||
private readonly unsecuredSavedObjectsClient: SavedObjectsClientContract;
|
||||
private readonly authorization: AlertingAuthorization;
|
||||
private readonly alertTypeRegistry: AlertTypeRegistry;
|
||||
private readonly ruleTypeRegistry: RuleTypeRegistry;
|
||||
private readonly createAPIKey: (name: string) => Promise<CreateAPIKeyResult>;
|
||||
private readonly getActionsClient: () => Promise<ActionsClient>;
|
||||
private readonly actionsAuthorization: ActionsAuthorization;
|
||||
|
@ -209,7 +209,7 @@ export class RulesClient {
|
|||
private readonly auditLogger?: AuditLogger;
|
||||
|
||||
constructor({
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
authorization,
|
||||
taskManager,
|
||||
|
@ -230,7 +230,7 @@ export class RulesClient {
|
|||
this.spaceId = spaceId;
|
||||
this.namespace = namespace;
|
||||
this.taskManager = taskManager;
|
||||
this.alertTypeRegistry = alertTypeRegistry;
|
||||
this.ruleTypeRegistry = ruleTypeRegistry;
|
||||
this.unsecuredSavedObjectsClient = unsecuredSavedObjectsClient;
|
||||
this.authorization = authorization;
|
||||
this.createAPIKey = createAPIKey;
|
||||
|
@ -266,31 +266,31 @@ export class RulesClient {
|
|||
throw error;
|
||||
}
|
||||
|
||||
this.alertTypeRegistry.ensureAlertTypeEnabled(data.alertTypeId);
|
||||
this.ruleTypeRegistry.ensureRuleTypeEnabled(data.alertTypeId);
|
||||
|
||||
// Throws an error if alert type isn't registered
|
||||
const alertType = this.alertTypeRegistry.get(data.alertTypeId);
|
||||
const ruleType = this.ruleTypeRegistry.get(data.alertTypeId);
|
||||
|
||||
const validatedAlertTypeParams = validateAlertTypeParams(
|
||||
data.params,
|
||||
alertType.validate?.params
|
||||
ruleType.validate?.params
|
||||
);
|
||||
const username = await this.getUserName();
|
||||
|
||||
let createdAPIKey = null;
|
||||
try {
|
||||
createdAPIKey = data.enabled
|
||||
? await this.createAPIKey(this.generateAPIKeyName(alertType.id, data.name))
|
||||
? await this.createAPIKey(this.generateAPIKeyName(ruleType.id, data.name))
|
||||
: null;
|
||||
} catch (error) {
|
||||
throw Boom.badRequest(`Error creating rule: could not create API key - ${error.message}`);
|
||||
}
|
||||
|
||||
await this.validateActions(alertType, data.actions);
|
||||
await this.validateActions(ruleType, data.actions);
|
||||
|
||||
// Extract saved object references for this rule
|
||||
const { references, params: updatedParams, actions } = await this.extractReferences(
|
||||
alertType,
|
||||
ruleType,
|
||||
data.actions,
|
||||
validatedAlertTypeParams
|
||||
);
|
||||
|
@ -731,7 +731,7 @@ export class RulesClient {
|
|||
})
|
||||
);
|
||||
|
||||
this.alertTypeRegistry.ensureAlertTypeEnabled(alertSavedObject.attributes.alertTypeId);
|
||||
this.ruleTypeRegistry.ensureRuleTypeEnabled(alertSavedObject.attributes.alertTypeId);
|
||||
|
||||
const updateResult = await this.updateAlert<Params>({ id, data }, alertSavedObject);
|
||||
|
||||
|
@ -771,18 +771,18 @@ export class RulesClient {
|
|||
{ id, data }: UpdateOptions<Params>,
|
||||
{ attributes, version }: SavedObject<RawAlert>
|
||||
): Promise<PartialAlert<Params>> {
|
||||
const alertType = this.alertTypeRegistry.get(attributes.alertTypeId);
|
||||
const ruleType = this.ruleTypeRegistry.get(attributes.alertTypeId);
|
||||
|
||||
// Validate
|
||||
const validatedAlertTypeParams = validateAlertTypeParams(
|
||||
data.params,
|
||||
alertType.validate?.params
|
||||
ruleType.validate?.params
|
||||
);
|
||||
await this.validateActions(alertType, data.actions);
|
||||
await this.validateActions(ruleType, data.actions);
|
||||
|
||||
// Extract saved object references for this rule
|
||||
const { references, params: updatedParams, actions } = await this.extractReferences(
|
||||
alertType,
|
||||
ruleType,
|
||||
data.actions,
|
||||
validatedAlertTypeParams
|
||||
);
|
||||
|
@ -792,7 +792,7 @@ export class RulesClient {
|
|||
let createdAPIKey = null;
|
||||
try {
|
||||
createdAPIKey = attributes.enabled
|
||||
? await this.createAPIKey(this.generateAPIKeyName(alertType.id, data.name))
|
||||
? await this.createAPIKey(this.generateAPIKeyName(ruleType.id, data.name))
|
||||
: null;
|
||||
} catch (error) {
|
||||
throw Boom.badRequest(`Error updating rule: could not create API key - ${error.message}`);
|
||||
|
@ -835,7 +835,7 @@ export class RulesClient {
|
|||
|
||||
return this.getPartialAlertFromRaw(
|
||||
id,
|
||||
alertType,
|
||||
ruleType,
|
||||
updatedObject.attributes,
|
||||
updatedObject.references
|
||||
);
|
||||
|
@ -938,7 +938,7 @@ export class RulesClient {
|
|||
})
|
||||
);
|
||||
|
||||
this.alertTypeRegistry.ensureAlertTypeEnabled(attributes.alertTypeId);
|
||||
this.ruleTypeRegistry.ensureRuleTypeEnabled(attributes.alertTypeId);
|
||||
|
||||
try {
|
||||
await this.unsecuredSavedObjectsClient.update('alert', id, updateAttributes, { version });
|
||||
|
@ -1024,7 +1024,7 @@ export class RulesClient {
|
|||
})
|
||||
);
|
||||
|
||||
this.alertTypeRegistry.ensureAlertTypeEnabled(attributes.alertTypeId);
|
||||
this.ruleTypeRegistry.ensureRuleTypeEnabled(attributes.alertTypeId);
|
||||
|
||||
if (attributes.enabled === false) {
|
||||
const username = await this.getUserName();
|
||||
|
@ -1138,7 +1138,7 @@ export class RulesClient {
|
|||
})
|
||||
);
|
||||
|
||||
this.alertTypeRegistry.ensureAlertTypeEnabled(attributes.alertTypeId);
|
||||
this.ruleTypeRegistry.ensureRuleTypeEnabled(attributes.alertTypeId);
|
||||
|
||||
if (attributes.enabled === true) {
|
||||
await this.unsecuredSavedObjectsClient.update(
|
||||
|
@ -1215,7 +1215,7 @@ export class RulesClient {
|
|||
})
|
||||
);
|
||||
|
||||
this.alertTypeRegistry.ensureAlertTypeEnabled(attributes.alertTypeId);
|
||||
this.ruleTypeRegistry.ensureRuleTypeEnabled(attributes.alertTypeId);
|
||||
|
||||
const updateAttributes = this.updateMeta({
|
||||
muteAll: true,
|
||||
|
@ -1277,7 +1277,7 @@ export class RulesClient {
|
|||
})
|
||||
);
|
||||
|
||||
this.alertTypeRegistry.ensureAlertTypeEnabled(attributes.alertTypeId);
|
||||
this.ruleTypeRegistry.ensureRuleTypeEnabled(attributes.alertTypeId);
|
||||
|
||||
const updateAttributes = this.updateMeta({
|
||||
muteAll: false,
|
||||
|
@ -1339,7 +1339,7 @@ export class RulesClient {
|
|||
})
|
||||
);
|
||||
|
||||
this.alertTypeRegistry.ensureAlertTypeEnabled(attributes.alertTypeId);
|
||||
this.ruleTypeRegistry.ensureRuleTypeEnabled(attributes.alertTypeId);
|
||||
|
||||
const mutedInstanceIds = attributes.mutedInstanceIds || [];
|
||||
if (!attributes.muteAll && !mutedInstanceIds.includes(alertInstanceId)) {
|
||||
|
@ -1406,7 +1406,7 @@ export class RulesClient {
|
|||
})
|
||||
);
|
||||
|
||||
this.alertTypeRegistry.ensureAlertTypeEnabled(attributes.alertTypeId);
|
||||
this.ruleTypeRegistry.ensureRuleTypeEnabled(attributes.alertTypeId);
|
||||
|
||||
const mutedInstanceIds = attributes.mutedInstanceIds || [];
|
||||
if (!attributes.muteAll && mutedInstanceIds.includes(alertInstanceId)) {
|
||||
|
@ -1425,7 +1425,7 @@ export class RulesClient {
|
|||
|
||||
public async listAlertTypes() {
|
||||
return await this.authorization.filterByRuleTypeAuthorization(
|
||||
this.alertTypeRegistry.list(),
|
||||
this.ruleTypeRegistry.list(),
|
||||
[ReadOperations.Get, WriteOperations.Create],
|
||||
AlertingAuthorizationEntity.Rule
|
||||
);
|
||||
|
@ -1471,7 +1471,7 @@ export class RulesClient {
|
|||
rawAlert: RawAlert,
|
||||
references: SavedObjectReference[] | undefined
|
||||
): Alert {
|
||||
const ruleType = this.alertTypeRegistry.get(ruleTypeId);
|
||||
const ruleType = this.ruleTypeRegistry.get(ruleTypeId);
|
||||
// In order to support the partial update API of Saved Objects we have to support
|
||||
// partial updates of an Alert, but when we receive an actual RawAlert, it is safe
|
||||
// to cast the result to an Alert
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock';
|
||||
import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks';
|
||||
import { actionsAuthorizationMock } from '../../../../actions/server/mocks';
|
||||
|
@ -17,10 +17,10 @@ import { ActionsAuthorization } from '../../../../actions/server';
|
|||
import { getBeforeSetup, setGlobalDate } from './lib';
|
||||
import { AlertExecutionStatusValues } from '../../types';
|
||||
import { RecoveredActionGroup } from '../../../common';
|
||||
import { RegistryAlertType } from '../../alert_type_registry';
|
||||
import { RegistryRuleType } from '../../rule_type_registry';
|
||||
|
||||
const taskManager = taskManagerMock.createStart();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
const unsecuredSavedObjectsClient = savedObjectsClientMock.create();
|
||||
|
||||
const encryptedSavedObjects = encryptedSavedObjectsMock.createClient();
|
||||
|
@ -30,7 +30,7 @@ const actionsAuthorization = actionsAuthorizationMock.create();
|
|||
const kibanaVersion = 'v7.10.0';
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
authorization: (authorization as unknown) as AlertingAuthorization,
|
||||
actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization,
|
||||
|
@ -46,13 +46,13 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry);
|
||||
});
|
||||
|
||||
setGlobalDate();
|
||||
|
||||
describe('aggregate()', () => {
|
||||
const listedTypes = new Set<RegistryAlertType>([
|
||||
const listedTypes = new Set<RegistryRuleType>([
|
||||
{
|
||||
actionGroups: [],
|
||||
actionVariables: undefined,
|
||||
|
@ -102,7 +102,7 @@ describe('aggregate()', () => {
|
|||
page: 1,
|
||||
saved_objects: [],
|
||||
});
|
||||
alertTypeRegistry.list.mockReturnValue(listedTypes);
|
||||
ruleTypeRegistry.list.mockReturnValue(listedTypes);
|
||||
authorization.filterByRuleTypeAuthorization.mockResolvedValue(
|
||||
new Set([
|
||||
{
|
||||
|
|
|
@ -9,7 +9,7 @@ import { schema } from '@kbn/config-schema';
|
|||
import { RulesClient, ConstructorOptions, CreateOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock';
|
||||
import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks';
|
||||
import { actionsAuthorizationMock } from '../../../../actions/server/mocks';
|
||||
|
@ -28,7 +28,7 @@ jest.mock('../../../../../../src/core/server/saved_objects/service/lib/utils', (
|
|||
}));
|
||||
|
||||
const taskManager = taskManagerMock.createStart();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
const unsecuredSavedObjectsClient = savedObjectsClientMock.create();
|
||||
const encryptedSavedObjects = encryptedSavedObjectsMock.createClient();
|
||||
const authorization = alertingAuthorizationMock.create();
|
||||
|
@ -38,7 +38,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba
|
|||
const kibanaVersion = 'v7.10.0';
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
authorization: (authorization as unknown) as AlertingAuthorization,
|
||||
actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization,
|
||||
|
@ -55,7 +55,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
|
@ -823,7 +823,7 @@ describe('create()', () => {
|
|||
bar: true,
|
||||
parameterThatIsSavedObjectId: '9',
|
||||
});
|
||||
alertTypeRegistry.get.mockImplementation(() => ({
|
||||
ruleTypeRegistry.get.mockImplementation(() => ({
|
||||
id: '123',
|
||||
name: 'Test',
|
||||
actionGroups: [{ id: 'default', name: 'Default' }],
|
||||
|
@ -1000,7 +1000,7 @@ describe('create()', () => {
|
|||
bar: true,
|
||||
parameterThatIsSavedObjectId: '8',
|
||||
});
|
||||
alertTypeRegistry.get.mockImplementation(() => ({
|
||||
ruleTypeRegistry.get.mockImplementation(() => ({
|
||||
id: '123',
|
||||
name: 'Test',
|
||||
actionGroups: [{ id: 'default', name: 'Default' }],
|
||||
|
@ -1629,7 +1629,7 @@ describe('create()', () => {
|
|||
|
||||
test('should validate params', async () => {
|
||||
const data = getMockData();
|
||||
alertTypeRegistry.get.mockReturnValue({
|
||||
ruleTypeRegistry.get.mockReturnValue({
|
||||
id: '123',
|
||||
name: 'Test',
|
||||
actionGroups: [
|
||||
|
@ -1784,7 +1784,7 @@ describe('create()', () => {
|
|||
|
||||
test('throws an error if alert type not registerd', async () => {
|
||||
const data = getMockData();
|
||||
alertTypeRegistry.get.mockImplementation(() => {
|
||||
ruleTypeRegistry.get.mockImplementation(() => {
|
||||
throw new Error('Invalid type');
|
||||
});
|
||||
await expect(rulesClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
|
@ -2032,7 +2032,7 @@ describe('create()', () => {
|
|||
|
||||
test('throws error when ensureActionTypeEnabled throws', async () => {
|
||||
const data = getMockData();
|
||||
alertTypeRegistry.ensureAlertTypeEnabled.mockImplementation(() => {
|
||||
ruleTypeRegistry.ensureRuleTypeEnabled.mockImplementation(() => {
|
||||
throw new Error('Fail');
|
||||
});
|
||||
await expect(rulesClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(`"Fail"`);
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock';
|
||||
import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks';
|
||||
import { actionsAuthorizationMock } from '../../../../actions/server/mocks';
|
||||
|
@ -19,7 +19,7 @@ import { auditServiceMock } from '../../../../security/server/audit/index.mock';
|
|||
import { getBeforeSetup } from './lib';
|
||||
|
||||
const taskManager = taskManagerMock.createStart();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
const unsecuredSavedObjectsClient = savedObjectsClientMock.create();
|
||||
const encryptedSavedObjects = encryptedSavedObjectsMock.createClient();
|
||||
const authorization = alertingAuthorizationMock.create();
|
||||
|
@ -29,7 +29,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba
|
|||
const kibanaVersion = 'v7.10.0';
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
authorization: (authorization as unknown) as AlertingAuthorization,
|
||||
actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization,
|
||||
|
@ -46,7 +46,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock';
|
||||
import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks';
|
||||
import { actionsAuthorizationMock } from '../../../../actions/server/mocks';
|
||||
|
@ -20,7 +20,7 @@ import { auditServiceMock } from '../../../../security/server/audit/index.mock';
|
|||
import { getBeforeSetup, setGlobalDate } from './lib';
|
||||
|
||||
const taskManager = taskManagerMock.createStart();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
const unsecuredSavedObjectsClient = savedObjectsClientMock.create();
|
||||
const encryptedSavedObjects = encryptedSavedObjectsMock.createClient();
|
||||
const authorization = alertingAuthorizationMock.create();
|
||||
|
@ -30,7 +30,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba
|
|||
const kibanaVersion = 'v7.10.0';
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
authorization: (authorization as unknown) as AlertingAuthorization,
|
||||
actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization,
|
||||
|
@ -47,7 +47,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock';
|
||||
import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks';
|
||||
import { actionsAuthorizationMock } from '../../../../actions/server/mocks';
|
||||
|
@ -21,7 +21,7 @@ import { InvalidatePendingApiKey } from '../../types';
|
|||
import { getBeforeSetup, setGlobalDate } from './lib';
|
||||
|
||||
const taskManager = taskManagerMock.createStart();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
const unsecuredSavedObjectsClient = savedObjectsClientMock.create();
|
||||
const encryptedSavedObjects = encryptedSavedObjectsMock.createClient();
|
||||
const authorization = alertingAuthorizationMock.create();
|
||||
|
@ -31,7 +31,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba
|
|||
const kibanaVersion = 'v7.10.0';
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
authorization: (authorization as unknown) as AlertingAuthorization,
|
||||
actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization,
|
||||
|
@ -48,7 +48,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock';
|
||||
import { nodeTypes } from '@kbn/es-query';
|
||||
import { esKuery } from '../../../../../../src/plugins/data/server';
|
||||
|
@ -20,10 +20,10 @@ import { httpServerMock } from '../../../../../../src/core/server/mocks';
|
|||
import { auditServiceMock } from '../../../../security/server/audit/index.mock';
|
||||
import { getBeforeSetup, setGlobalDate } from './lib';
|
||||
import { RecoveredActionGroup } from '../../../common';
|
||||
import { RegistryAlertType } from '../../alert_type_registry';
|
||||
import { RegistryRuleType } from '../../rule_type_registry';
|
||||
|
||||
const taskManager = taskManagerMock.createStart();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
const unsecuredSavedObjectsClient = savedObjectsClientMock.create();
|
||||
const encryptedSavedObjects = encryptedSavedObjectsMock.createClient();
|
||||
const authorization = alertingAuthorizationMock.create();
|
||||
|
@ -33,7 +33,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba
|
|||
const kibanaVersion = 'v7.10.0';
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
authorization: (authorization as unknown) as AlertingAuthorization,
|
||||
actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization,
|
||||
|
@ -49,7 +49,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
|
@ -60,7 +60,7 @@ jest.mock('../lib/map_sort_field', () => ({
|
|||
}));
|
||||
|
||||
describe('find()', () => {
|
||||
const listedTypes = new Set<RegistryAlertType>([
|
||||
const listedTypes = new Set<RegistryRuleType>([
|
||||
{
|
||||
actionGroups: [],
|
||||
recoveryActionGroup: RecoveredActionGroup,
|
||||
|
@ -117,7 +117,7 @@ describe('find()', () => {
|
|||
},
|
||||
],
|
||||
});
|
||||
alertTypeRegistry.list.mockReturnValue(listedTypes);
|
||||
ruleTypeRegistry.list.mockReturnValue(listedTypes);
|
||||
authorization.filterByRuleTypeAuthorization.mockResolvedValue(
|
||||
new Set([
|
||||
{
|
||||
|
@ -201,7 +201,7 @@ describe('find()', () => {
|
|||
bar: true,
|
||||
parameterThatIsSavedObjectId: '9',
|
||||
});
|
||||
alertTypeRegistry.list.mockReturnValue(
|
||||
ruleTypeRegistry.list.mockReturnValue(
|
||||
new Set([
|
||||
...listedTypes,
|
||||
{
|
||||
|
@ -218,7 +218,7 @@ describe('find()', () => {
|
|||
},
|
||||
])
|
||||
);
|
||||
alertTypeRegistry.get.mockImplementationOnce(() => ({
|
||||
ruleTypeRegistry.get.mockImplementationOnce(() => ({
|
||||
id: 'myType',
|
||||
name: 'myType',
|
||||
actionGroups: [{ id: 'default', name: 'Default' }],
|
||||
|
@ -229,7 +229,7 @@ describe('find()', () => {
|
|||
async executor() {},
|
||||
producer: 'myApp',
|
||||
}));
|
||||
alertTypeRegistry.get.mockImplementationOnce(() => ({
|
||||
ruleTypeRegistry.get.mockImplementationOnce(() => ({
|
||||
id: '123',
|
||||
name: 'Test',
|
||||
actionGroups: [{ id: 'default', name: 'Default' }],
|
||||
|
@ -396,7 +396,7 @@ describe('find()', () => {
|
|||
const injectReferencesFn = jest.fn().mockImplementation(() => {
|
||||
throw new Error('something went wrong!');
|
||||
});
|
||||
alertTypeRegistry.list.mockReturnValue(
|
||||
ruleTypeRegistry.list.mockReturnValue(
|
||||
new Set([
|
||||
...listedTypes,
|
||||
{
|
||||
|
@ -413,7 +413,7 @@ describe('find()', () => {
|
|||
},
|
||||
])
|
||||
);
|
||||
alertTypeRegistry.get.mockImplementationOnce(() => ({
|
||||
ruleTypeRegistry.get.mockImplementationOnce(() => ({
|
||||
id: 'myType',
|
||||
name: 'myType',
|
||||
actionGroups: [{ id: 'default', name: 'Default' }],
|
||||
|
@ -424,7 +424,7 @@ describe('find()', () => {
|
|||
async executor() {},
|
||||
producer: 'myApp',
|
||||
}));
|
||||
alertTypeRegistry.get.mockImplementationOnce(() => ({
|
||||
ruleTypeRegistry.get.mockImplementationOnce(() => ({
|
||||
id: '123',
|
||||
name: 'Test',
|
||||
actionGroups: [{ id: 'default', name: 'Default' }],
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock';
|
||||
import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks';
|
||||
import { actionsAuthorizationMock } from '../../../../actions/server/mocks';
|
||||
|
@ -20,7 +20,7 @@ import { getBeforeSetup, setGlobalDate } from './lib';
|
|||
import { RecoveredActionGroup } from '../../../common';
|
||||
|
||||
const taskManager = taskManagerMock.createStart();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
const unsecuredSavedObjectsClient = savedObjectsClientMock.create();
|
||||
const encryptedSavedObjects = encryptedSavedObjectsMock.createClient();
|
||||
const authorization = alertingAuthorizationMock.create();
|
||||
|
@ -30,7 +30,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba
|
|||
const kibanaVersion = 'v7.10.0';
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
authorization: (authorization as unknown) as AlertingAuthorization,
|
||||
actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization,
|
||||
|
@ -46,7 +46,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
|
@ -124,7 +124,7 @@ describe('get()', () => {
|
|||
bar: true,
|
||||
parameterThatIsSavedObjectId: '9',
|
||||
});
|
||||
alertTypeRegistry.get.mockImplementation(() => ({
|
||||
ruleTypeRegistry.get.mockImplementation(() => ({
|
||||
id: '123',
|
||||
name: 'Test',
|
||||
actionGroups: [{ id: 'default', name: 'Default' }],
|
||||
|
@ -244,7 +244,7 @@ describe('get()', () => {
|
|||
const injectReferencesFn = jest.fn().mockImplementation(() => {
|
||||
throw new Error('something went wrong!');
|
||||
});
|
||||
alertTypeRegistry.get.mockImplementation(() => ({
|
||||
ruleTypeRegistry.get.mockImplementation(() => ({
|
||||
id: '123',
|
||||
name: 'Test',
|
||||
actionGroups: [{ id: 'default', name: 'Default' }],
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock';
|
||||
import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks';
|
||||
import { actionsAuthorizationMock } from '../../../../actions/server/mocks';
|
||||
|
@ -22,7 +22,7 @@ import { RawAlert } from '../../types';
|
|||
import { getBeforeSetup, mockedDateString, setGlobalDate } from './lib';
|
||||
|
||||
const taskManager = taskManagerMock.createStart();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
const unsecuredSavedObjectsClient = savedObjectsClientMock.create();
|
||||
const eventLogClient = eventLogClientMock.create();
|
||||
|
||||
|
@ -33,7 +33,7 @@ const actionsAuthorization = actionsAuthorizationMock.create();
|
|||
const kibanaVersion = 'v7.10.0';
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
authorization: (authorization as unknown) as AlertingAuthorization,
|
||||
actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization,
|
||||
|
@ -49,7 +49,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry, eventLogClient);
|
||||
getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry, eventLogClient);
|
||||
});
|
||||
|
||||
setGlobalDate();
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock';
|
||||
import { TaskStatus } from '../../../../task_manager/server';
|
||||
import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks';
|
||||
|
@ -18,7 +18,7 @@ import { ActionsAuthorization } from '../../../../actions/server';
|
|||
import { getBeforeSetup } from './lib';
|
||||
|
||||
const taskManager = taskManagerMock.createStart();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
const unsecuredSavedObjectsClient = savedObjectsClientMock.create();
|
||||
|
||||
const encryptedSavedObjects = encryptedSavedObjectsMock.createClient();
|
||||
|
@ -28,7 +28,7 @@ const actionsAuthorization = actionsAuthorizationMock.create();
|
|||
const kibanaVersion = 'v7.10.0';
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
authorization: (authorization as unknown) as AlertingAuthorization,
|
||||
actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization,
|
||||
|
@ -44,7 +44,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry);
|
||||
});
|
||||
|
||||
describe('getAlertState()', () => {
|
||||
|
|
|
@ -10,7 +10,7 @@ import { IEventLogClient } from '../../../../event_log/server';
|
|||
import { actionsClientMock } from '../../../../actions/server/mocks';
|
||||
import { ConstructorOptions } from '../rules_client';
|
||||
import { eventLogClientMock } from '../../../../event_log/server/mocks';
|
||||
import { AlertTypeRegistry } from '../../alert_type_registry';
|
||||
import { RuleTypeRegistry } from '../../rule_type_registry';
|
||||
import { RecoveredActionGroup } from '../../../common';
|
||||
|
||||
export const mockedDateString = '2019-02-12T21:01:22.479Z';
|
||||
|
@ -44,7 +44,7 @@ export function setGlobalDate() {
|
|||
export function getBeforeSetup(
|
||||
rulesClientParams: jest.Mocked<ConstructorOptions>,
|
||||
taskManager: ReturnType<typeof taskManagerMock.createStart>,
|
||||
alertTypeRegistry: jest.Mocked<Pick<AlertTypeRegistry, 'get' | 'has' | 'register' | 'list'>>,
|
||||
ruleTypeRegistry: jest.Mocked<Pick<RuleTypeRegistry, 'get' | 'has' | 'register' | 'list'>>,
|
||||
eventLogClient?: jest.Mocked<IEventLogClient>
|
||||
) {
|
||||
jest.resetAllMocks();
|
||||
|
@ -81,7 +81,7 @@ export function getBeforeSetup(
|
|||
]);
|
||||
rulesClientParams.getActionsClient.mockResolvedValue(actionsClient);
|
||||
|
||||
alertTypeRegistry.get.mockImplementation(() => ({
|
||||
ruleTypeRegistry.get.mockImplementation(() => ({
|
||||
id: '123',
|
||||
name: 'Test',
|
||||
actionGroups: [{ id: 'default', name: 'Default' }],
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock';
|
||||
import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks';
|
||||
import { actionsAuthorizationMock } from '../../../../actions/server/mocks';
|
||||
|
@ -19,10 +19,10 @@ import {
|
|||
import { ActionsAuthorization } from '../../../../actions/server';
|
||||
import { getBeforeSetup } from './lib';
|
||||
import { RecoveredActionGroup } from '../../../common';
|
||||
import { RegistryAlertType } from '../../alert_type_registry';
|
||||
import { RegistryRuleType } from '../../rule_type_registry';
|
||||
|
||||
const taskManager = taskManagerMock.createStart();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
const unsecuredSavedObjectsClient = savedObjectsClientMock.create();
|
||||
|
||||
const encryptedSavedObjects = encryptedSavedObjectsMock.createClient();
|
||||
|
@ -32,7 +32,7 @@ const actionsAuthorization = actionsAuthorizationMock.create();
|
|||
const kibanaVersion = 'v7.10.0';
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
authorization: (authorization as unknown) as AlertingAuthorization,
|
||||
actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization,
|
||||
|
@ -48,12 +48,12 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry);
|
||||
});
|
||||
|
||||
describe('listAlertTypes', () => {
|
||||
let rulesClient: RulesClient;
|
||||
const alertingAlertType: RegistryAlertType = {
|
||||
const alertingAlertType: RegistryRuleType = {
|
||||
actionGroups: [],
|
||||
actionVariables: undefined,
|
||||
defaultActionGroupId: 'default',
|
||||
|
@ -65,7 +65,7 @@ describe('listAlertTypes', () => {
|
|||
producer: 'alerts',
|
||||
enabledInLicense: true,
|
||||
};
|
||||
const myAppAlertType: RegistryAlertType = {
|
||||
const myAppAlertType: RegistryRuleType = {
|
||||
actionGroups: [],
|
||||
actionVariables: undefined,
|
||||
defaultActionGroupId: 'default',
|
||||
|
@ -90,7 +90,7 @@ describe('listAlertTypes', () => {
|
|||
});
|
||||
|
||||
test('should return a list of AlertTypes that exist in the registry', async () => {
|
||||
alertTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
ruleTypeRegistry.list.mockReturnValue(setOfAlertTypes);
|
||||
authorization.filterByRuleTypeAuthorization.mockResolvedValue(
|
||||
new Set<RegistryAlertTypeWithAuth>([
|
||||
{ ...myAppAlertType, authorizedConsumers },
|
||||
|
@ -106,7 +106,7 @@ describe('listAlertTypes', () => {
|
|||
});
|
||||
|
||||
describe('authorization', () => {
|
||||
const listedTypes = new Set<RegistryAlertType>([
|
||||
const listedTypes = new Set<RegistryRuleType>([
|
||||
{
|
||||
actionGroups: [],
|
||||
actionVariables: undefined,
|
||||
|
@ -132,7 +132,7 @@ describe('listAlertTypes', () => {
|
|||
},
|
||||
]);
|
||||
beforeEach(() => {
|
||||
alertTypeRegistry.list.mockReturnValue(listedTypes);
|
||||
ruleTypeRegistry.list.mockReturnValue(listedTypes);
|
||||
});
|
||||
|
||||
test('should return a list of AlertTypes that exist in the registry only if the user is authorised to get them', async () => {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock';
|
||||
import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks';
|
||||
import { actionsAuthorizationMock } from '../../../../actions/server/mocks';
|
||||
|
@ -19,7 +19,7 @@ import { auditServiceMock } from '../../../../security/server/audit/index.mock';
|
|||
import { getBeforeSetup, setGlobalDate } from './lib';
|
||||
|
||||
const taskManager = taskManagerMock.createStart();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
const unsecuredSavedObjectsClient = savedObjectsClientMock.create();
|
||||
const encryptedSavedObjects = encryptedSavedObjectsMock.createClient();
|
||||
const authorization = alertingAuthorizationMock.create();
|
||||
|
@ -29,7 +29,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba
|
|||
const kibanaVersion = 'v7.10.0';
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
authorization: (authorization as unknown) as AlertingAuthorization,
|
||||
actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization,
|
||||
|
@ -45,7 +45,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock';
|
||||
import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks';
|
||||
import { actionsAuthorizationMock } from '../../../../actions/server/mocks';
|
||||
|
@ -19,7 +19,7 @@ import { auditServiceMock } from '../../../../security/server/audit/index.mock';
|
|||
import { getBeforeSetup, setGlobalDate } from './lib';
|
||||
|
||||
const taskManager = taskManagerMock.createStart();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
const unsecuredSavedObjectsClient = savedObjectsClientMock.create();
|
||||
const encryptedSavedObjects = encryptedSavedObjectsMock.createClient();
|
||||
const authorization = alertingAuthorizationMock.create();
|
||||
|
@ -29,7 +29,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba
|
|||
const kibanaVersion = 'v7.10.0';
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
authorization: (authorization as unknown) as AlertingAuthorization,
|
||||
actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization,
|
||||
|
@ -45,7 +45,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock';
|
||||
import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks';
|
||||
import { actionsAuthorizationMock } from '../../../../actions/server/mocks';
|
||||
|
@ -19,7 +19,7 @@ import { auditServiceMock } from '../../../../security/server/audit/index.mock';
|
|||
import { getBeforeSetup, setGlobalDate } from './lib';
|
||||
|
||||
const taskManager = taskManagerMock.createStart();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
const unsecuredSavedObjectsClient = savedObjectsClientMock.create();
|
||||
const encryptedSavedObjects = encryptedSavedObjectsMock.createClient();
|
||||
const authorization = alertingAuthorizationMock.create();
|
||||
|
@ -29,7 +29,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba
|
|||
const kibanaVersion = 'v7.10.0';
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
authorization: (authorization as unknown) as AlertingAuthorization,
|
||||
actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization,
|
||||
|
@ -45,7 +45,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock';
|
||||
import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks';
|
||||
import { actionsAuthorizationMock } from '../../../../actions/server/mocks';
|
||||
|
@ -19,7 +19,7 @@ import { auditServiceMock } from '../../../../security/server/audit/index.mock';
|
|||
import { getBeforeSetup, setGlobalDate } from './lib';
|
||||
|
||||
const taskManager = taskManagerMock.createStart();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
const unsecuredSavedObjectsClient = savedObjectsClientMock.create();
|
||||
const encryptedSavedObjects = encryptedSavedObjectsMock.createClient();
|
||||
const authorization = alertingAuthorizationMock.create();
|
||||
|
@ -29,7 +29,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba
|
|||
const kibanaVersion = 'v7.10.0';
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
authorization: (authorization as unknown) as AlertingAuthorization,
|
||||
actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization,
|
||||
|
@ -45,7 +45,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import { schema } from '@kbn/config-schema';
|
|||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock';
|
||||
import { IntervalSchedule, InvalidatePendingApiKey } from '../../types';
|
||||
import { RecoveredActionGroup } from '../../../common';
|
||||
|
@ -31,7 +31,7 @@ jest.mock('../../../../../../src/core/server/saved_objects/service/lib/utils', (
|
|||
}));
|
||||
|
||||
const taskManager = taskManagerMock.createStart();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
const unsecuredSavedObjectsClient = savedObjectsClientMock.create();
|
||||
const encryptedSavedObjects = encryptedSavedObjectsMock.createClient();
|
||||
const authorization = alertingAuthorizationMock.create();
|
||||
|
@ -41,7 +41,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba
|
|||
const kibanaVersion = 'v7.10.0';
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
authorization: (authorization as unknown) as AlertingAuthorization,
|
||||
actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization,
|
||||
|
@ -58,7 +58,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
|
@ -127,7 +127,7 @@ describe('update()', () => {
|
|||
rulesClientParams.getActionsClient.mockResolvedValue(actionsClient);
|
||||
unsecuredSavedObjectsClient.get.mockResolvedValue(existingAlert);
|
||||
encryptedSavedObjects.getDecryptedAsInternalUser.mockResolvedValue(existingDecryptedAlert);
|
||||
alertTypeRegistry.get.mockReturnValue({
|
||||
ruleTypeRegistry.get.mockReturnValue({
|
||||
id: 'myType',
|
||||
name: 'Test',
|
||||
actionGroups: [{ id: 'default', name: 'Default' }],
|
||||
|
@ -429,7 +429,7 @@ describe('update()', () => {
|
|||
bar: true,
|
||||
parameterThatIsSavedObjectId: '9',
|
||||
});
|
||||
alertTypeRegistry.get.mockImplementation(() => ({
|
||||
ruleTypeRegistry.get.mockImplementation(() => ({
|
||||
id: 'myType',
|
||||
name: 'Test',
|
||||
actionGroups: [{ id: 'default', name: 'Default' }],
|
||||
|
@ -940,7 +940,7 @@ describe('update()', () => {
|
|||
});
|
||||
|
||||
it('should validate params', async () => {
|
||||
alertTypeRegistry.get.mockReturnValueOnce({
|
||||
ruleTypeRegistry.get.mockReturnValueOnce({
|
||||
id: '123',
|
||||
name: 'Test',
|
||||
actionGroups: [{ id: 'default', name: 'Default' }],
|
||||
|
@ -1264,7 +1264,7 @@ describe('update()', () => {
|
|||
updatedSchedule: IntervalSchedule
|
||||
) {
|
||||
// mock return values from deps
|
||||
alertTypeRegistry.get.mockReturnValueOnce({
|
||||
ruleTypeRegistry.get.mockReturnValueOnce({
|
||||
id: '123',
|
||||
name: 'Test',
|
||||
actionGroups: [{ id: 'default', name: 'Default' }],
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { RulesClient, ConstructorOptions } from '../rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock';
|
||||
import { encryptedSavedObjectsMock } from '../../../../encrypted_saved_objects/server/mocks';
|
||||
import { actionsAuthorizationMock } from '../../../../actions/server/mocks';
|
||||
|
@ -20,7 +20,7 @@ import { InvalidatePendingApiKey } from '../../types';
|
|||
import { getBeforeSetup, setGlobalDate } from './lib';
|
||||
|
||||
const taskManager = taskManagerMock.createStart();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
const unsecuredSavedObjectsClient = savedObjectsClientMock.create();
|
||||
const encryptedSavedObjects = encryptedSavedObjectsMock.createClient();
|
||||
const authorization = alertingAuthorizationMock.create();
|
||||
|
@ -30,7 +30,7 @@ const auditLogger = auditServiceMock.create().asScoped(httpServerMock.createKiba
|
|||
const kibanaVersion = 'v7.10.0';
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
authorization: (authorization as unknown) as AlertingAuthorization,
|
||||
actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization,
|
||||
|
@ -47,7 +47,7 @@ const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
getBeforeSetup(rulesClientParams, taskManager, alertTypeRegistry);
|
||||
getBeforeSetup(rulesClientParams, taskManager, ruleTypeRegistry);
|
||||
(auditLogger.log as jest.Mock).mockClear();
|
||||
});
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import { cloneDeep } from 'lodash';
|
|||
import { RulesClient, ConstructorOptions } from './rules_client';
|
||||
import { savedObjectsClientMock, loggingSystemMock } from '../../../../src/core/server/mocks';
|
||||
import { taskManagerMock } from '../../task_manager/server/mocks';
|
||||
import { alertTypeRegistryMock } from './alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from './rule_type_registry.mock';
|
||||
import { alertingAuthorizationMock } from './authorization/alerting_authorization.mock';
|
||||
import { encryptedSavedObjectsMock } from '../../encrypted_saved_objects/server/mocks';
|
||||
import { actionsClientMock, actionsAuthorizationMock } from '../../actions/server/mocks';
|
||||
|
@ -28,7 +28,7 @@ const MockAlertId = 'alert-id';
|
|||
const ConflictAfterRetries = RetryForConflictsAttempts + 1;
|
||||
|
||||
const taskManager = taskManagerMock.createStart();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
const unsecuredSavedObjectsClient = savedObjectsClientMock.create();
|
||||
|
||||
const encryptedSavedObjects = encryptedSavedObjectsMock.createClient();
|
||||
|
@ -39,7 +39,7 @@ const kibanaVersion = 'v7.10.0';
|
|||
const logger = loggingSystemMock.create().get();
|
||||
const rulesClientParams: jest.Mocked<ConstructorOptions> = {
|
||||
taskManager,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
unsecuredSavedObjectsClient,
|
||||
authorization: (authorization as unknown) as AlertingAuthorization,
|
||||
actionsAuthorization: (actionsAuthorization as unknown) as ActionsAuthorization,
|
||||
|
@ -327,7 +327,7 @@ beforeEach(() => {
|
|||
actionsClient.getBulk.mockResolvedValue([]);
|
||||
rulesClientParams.getActionsClient.mockResolvedValue(actionsClient);
|
||||
|
||||
alertTypeRegistry.get.mockImplementation((id) => ({
|
||||
ruleTypeRegistry.get.mockImplementation((id) => ({
|
||||
id: '123',
|
||||
name: 'Test',
|
||||
actionGroups: [{ id: 'default', name: 'Default' }],
|
||||
|
@ -339,7 +339,7 @@ beforeEach(() => {
|
|||
producer: 'alerts',
|
||||
}));
|
||||
|
||||
alertTypeRegistry.get.mockReturnValue({
|
||||
ruleTypeRegistry.get.mockReturnValue({
|
||||
id: 'myType',
|
||||
name: 'Test',
|
||||
actionGroups: [{ id: 'default', name: 'Default' }],
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import { Request } from '@hapi/hapi';
|
||||
import { RulesClientFactory, RulesClientFactoryOpts } from './rules_client_factory';
|
||||
import { alertTypeRegistryMock } from './alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from './rule_type_registry.mock';
|
||||
import { taskManagerMock } from '../../task_manager/server/mocks';
|
||||
import { KibanaRequest } from '../../../../src/core/server';
|
||||
import {
|
||||
|
@ -44,7 +44,7 @@ const alertingAuthorizationClientFactory = alertingAuthorizationClientFactoryMoc
|
|||
const rulesClientFactoryParams: jest.Mocked<RulesClientFactoryOpts> = {
|
||||
logger: loggingSystemMock.create().get(),
|
||||
taskManager: taskManagerMock.createStart(),
|
||||
alertTypeRegistry: alertTypeRegistryMock.create(),
|
||||
ruleTypeRegistry: ruleTypeRegistryMock.create(),
|
||||
getSpaceId: jest.fn(),
|
||||
spaceIdToNamespace: jest.fn(),
|
||||
encryptedSavedObjectsClient: encryptedSavedObjectsMock.createClient(),
|
||||
|
@ -119,7 +119,7 @@ test('creates an alerts client with proper constructor arguments when security i
|
|||
actionsAuthorization,
|
||||
logger: rulesClientFactoryParams.logger,
|
||||
taskManager: rulesClientFactoryParams.taskManager,
|
||||
alertTypeRegistry: rulesClientFactoryParams.alertTypeRegistry,
|
||||
ruleTypeRegistry: rulesClientFactoryParams.ruleTypeRegistry,
|
||||
spaceId: 'default',
|
||||
namespace: 'default',
|
||||
getUserName: expect.any(Function),
|
||||
|
@ -158,7 +158,7 @@ test('creates an alerts client with proper constructor arguments', async () => {
|
|||
actionsAuthorization,
|
||||
logger: rulesClientFactoryParams.logger,
|
||||
taskManager: rulesClientFactoryParams.taskManager,
|
||||
alertTypeRegistry: rulesClientFactoryParams.alertTypeRegistry,
|
||||
ruleTypeRegistry: rulesClientFactoryParams.ruleTypeRegistry,
|
||||
spaceId: 'default',
|
||||
namespace: 'default',
|
||||
getUserName: expect.any(Function),
|
||||
|
|
|
@ -13,7 +13,7 @@ import {
|
|||
} from 'src/core/server';
|
||||
import { PluginStartContract as ActionsPluginStartContract } from '../../actions/server';
|
||||
import { RulesClient } from './rules_client';
|
||||
import { AlertTypeRegistry, SpaceIdToNamespaceFunction } from './types';
|
||||
import { RuleTypeRegistry, SpaceIdToNamespaceFunction } from './types';
|
||||
import { SecurityPluginSetup, SecurityPluginStart } from '../../security/server';
|
||||
import { EncryptedSavedObjectsClient } from '../../encrypted_saved_objects/server';
|
||||
import { TaskManagerStartContract } from '../../task_manager/server';
|
||||
|
@ -23,7 +23,7 @@ import { ALERTS_FEATURE_ID } from '../common';
|
|||
export interface RulesClientFactoryOpts {
|
||||
logger: Logger;
|
||||
taskManager: TaskManagerStartContract;
|
||||
alertTypeRegistry: AlertTypeRegistry;
|
||||
ruleTypeRegistry: RuleTypeRegistry;
|
||||
securityPluginSetup?: SecurityPluginSetup;
|
||||
securityPluginStart?: SecurityPluginStart;
|
||||
getSpaceId: (request: KibanaRequest) => string | undefined;
|
||||
|
@ -39,7 +39,7 @@ export class RulesClientFactory {
|
|||
private isInitialized = false;
|
||||
private logger!: Logger;
|
||||
private taskManager!: TaskManagerStartContract;
|
||||
private alertTypeRegistry!: AlertTypeRegistry;
|
||||
private ruleTypeRegistry!: RuleTypeRegistry;
|
||||
private securityPluginSetup?: SecurityPluginSetup;
|
||||
private securityPluginStart?: SecurityPluginStart;
|
||||
private getSpaceId!: (request: KibanaRequest) => string | undefined;
|
||||
|
@ -58,7 +58,7 @@ export class RulesClientFactory {
|
|||
this.logger = options.logger;
|
||||
this.getSpaceId = options.getSpaceId;
|
||||
this.taskManager = options.taskManager;
|
||||
this.alertTypeRegistry = options.alertTypeRegistry;
|
||||
this.ruleTypeRegistry = options.ruleTypeRegistry;
|
||||
this.securityPluginSetup = options.securityPluginSetup;
|
||||
this.securityPluginStart = options.securityPluginStart;
|
||||
this.spaceIdToNamespace = options.spaceIdToNamespace;
|
||||
|
@ -82,7 +82,7 @@ export class RulesClientFactory {
|
|||
kibanaVersion: this.kibanaVersion,
|
||||
logger: this.logger,
|
||||
taskManager: this.taskManager,
|
||||
alertTypeRegistry: this.alertTypeRegistry,
|
||||
ruleTypeRegistry: this.ruleTypeRegistry,
|
||||
unsecuredSavedObjectsClient: savedObjects.getScopedClient(request, {
|
||||
excludedWrappers: ['security'],
|
||||
includedHiddenTypes: ['alert', 'api_key_pending_invalidation'],
|
||||
|
|
|
@ -19,7 +19,7 @@ import { transformRulesForExport } from './transform_rule_for_export';
|
|||
import { RawAlert } from '../types';
|
||||
import { getImportWarnings } from './get_import_warnings';
|
||||
import { isRuleExportable } from './is_rule_exportable';
|
||||
import { AlertTypeRegistry } from '../alert_type_registry';
|
||||
import { RuleTypeRegistry } from '../rule_type_registry';
|
||||
|
||||
export { partiallyUpdateAlert } from './partially_update_alert';
|
||||
|
||||
|
@ -47,7 +47,7 @@ export type AlertAttributesExcludedFromAADType =
|
|||
export function setupSavedObjects(
|
||||
savedObjects: SavedObjectsServiceSetup,
|
||||
encryptedSavedObjects: EncryptedSavedObjectsPluginSetup,
|
||||
ruleTypeRegistry: AlertTypeRegistry,
|
||||
ruleTypeRegistry: RuleTypeRegistry,
|
||||
logger: Logger
|
||||
) {
|
||||
savedObjects.registerType({
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import { MockedLogger, loggerMock } from '@kbn/logging/target/mocks';
|
||||
import { TaskRunnerFactory } from '../task_runner';
|
||||
import { AlertTypeRegistry, ConstructorOptions } from '../alert_type_registry';
|
||||
import { RuleTypeRegistry, ConstructorOptions } from '../rule_type_registry';
|
||||
import { taskManagerMock } from '../../../task_manager/server/mocks';
|
||||
import { ILicenseState } from '../lib/license_state';
|
||||
import { licenseStateMock } from '../lib/license_state.mock';
|
||||
|
@ -33,7 +33,7 @@ beforeEach(() => {
|
|||
|
||||
describe('isRuleExportable', () => {
|
||||
it('should return true if rule type isExportable is true', () => {
|
||||
const registry = new AlertTypeRegistry(ruleTypeRegistryParams);
|
||||
const registry = new RuleTypeRegistry(ruleTypeRegistryParams);
|
||||
registry.register({
|
||||
id: 'foo',
|
||||
name: 'Foo',
|
||||
|
@ -89,7 +89,7 @@ describe('isRuleExportable', () => {
|
|||
});
|
||||
|
||||
it('should return false and log warning if rule type isExportable is false', () => {
|
||||
const registry = new AlertTypeRegistry(ruleTypeRegistryParams);
|
||||
const registry = new RuleTypeRegistry(ruleTypeRegistryParams);
|
||||
registry.register({
|
||||
id: 'foo',
|
||||
name: 'Foo',
|
||||
|
@ -148,7 +148,7 @@ describe('isRuleExportable', () => {
|
|||
});
|
||||
|
||||
it('should return false and log warning if rule type is not registered', () => {
|
||||
const registry = new AlertTypeRegistry(ruleTypeRegistryParams);
|
||||
const registry = new RuleTypeRegistry(ruleTypeRegistryParams);
|
||||
registry.register({
|
||||
id: 'foo',
|
||||
name: 'Foo',
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
|
||||
import { Logger, SavedObject } from 'kibana/server';
|
||||
import { RawAlert } from '../types';
|
||||
import { AlertTypeRegistry } from '../alert_type_registry';
|
||||
import { RuleTypeRegistry } from '../rule_type_registry';
|
||||
|
||||
export function isRuleExportable(
|
||||
rule: SavedObject,
|
||||
ruleTypeRegistry: AlertTypeRegistry,
|
||||
ruleTypeRegistry: RuleTypeRegistry,
|
||||
logger: Logger
|
||||
): boolean {
|
||||
const ruleSO = rule as SavedObject<RawAlert>;
|
||||
|
|
|
@ -16,7 +16,7 @@ import { eventLoggerMock } from '../../../event_log/server/event_logger.mock';
|
|||
import { KibanaRequest } from 'kibana/server';
|
||||
import { asSavedObjectExecutionSource } from '../../../actions/server';
|
||||
import { InjectActionParamsOpts } from './inject_action_params';
|
||||
import { NormalizedAlertType } from '../alert_type_registry';
|
||||
import { NormalizedAlertType } from '../rule_type_registry';
|
||||
import {
|
||||
AlertTypeParams,
|
||||
AlertTypeState,
|
||||
|
|
|
@ -21,7 +21,7 @@ import {
|
|||
AlertInstanceContext,
|
||||
RawAlert,
|
||||
} from '../types';
|
||||
import { NormalizedAlertType } from '../alert_type_registry';
|
||||
import { NormalizedAlertType } from '../rule_type_registry';
|
||||
import { isEphemeralTaskRejectedDueToCapacityError } from '../../../task_manager/server';
|
||||
|
||||
export interface CreateExecutionHandlerOptions<
|
||||
|
|
|
@ -36,8 +36,8 @@ import { IEventLogger } from '../../../event_log/server';
|
|||
import { SavedObjectsErrorHelpers } from '../../../../../src/core/server';
|
||||
import { Alert, RecoveredActionGroup } from '../../common';
|
||||
import { omit } from 'lodash';
|
||||
import { UntypedNormalizedAlertType } from '../alert_type_registry';
|
||||
import { alertTypeRegistryMock } from '../alert_type_registry.mock';
|
||||
import { UntypedNormalizedAlertType } from '../rule_type_registry';
|
||||
import { ruleTypeRegistryMock } from '../rule_type_registry.mock';
|
||||
import { ExecuteOptions } from '../../../actions/server/create_execute_function';
|
||||
|
||||
const alertType: jest.Mocked<UntypedNormalizedAlertType> = {
|
||||
|
@ -84,7 +84,7 @@ describe('Task Runner', () => {
|
|||
const services = alertsMock.createAlertServices();
|
||||
const actionsClient = actionsClientMock.create();
|
||||
const rulesClient = rulesClientMock.create();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
|
||||
type TaskRunnerFactoryInitializerParamsType = jest.Mocked<TaskRunnerContext> & {
|
||||
actionsPlugin: jest.Mocked<ActionsPluginStart>;
|
||||
|
@ -101,7 +101,7 @@ describe('Task Runner', () => {
|
|||
basePathService: httpServiceMock.createBasePath(),
|
||||
eventLogger: eventLoggerMock.create(),
|
||||
internalSavedObjectsRepository: savedObjectsRepositoryMock.create(),
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
kibanaBaseUrl: 'https://localhost:5601',
|
||||
supportsEphemeralTasks: false,
|
||||
maxEphemeralActionsPerAlert: new Promise((resolve) => resolve(10)),
|
||||
|
@ -184,7 +184,7 @@ describe('Task Runner', () => {
|
|||
taskRunnerFactoryInitializerParams.actionsPlugin.renderActionParameterTemplates.mockImplementation(
|
||||
(actionTypeId, actionId, params) => params
|
||||
);
|
||||
alertTypeRegistry.get.mockReturnValue(alertType);
|
||||
ruleTypeRegistry.get.mockReturnValue(alertType);
|
||||
});
|
||||
|
||||
test('successfully executes the task', async () => {
|
||||
|
@ -2623,7 +2623,7 @@ describe('Task Runner', () => {
|
|||
});
|
||||
|
||||
test('recovers gracefully when the Alert Task Runner throws an exception when license is higher than supported', async () => {
|
||||
alertTypeRegistry.ensureAlertTypeEnabled.mockImplementation(() => {
|
||||
ruleTypeRegistry.ensureRuleTypeEnabled.mockImplementation(() => {
|
||||
throw new Error('OMG');
|
||||
});
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ import {
|
|||
SanitizedAlert,
|
||||
AlertExecutionStatus,
|
||||
AlertExecutionStatusErrorReasons,
|
||||
AlertTypeRegistry,
|
||||
RuleTypeRegistry,
|
||||
} from '../types';
|
||||
import { promiseResult, map, Resultable, asOk, asErr, resolveErr } from '../lib/result_type';
|
||||
import { taskInstanceToAlertTaskInstance } from './alert_task_instance';
|
||||
|
@ -49,7 +49,7 @@ import {
|
|||
AlertInstanceContext,
|
||||
WithoutReservedActionGroups,
|
||||
} from '../../common';
|
||||
import { NormalizedAlertType } from '../alert_type_registry';
|
||||
import { NormalizedAlertType } from '../rule_type_registry';
|
||||
import { getEsErrorMessage } from '../lib/errors';
|
||||
|
||||
const FALLBACK_RETRY_INTERVAL = '5m';
|
||||
|
@ -89,7 +89,7 @@ export class TaskRunner<
|
|||
ActionGroupIds,
|
||||
RecoveryActionGroupId
|
||||
>;
|
||||
private readonly alertTypeRegistry: AlertTypeRegistry;
|
||||
private readonly ruleTypeRegistry: RuleTypeRegistry;
|
||||
|
||||
constructor(
|
||||
alertType: NormalizedAlertType<
|
||||
|
@ -108,7 +108,7 @@ export class TaskRunner<
|
|||
this.logger = context.logger;
|
||||
this.alertType = alertType;
|
||||
this.taskInstance = taskInstanceToAlertTaskInstance(taskInstance);
|
||||
this.alertTypeRegistry = context.alertTypeRegistry;
|
||||
this.ruleTypeRegistry = context.ruleTypeRegistry;
|
||||
}
|
||||
|
||||
async getApiKeyForAlertPermissions(alertId: string, spaceId: string) {
|
||||
|
@ -245,7 +245,7 @@ export class TaskRunner<
|
|||
state: { alertInstances: alertRawInstances = {}, alertTypeState = {}, previousStartedAt },
|
||||
} = this.taskInstance;
|
||||
const namespace = this.context.spaceIdToNamespace(spaceId);
|
||||
const alertType = this.alertTypeRegistry.get(alertTypeId);
|
||||
const alertType = this.ruleTypeRegistry.get(alertTypeId);
|
||||
|
||||
const alertInstances = mapValues<
|
||||
Record<string, RawAlertInstance>,
|
||||
|
@ -474,7 +474,7 @@ export class TaskRunner<
|
|||
}
|
||||
|
||||
try {
|
||||
this.alertTypeRegistry.ensureAlertTypeEnabled(alert.alertTypeId);
|
||||
this.ruleTypeRegistry.ensureRuleTypeEnabled(alert.alertTypeId);
|
||||
} catch (err) {
|
||||
throw new ErrorWithReason(AlertExecutionStatusErrorReasons.License, err);
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ import {
|
|||
import { actionsMock } from '../../../actions/server/mocks';
|
||||
import { alertsMock, rulesClientMock } from '../mocks';
|
||||
import { eventLoggerMock } from '../../../event_log/server/event_logger.mock';
|
||||
import { UntypedNormalizedAlertType } from '../alert_type_registry';
|
||||
import { alertTypeRegistryMock } from '../alert_type_registry.mock';
|
||||
import { UntypedNormalizedAlertType } from '../rule_type_registry';
|
||||
import { ruleTypeRegistryMock } from '../rule_type_registry.mock';
|
||||
|
||||
const alertType: UntypedNormalizedAlertType = {
|
||||
id: 'test',
|
||||
|
@ -77,7 +77,7 @@ describe('Task Runner Factory', () => {
|
|||
basePathService: httpServiceMock.createBasePath(),
|
||||
eventLogger: eventLoggerMock.create(),
|
||||
internalSavedObjectsRepository: savedObjectsRepositoryMock.create(),
|
||||
alertTypeRegistry: alertTypeRegistryMock.create(),
|
||||
ruleTypeRegistry: ruleTypeRegistryMock.create(),
|
||||
kibanaBaseUrl: 'https://localhost:5601',
|
||||
supportsEphemeralTasks: true,
|
||||
maxEphemeralActionsPerAlert: new Promise((resolve) => resolve(10)),
|
||||
|
|
|
@ -17,7 +17,7 @@ import { EncryptedSavedObjectsClient } from '../../../encrypted_saved_objects/se
|
|||
import { PluginStartContract as ActionsPluginStartContract } from '../../../actions/server';
|
||||
import {
|
||||
AlertTypeParams,
|
||||
AlertTypeRegistry,
|
||||
RuleTypeRegistry,
|
||||
GetServicesFunction,
|
||||
SpaceIdToNamespaceFunction,
|
||||
AlertTypeState,
|
||||
|
@ -27,7 +27,7 @@ import {
|
|||
import { TaskRunner } from './task_runner';
|
||||
import { IEventLogger } from '../../../event_log/server';
|
||||
import { RulesClient } from '../rules_client';
|
||||
import { NormalizedAlertType } from '../alert_type_registry';
|
||||
import { NormalizedAlertType } from '../rule_type_registry';
|
||||
|
||||
export interface TaskRunnerContext {
|
||||
logger: Logger;
|
||||
|
@ -39,7 +39,7 @@ export interface TaskRunnerContext {
|
|||
spaceIdToNamespace: SpaceIdToNamespaceFunction;
|
||||
basePathService: IBasePath;
|
||||
internalSavedObjectsRepository: ISavedObjectsRepository;
|
||||
alertTypeRegistry: AlertTypeRegistry;
|
||||
ruleTypeRegistry: RuleTypeRegistry;
|
||||
kibanaBaseUrl: string | undefined;
|
||||
supportsEphemeralTasks: boolean;
|
||||
maxEphemeralActionsPerAlert: Promise<number>;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import type { IRouter, RequestHandlerContext, SavedObjectReference } from 'src/core/server';
|
||||
import type { PublicMethodsOf } from '@kbn/utility-types';
|
||||
import { PublicAlertInstance } from './alert_instance';
|
||||
import { AlertTypeRegistry as OrigAlertTypeRegistry } from './alert_type_registry';
|
||||
import { RuleTypeRegistry as OrigruleTypeRegistry } from './rule_type_registry';
|
||||
import { PluginSetupContract, PluginStartContract } from './plugin';
|
||||
import { RulesClient } from './rules_client';
|
||||
export * from '../common';
|
||||
|
@ -45,7 +45,7 @@ export type SpaceIdToNamespaceFunction = (spaceId?: string) => string | undefine
|
|||
*/
|
||||
export interface AlertingApiRequestHandlerContext {
|
||||
getRulesClient: () => RulesClient;
|
||||
listTypes: AlertTypeRegistry['list'];
|
||||
listTypes: RuleTypeRegistry['list'];
|
||||
getFrameworkHealth: () => Promise<AlertsHealth>;
|
||||
areApiKeysEnabled: () => Promise<boolean>;
|
||||
}
|
||||
|
@ -252,4 +252,4 @@ export interface InvalidatePendingApiKey {
|
|||
createdAt: string;
|
||||
}
|
||||
|
||||
export type AlertTypeRegistry = PublicMethodsOf<OrigAlertTypeRegistry>;
|
||||
export type RuleTypeRegistry = PublicMethodsOf<OrigruleTypeRegistry>;
|
||||
|
|
|
@ -49,7 +49,7 @@ describe('renderApp', () => {
|
|||
|
||||
const plugins = {
|
||||
licensing: { license$: new Observable() },
|
||||
triggersActionsUi: { actionTypeRegistry: {}, alertTypeRegistry: {} },
|
||||
triggersActionsUi: { actionTypeRegistry: {}, ruleTypeRegistry: {} },
|
||||
data: {
|
||||
query: {
|
||||
timefilter: {
|
||||
|
@ -80,7 +80,7 @@ describe('renderApp', () => {
|
|||
},
|
||||
triggersActionsUi: {
|
||||
actionTypeRegistry: {},
|
||||
alertTypeRegistry: {},
|
||||
ruleTypeRegistry: {},
|
||||
getAddAlertFlyout: jest.fn(),
|
||||
getEditAlertFlyout: jest.fn(),
|
||||
},
|
||||
|
|
|
@ -41,8 +41,8 @@ export class Plugin implements InfraClientPluginClass {
|
|||
pluginsSetup.observability.observabilityRuleTypeRegistry.register(
|
||||
createLogThresholdAlertType()
|
||||
);
|
||||
pluginsSetup.triggersActionsUi.ruleTypeRegistry.register(createMetricThresholdAlertType());
|
||||
|
||||
pluginsSetup.triggersActionsUi.alertTypeRegistry.register(createMetricThresholdAlertType());
|
||||
pluginsSetup.observability.dashboard.register({
|
||||
appName: 'infra_logs',
|
||||
hasData: getLogsHasDataFetcher(core.getStartServices),
|
||||
|
|
|
@ -17,7 +17,7 @@ export function registerJobsHealthAlertingRule(
|
|||
triggersActionsUi: TriggersAndActionsUIPublicPluginSetup,
|
||||
alerting?: AlertingSetup
|
||||
) {
|
||||
triggersActionsUi.alertTypeRegistry.register({
|
||||
triggersActionsUi.ruleTypeRegistry.register({
|
||||
id: ML_ALERT_TYPES.AD_JOBS_HEALTH,
|
||||
description: i18n.translate('xpack.ml.alertTypes.jobsHealthAlertingRule.description', {
|
||||
defaultMessage: 'Alert when anomaly detection jobs experience operational issues.',
|
||||
|
|
|
@ -20,7 +20,7 @@ export function registerMlAlerts(
|
|||
triggersActionsUi: TriggersAndActionsUIPublicPluginSetup,
|
||||
alerting?: AlertingSetup
|
||||
) {
|
||||
triggersActionsUi.alertTypeRegistry.register({
|
||||
triggersActionsUi.ruleTypeRegistry.register({
|
||||
id: ML_ALERT_TYPES.ANOMALY_DETECTION,
|
||||
description: i18n.translate('xpack.ml.alertTypes.anomalyDetection.description', {
|
||||
defaultMessage: 'Alert when anomaly detection jobs results match the condition.',
|
||||
|
|
|
@ -15,7 +15,7 @@ import { ReactWrapper, mount } from 'enzyme';
|
|||
import { act } from 'react-dom/test-utils';
|
||||
import { coreMock } from 'src/core/public/mocks';
|
||||
import { actionTypeRegistryMock } from '../../../triggers_actions_ui/public/application/action_type_registry.mock';
|
||||
import { alertTypeRegistryMock } from '../../../triggers_actions_ui/public/application/alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../../triggers_actions_ui/public/application/rule_type_registry.mock';
|
||||
import {
|
||||
ValidationResult,
|
||||
Alert,
|
||||
|
@ -47,7 +47,7 @@ jest.mock('../../../triggers_actions_ui/public/application/lib/alert_api', () =>
|
|||
const initLegacyShims = () => {
|
||||
const triggersActionsUi = {
|
||||
actionTypeRegistry: actionTypeRegistryMock.create(),
|
||||
alertTypeRegistry: alertTypeRegistryMock.create(),
|
||||
ruleTypeRegistry: ruleTypeRegistryMock.create(),
|
||||
};
|
||||
const data = { query: { timefilter: { timefilter: {} } } } as any;
|
||||
const ngInjector = {} as angular.auto.IInjectorService;
|
||||
|
@ -66,7 +66,7 @@ const initLegacyShims = () => {
|
|||
const ALERTS_FEATURE_ID = 'alerts';
|
||||
const validationMethod = (): ValidationResult => ({ errors: {} });
|
||||
const actionTypeRegistry = actionTypeRegistryMock.create();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
|
||||
describe('alert_form', () => {
|
||||
beforeEach(() => {
|
||||
|
@ -109,9 +109,9 @@ describe('alert_form', () => {
|
|||
let wrapper: ReactWrapper<any>;
|
||||
|
||||
beforeEach(async () => {
|
||||
alertTypeRegistry.list.mockReturnValue([alertType]);
|
||||
alertTypeRegistry.get.mockReturnValue(alertType);
|
||||
alertTypeRegistry.has.mockReturnValue(true);
|
||||
ruleTypeRegistry.list.mockReturnValue([alertType]);
|
||||
ruleTypeRegistry.get.mockReturnValue(alertType);
|
||||
ruleTypeRegistry.has.mockReturnValue(true);
|
||||
actionTypeRegistry.list.mockReturnValue([actionType]);
|
||||
actionTypeRegistry.has.mockReturnValue(true);
|
||||
actionTypeRegistry.get.mockReturnValue(actionType);
|
||||
|
@ -142,7 +142,7 @@ describe('alert_form', () => {
|
|||
errors={{ name: [], interval: [] }}
|
||||
operation="create"
|
||||
actionTypeRegistry={actionTypeRegistry}
|
||||
alertTypeRegistry={alertTypeRegistry}
|
||||
ruleTypeRegistry={ruleTypeRegistry}
|
||||
/>
|
||||
</KibanaReactContext.Provider>
|
||||
</I18nProvider>
|
||||
|
|
|
@ -52,7 +52,7 @@ export interface IShims {
|
|||
docTitle: CoreStart['chrome']['docTitle'];
|
||||
timefilter: MonitoringStartPluginDependencies['data']['query']['timefilter']['timefilter'];
|
||||
actionTypeRegistry: TypeRegistry<ActionTypeModel>;
|
||||
alertTypeRegistry: TypeRegistry<AlertTypeModel>;
|
||||
ruleTypeRegistry: TypeRegistry<AlertTypeModel>;
|
||||
uiSettings: IUiSettingsClient;
|
||||
http: HttpSetup;
|
||||
kfetch: (
|
||||
|
@ -119,7 +119,7 @@ export class Legacy {
|
|||
docTitle: core.chrome.docTitle,
|
||||
timefilter: data.query.timefilter.timefilter,
|
||||
actionTypeRegistry: triggersActionsUi?.actionTypeRegistry,
|
||||
alertTypeRegistry: triggersActionsUi?.alertTypeRegistry,
|
||||
ruleTypeRegistry: triggersActionsUi?.ruleTypeRegistry,
|
||||
uiSettings: core.uiSettings,
|
||||
http: core.http,
|
||||
kfetch: async (
|
||||
|
|
|
@ -171,29 +171,29 @@ export class MonitoringPlugin
|
|||
|
||||
private registerAlerts(plugins: MonitoringSetupPluginDependencies) {
|
||||
const {
|
||||
triggersActionsUi: { alertTypeRegistry },
|
||||
triggersActionsUi: { ruleTypeRegistry },
|
||||
} = plugins;
|
||||
alertTypeRegistry.register(createCpuUsageAlertType());
|
||||
alertTypeRegistry.register(createDiskUsageAlertType());
|
||||
alertTypeRegistry.register(createMemoryUsageAlertType());
|
||||
alertTypeRegistry.register(createMissingMonitoringDataAlertType());
|
||||
alertTypeRegistry.register(
|
||||
ruleTypeRegistry.register(createCpuUsageAlertType());
|
||||
ruleTypeRegistry.register(createDiskUsageAlertType());
|
||||
ruleTypeRegistry.register(createMemoryUsageAlertType());
|
||||
ruleTypeRegistry.register(createMissingMonitoringDataAlertType());
|
||||
ruleTypeRegistry.register(
|
||||
createThreadPoolRejectionsAlertType(
|
||||
ALERT_THREAD_POOL_SEARCH_REJECTIONS,
|
||||
ALERT_DETAILS[ALERT_THREAD_POOL_SEARCH_REJECTIONS]
|
||||
)
|
||||
);
|
||||
alertTypeRegistry.register(
|
||||
ruleTypeRegistry.register(
|
||||
createThreadPoolRejectionsAlertType(
|
||||
ALERT_THREAD_POOL_WRITE_REJECTIONS,
|
||||
ALERT_DETAILS[ALERT_THREAD_POOL_WRITE_REJECTIONS]
|
||||
)
|
||||
);
|
||||
alertTypeRegistry.register(createCCRReadExceptionsAlertType());
|
||||
alertTypeRegistry.register(createLargeShardSizeAlertType());
|
||||
ruleTypeRegistry.register(createCCRReadExceptionsAlertType());
|
||||
ruleTypeRegistry.register(createLargeShardSizeAlertType());
|
||||
const legacyAlertTypes = createLegacyAlertTypes();
|
||||
for (const legacyAlertType of legacyAlertTypes) {
|
||||
alertTypeRegistry.register(legacyAlertType);
|
||||
ruleTypeRegistry.register(legacyAlertType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ export class Plugin
|
|||
createCallObservabilityApi(coreSetup.http);
|
||||
|
||||
const observabilityRuleTypeRegistry = createObservabilityRuleTypeRegistry(
|
||||
pluginsSetup.triggersActionsUi.alertTypeRegistry
|
||||
pluginsSetup.triggersActionsUi.ruleTypeRegistry
|
||||
);
|
||||
|
||||
const mount = async (params: AppMountParameters<unknown>) => {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import {
|
||||
AlertTypeModel,
|
||||
AlertTypeParams,
|
||||
AlertTypeRegistryContract,
|
||||
RuleTypeRegistryContract,
|
||||
} from '../../../triggers_actions_ui/public';
|
||||
import { ParsedTechnicalFields } from '../../../rule_registry/common/parse_technical_fields';
|
||||
import { AsDuration, AsPercent } from '../../common/utils/formatters';
|
||||
|
@ -23,14 +23,14 @@ export interface ObservabilityRuleTypeModel<Params extends AlertTypeParams = Ale
|
|||
format: ObservabilityRuleTypeFormatter;
|
||||
}
|
||||
|
||||
export function createObservabilityRuleTypeRegistry(alertTypeRegistry: AlertTypeRegistryContract) {
|
||||
export function createObservabilityRuleTypeRegistry(ruleTypeRegistry: RuleTypeRegistryContract) {
|
||||
const formatters: Array<{ typeId: string; fn: ObservabilityRuleTypeFormatter }> = [];
|
||||
|
||||
return {
|
||||
register: (type: ObservabilityRuleTypeModel<any>) => {
|
||||
const { format, ...rest } = type;
|
||||
formatters.push({ typeId: type.id, fn: format });
|
||||
alertTypeRegistry.register(rest);
|
||||
ruleTypeRegistry.register(rest);
|
||||
},
|
||||
getFormatter: (typeId: string) => {
|
||||
return formatters.find((formatter) => formatter.typeId === typeId)?.fn;
|
||||
|
|
|
@ -12,13 +12,13 @@ import { Config } from '../../common';
|
|||
import { TriggersAndActionsUIPublicPluginSetup } from '../../../triggers_actions_ui/public';
|
||||
|
||||
export function registerAlertTypes({
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
config,
|
||||
}: {
|
||||
alertTypeRegistry: TriggersAndActionsUIPublicPluginSetup['alertTypeRegistry'];
|
||||
ruleTypeRegistry: TriggersAndActionsUIPublicPluginSetup['ruleTypeRegistry'];
|
||||
config: Config;
|
||||
}) {
|
||||
alertTypeRegistry.register(getGeoContainmentAlertType());
|
||||
alertTypeRegistry.register(getThresholdAlertType());
|
||||
alertTypeRegistry.register(getEsQueryAlertType());
|
||||
ruleTypeRegistry.register(getGeoContainmentAlertType());
|
||||
ruleTypeRegistry.register(getThresholdAlertType());
|
||||
ruleTypeRegistry.register(getEsQueryAlertType());
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ export class StackAlertsPublicPlugin implements Plugin<Setup, Start, StackAlerts
|
|||
|
||||
public setup(core: CoreSetup, { triggersActionsUi }: StackAlertsPublicSetupDeps) {
|
||||
registerAlertTypes({
|
||||
alertTypeRegistry: triggersActionsUi.alertTypeRegistry,
|
||||
ruleTypeRegistry: triggersActionsUi.ruleTypeRegistry,
|
||||
config: this.initializerContext.config.get<Config>(),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -5415,9 +5415,9 @@
|
|||
"xpack.alerting.alertNavigationRegistry.get.missingNavigationError": "「{consumer}」内のアラートタイプ「{alertType}」のナビゲーションは登録されていません。",
|
||||
"xpack.alerting.alertNavigationRegistry.register.duplicateDefaultError": "「{consumer}」内のデフォルトナビゲーションはすでに登録されています。",
|
||||
"xpack.alerting.alertNavigationRegistry.register.duplicateNavigationError": "「{consumer}」内のアラートタイプ「{alertType}」のナビゲーションはすでに登録されています。",
|
||||
"xpack.alerting.alertTypeRegistry.get.missingAlertTypeError": "アラートタイプ「{id}」は登録されていません。",
|
||||
"xpack.alerting.alertTypeRegistry.register.customRecoveryActionGroupUsageError": "アラートタイプ [id=\"{id}\"] を登録できません。アクショングループ [{actionGroup}] は、復元とアクティブなアクショングループの両方として使用できません。",
|
||||
"xpack.alerting.alertTypeRegistry.register.duplicateAlertTypeError": "アラートタイプ\"{id}\"はすでに登録されています。",
|
||||
"xpack.alerting.ruleTypeRegistry.get.missingAlertTypeError": "アラートタイプ「{id}」は登録されていません。",
|
||||
"xpack.alerting.ruleTypeRegistry.register.customRecoveryActionGroupUsageError": "アラートタイプ [id=\"{id}\"] を登録できません。アクショングループ [{actionGroup}] は、復元とアクティブなアクショングループの両方として使用できません。",
|
||||
"xpack.alerting.ruleTypeRegistry.register.duplicateAlertTypeError": "アラートタイプ\"{id}\"はすでに登録されています。",
|
||||
"xpack.alerting.api.error.disabledApiKeys": "アラートは API キーに依存しますがキーが無効になっているようです",
|
||||
"xpack.alerting.appName": "アラート",
|
||||
"xpack.alerting.builtinActionGroups.recovered": "回復済み",
|
||||
|
|
|
@ -5445,10 +5445,10 @@
|
|||
"xpack.alerting.alertNavigationRegistry.get.missingNavigationError": "在“{consumer}”内针对告警类型“{alertType}”的导航未注册。",
|
||||
"xpack.alerting.alertNavigationRegistry.register.duplicateDefaultError": "“{consumer}”内的默认导航已注册。",
|
||||
"xpack.alerting.alertNavigationRegistry.register.duplicateNavigationError": "在“{consumer}”内针对告警类型“{alertType}”的导航已注册。",
|
||||
"xpack.alerting.alertTypeRegistry.get.missingAlertTypeError": "未注册告警类型“{id}”。",
|
||||
"xpack.alerting.alertTypeRegistry.register.customRecoveryActionGroupUsageError": "无法注册告警类型 [id=\"{id}\"]。操作组 [{actionGroup}] 无法同时用作恢复和活动操作组。",
|
||||
"xpack.alerting.alertTypeRegistry.register.duplicateAlertTypeError": "已注册告警类型“{id}”。",
|
||||
"xpack.alerting.alertTypeRegistry.register.reservedActionGroupUsageError": "无法注册告警类型 [id=\"{id}\"]。操作组 [{actionGroups}] 由框架保留。",
|
||||
"xpack.alerting.ruleTypeRegistry.get.missingAlertTypeError": "未注册告警类型“{id}”。",
|
||||
"xpack.alerting.ruleTypeRegistry.register.customRecoveryActionGroupUsageError": "无法注册告警类型 [id=\"{id}\"]。操作组 [{actionGroup}] 无法同时用作恢复和活动操作组。",
|
||||
"xpack.alerting.ruleTypeRegistry.register.duplicateAlertTypeError": "已注册告警类型“{id}”。",
|
||||
"xpack.alerting.ruleTypeRegistry.register.reservedActionGroupUsageError": "无法注册告警类型 [id=\"{id}\"]。操作组 [{actionGroups}] 由框架保留。",
|
||||
"xpack.alerting.api.error.disabledApiKeys": "Alerting 依赖的 API 密钥似乎已禁用",
|
||||
"xpack.alerting.appName": "Alerting",
|
||||
"xpack.alerting.builtinActionGroups.recovered": "已恢复",
|
||||
|
|
|
@ -289,7 +289,7 @@ function getSomeNewAlertType() {
|
|||
return { ... } as AlertTypeModel;
|
||||
}
|
||||
|
||||
triggersActionsUi.alertTypeRegistry.register(getSomeNewAlertType());
|
||||
triggersActionsUi.ruleTypeRegistry.register(getSomeNewAlertType());
|
||||
```
|
||||
|
||||
## Create and register new alert type UI example
|
||||
|
@ -409,7 +409,7 @@ import { getAlertType as getExampledAlertType } from './example';
|
|||
...
|
||||
|
||||
...
|
||||
alertTypeRegistry.register(getExampledAlertType());
|
||||
ruleTypeRegistry.register(getExampledAlertType());
|
||||
```
|
||||
|
||||
After these four steps, the new `Example Alert Type` is available in UI of Create flyout:
|
||||
|
@ -1472,7 +1472,7 @@ interface ActionAccordionFormProps {
|
|||
|---|---|
|
||||
|onSave|Optional function, which will be executed if alert was saved sucsessfuly.|
|
||||
|http|HttpSetup needed for executing API calls.|
|
||||
|alertTypeRegistry|Registry for alert types.|
|
||||
|ruleTypeRegistry|Registry for alert types.|
|
||||
|actionTypeRegistry|Registry for action types.|
|
||||
|uiSettings|Optional property, which is needed to display visualization of alert type expression. Will be changed after visualization refactoring.|
|
||||
|docLinks|Documentation Links, needed to link to the documentation from informational callouts.|
|
||||
|
|
|
@ -13,7 +13,7 @@ import { I18nProvider } from '@kbn/i18n/react';
|
|||
import useObservable from 'react-use/lib/useObservable';
|
||||
import { KibanaFeature } from '../../../features/common';
|
||||
import { Section, routeToRuleDetails, legacyRouteToRuleDetails } from './constants';
|
||||
import { ActionTypeRegistryContract, AlertTypeRegistryContract } from '../types';
|
||||
import { ActionTypeRegistryContract, RuleTypeRegistryContract } from '../types';
|
||||
import { ChartsPluginStart } from '../../../../../src/plugins/charts/public';
|
||||
import { DataPublicPluginStart } from '../../../../../src/plugins/data/public';
|
||||
import { PluginStartContract as AlertingStart } from '../../../alerting/public';
|
||||
|
@ -39,7 +39,7 @@ export interface TriggersAndActionsUiServices extends CoreStart {
|
|||
storage?: Storage;
|
||||
setBreadcrumbs: (crumbs: ChromeBreadcrumb[]) => void;
|
||||
actionTypeRegistry: ActionTypeRegistryContract;
|
||||
alertTypeRegistry: AlertTypeRegistryContract;
|
||||
ruleTypeRegistry: RuleTypeRegistryContract;
|
||||
history: ScopedHistory;
|
||||
kibanaFeatures: KibanaFeature[];
|
||||
element: HTMLElement;
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { AlertTypeRegistryContract } from '../types';
|
||||
import { RuleTypeRegistryContract } from '../types';
|
||||
|
||||
const createAlertTypeRegistryMock = () => {
|
||||
const mocked: jest.Mocked<AlertTypeRegistryContract> = {
|
||||
const createruleTypeRegistryMock = () => {
|
||||
const mocked: jest.Mocked<RuleTypeRegistryContract> = {
|
||||
has: jest.fn(),
|
||||
register: jest.fn(),
|
||||
get: jest.fn(),
|
||||
|
@ -17,6 +17,6 @@ const createAlertTypeRegistryMock = () => {
|
|||
return mocked;
|
||||
};
|
||||
|
||||
export const alertTypeRegistryMock = {
|
||||
create: createAlertTypeRegistryMock,
|
||||
export const ruleTypeRegistryMock = {
|
||||
create: createruleTypeRegistryMock,
|
||||
};
|
|
@ -26,7 +26,7 @@ import {
|
|||
ALERTS_FEATURE_ID,
|
||||
} from '../../../../../../alerting/common';
|
||||
import { useKibana } from '../../../../common/lib/kibana';
|
||||
import { alertTypeRegistryMock } from '../../../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../../rule_type_registry.mock';
|
||||
|
||||
jest.mock('../../../../common/lib/kibana');
|
||||
|
||||
|
@ -45,7 +45,7 @@ jest.mock('../../../lib/capabilities', () => ({
|
|||
hasExecuteActionsCapability: jest.fn(() => true),
|
||||
}));
|
||||
const useKibanaMock = useKibana as jest.Mocked<typeof useKibana>;
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
|
||||
const mockAlertApis = {
|
||||
muteAlert: jest.fn(),
|
||||
|
@ -739,7 +739,7 @@ describe('edit button', () => {
|
|||
minimumLicenseRequired: 'basic',
|
||||
},
|
||||
];
|
||||
alertTypeRegistry.has.mockReturnValue(true);
|
||||
ruleTypeRegistry.has.mockReturnValue(true);
|
||||
const alertTypeR: AlertTypeModel = {
|
||||
id: 'my-alert-type',
|
||||
iconClass: 'test',
|
||||
|
@ -751,8 +751,8 @@ describe('edit button', () => {
|
|||
alertParamsExpression: jest.fn(),
|
||||
requiresAppContext: false,
|
||||
};
|
||||
alertTypeRegistry.get.mockReturnValue(alertTypeR);
|
||||
useKibanaMock().services.alertTypeRegistry = alertTypeRegistry;
|
||||
ruleTypeRegistry.get.mockReturnValue(alertTypeR);
|
||||
useKibanaMock().services.ruleTypeRegistry = ruleTypeRegistry;
|
||||
|
||||
it('should render an edit button when alert and actions are editable', () => {
|
||||
const alert = mockAlert({
|
||||
|
|
|
@ -60,7 +60,7 @@ export const AlertDetails: React.FunctionComponent<AlertDetailsProps> = ({
|
|||
const history = useHistory();
|
||||
const {
|
||||
application: { capabilities },
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
actionTypeRegistry,
|
||||
setBreadcrumbs,
|
||||
chrome,
|
||||
|
@ -92,8 +92,8 @@ export const AlertDetails: React.FunctionComponent<AlertDetailsProps> = ({
|
|||
// can the user save the alert
|
||||
canSaveAlert &&
|
||||
// is this alert type editable from within Alerts Management
|
||||
(alertTypeRegistry.has(alert.alertTypeId)
|
||||
? !alertTypeRegistry.get(alert.alertTypeId).requiresAppContext
|
||||
(ruleTypeRegistry.has(alert.alertTypeId)
|
||||
? !ruleTypeRegistry.get(alert.alertTypeId).requiresAppContext
|
||||
: false);
|
||||
|
||||
const alertActions = alert.actions;
|
||||
|
@ -138,7 +138,7 @@ export const AlertDetails: React.FunctionComponent<AlertDetailsProps> = ({
|
|||
setEditFlyoutVisibility(false);
|
||||
}}
|
||||
actionTypeRegistry={actionTypeRegistry}
|
||||
alertTypeRegistry={alertTypeRegistry}
|
||||
ruleTypeRegistry={ruleTypeRegistry}
|
||||
onSave={setAlert}
|
||||
/>
|
||||
)}
|
||||
|
|
|
@ -23,7 +23,7 @@ import {
|
|||
GenericValidationResult,
|
||||
ValidationResult,
|
||||
} from '../../../types';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
import { ReactWrapper } from 'enzyme';
|
||||
import { ALERTS_FEATURE_ID } from '../../../../../alerting/common';
|
||||
import { useKibana } from '../../../common/lib/kibana';
|
||||
|
@ -44,7 +44,7 @@ jest.mock('../../../common/lib/health_api', () => ({
|
|||
}));
|
||||
|
||||
const actionTypeRegistry = actionTypeRegistryMock.create();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
const useKibanaMock = useKibana as jest.Mocked<typeof useKibana>;
|
||||
|
||||
const delay = (wait: number = 1000) =>
|
||||
|
@ -146,9 +146,9 @@ describe('alert_add', () => {
|
|||
});
|
||||
actionTypeRegistry.get.mockReturnValueOnce(actionTypeModel);
|
||||
actionTypeRegistry.has.mockReturnValue(true);
|
||||
alertTypeRegistry.list.mockReturnValue([alertType]);
|
||||
alertTypeRegistry.get.mockReturnValue(alertType);
|
||||
alertTypeRegistry.has.mockReturnValue(true);
|
||||
ruleTypeRegistry.list.mockReturnValue([alertType]);
|
||||
ruleTypeRegistry.get.mockReturnValue(alertType);
|
||||
ruleTypeRegistry.has.mockReturnValue(true);
|
||||
actionTypeRegistry.list.mockReturnValue([actionTypeModel]);
|
||||
actionTypeRegistry.has.mockReturnValue(true);
|
||||
|
||||
|
@ -161,7 +161,7 @@ describe('alert_add', () => {
|
|||
return new Promise<void>(() => {});
|
||||
}}
|
||||
actionTypeRegistry={actionTypeRegistry}
|
||||
alertTypeRegistry={alertTypeRegistry}
|
||||
ruleTypeRegistry={ruleTypeRegistry}
|
||||
metadata={{ test: 'some value', fields: ['test'] }}
|
||||
/>
|
||||
);
|
||||
|
|
|
@ -33,7 +33,7 @@ import { getAlertWithInvalidatedFields } from '../../lib/value_validators';
|
|||
|
||||
const AlertAdd = ({
|
||||
consumer,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
actionTypeRegistry,
|
||||
onClose,
|
||||
canChangeTrigger,
|
||||
|
@ -137,7 +137,7 @@ const AlertAdd = ({
|
|||
}
|
||||
};
|
||||
|
||||
const alertType = alert.alertTypeId ? alertTypeRegistry.get(alert.alertTypeId) : null;
|
||||
const alertType = alert.alertTypeId ? ruleTypeRegistry.get(alert.alertTypeId) : null;
|
||||
const { alertBaseErrors, alertErrors, alertParamsErrors } = getAlertErrors(
|
||||
alert as Alert,
|
||||
alertType
|
||||
|
@ -202,7 +202,7 @@ const AlertAdd = ({
|
|||
}
|
||||
)}
|
||||
actionTypeRegistry={actionTypeRegistry}
|
||||
alertTypeRegistry={alertTypeRegistry}
|
||||
ruleTypeRegistry={ruleTypeRegistry}
|
||||
metadata={metadata}
|
||||
/>
|
||||
</EuiFlyoutBody>
|
||||
|
|
|
@ -16,14 +16,14 @@ import {
|
|||
ConnectorValidationResult,
|
||||
GenericValidationResult,
|
||||
} from '../../../types';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
import { ReactWrapper } from 'enzyme';
|
||||
import AlertEdit from './alert_edit';
|
||||
import { useKibana } from '../../../common/lib/kibana';
|
||||
import { ALERTS_FEATURE_ID } from '../../../../../alerting/common';
|
||||
jest.mock('../../../common/lib/kibana');
|
||||
const actionTypeRegistry = actionTypeRegistryMock.create();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
const useKibanaMock = useKibana as jest.Mocked<typeof useKibana>;
|
||||
|
||||
jest.mock('../../lib/alert_api', () => ({
|
||||
|
@ -157,9 +157,9 @@ describe('alert_edit', () => {
|
|||
};
|
||||
actionTypeRegistry.get.mockReturnValueOnce(actionTypeModel);
|
||||
actionTypeRegistry.has.mockReturnValue(true);
|
||||
alertTypeRegistry.list.mockReturnValue([alertType]);
|
||||
alertTypeRegistry.get.mockReturnValue(alertType);
|
||||
alertTypeRegistry.has.mockReturnValue(true);
|
||||
ruleTypeRegistry.list.mockReturnValue([alertType]);
|
||||
ruleTypeRegistry.get.mockReturnValue(alertType);
|
||||
ruleTypeRegistry.has.mockReturnValue(true);
|
||||
actionTypeRegistry.list.mockReturnValue([actionTypeModel]);
|
||||
actionTypeRegistry.has.mockReturnValue(true);
|
||||
|
||||
|
@ -171,7 +171,7 @@ describe('alert_edit', () => {
|
|||
return new Promise<void>(() => {});
|
||||
}}
|
||||
actionTypeRegistry={actionTypeRegistry}
|
||||
alertTypeRegistry={alertTypeRegistry}
|
||||
ruleTypeRegistry={ruleTypeRegistry}
|
||||
/>
|
||||
);
|
||||
// Wait for active space to resolve before requesting the component to update
|
||||
|
|
|
@ -40,7 +40,7 @@ export const AlertEdit = ({
|
|||
onClose,
|
||||
reloadAlerts,
|
||||
onSave,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
actionTypeRegistry,
|
||||
metadata,
|
||||
}: AlertEditProps) => {
|
||||
|
@ -65,7 +65,7 @@ export const AlertEdit = ({
|
|||
dispatch({ command: { type: 'setAlert' }, payload: { key: 'alert', value } });
|
||||
};
|
||||
|
||||
const alertType = alertTypeRegistry.get(alert.alertTypeId);
|
||||
const alertType = ruleTypeRegistry.get(alert.alertTypeId);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
|
@ -168,7 +168,7 @@ export const AlertEdit = ({
|
|||
dispatch={dispatch}
|
||||
errors={alertErrors}
|
||||
actionTypeRegistry={actionTypeRegistry}
|
||||
alertTypeRegistry={alertTypeRegistry}
|
||||
ruleTypeRegistry={ruleTypeRegistry}
|
||||
canChangeTrigger={false}
|
||||
setHasActionsDisabled={setHasActionsDisabled}
|
||||
setHasActionsWithBrokenConnector={setHasActionsWithBrokenConnector}
|
||||
|
|
|
@ -10,7 +10,7 @@ import { mountWithIntl, nextTick } from '@kbn/test/jest';
|
|||
import { ReactWrapper } from 'enzyme';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
import { actionTypeRegistryMock } from '../../action_type_registry.mock';
|
||||
import { alertTypeRegistryMock } from '../../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../rule_type_registry.mock';
|
||||
import {
|
||||
ValidationResult,
|
||||
Alert,
|
||||
|
@ -24,7 +24,7 @@ import { ALERTS_FEATURE_ID, RecoveredActionGroup } from '../../../../../alerting
|
|||
import { useKibana } from '../../../common/lib/kibana';
|
||||
|
||||
const actionTypeRegistry = actionTypeRegistryMock.create();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
jest.mock('../../lib/alert_api', () => ({
|
||||
loadAlertTypes: jest.fn(),
|
||||
}));
|
||||
|
@ -159,12 +159,12 @@ describe('alert_form', () => {
|
|||
delete: true,
|
||||
},
|
||||
};
|
||||
alertTypeRegistry.list.mockReturnValue([
|
||||
ruleTypeRegistry.list.mockReturnValue([
|
||||
alertType,
|
||||
alertTypeNonEditable,
|
||||
disabledByLicenseAlertType,
|
||||
]);
|
||||
alertTypeRegistry.has.mockReturnValue(true);
|
||||
ruleTypeRegistry.has.mockReturnValue(true);
|
||||
actionTypeRegistry.list.mockReturnValue([actionType]);
|
||||
actionTypeRegistry.has.mockReturnValue(true);
|
||||
actionTypeRegistry.get.mockReturnValue(actionType);
|
||||
|
@ -189,7 +189,7 @@ describe('alert_form', () => {
|
|||
errors={{ name: [], interval: [], alertTypeId: [] }}
|
||||
operation="create"
|
||||
actionTypeRegistry={actionTypeRegistry}
|
||||
alertTypeRegistry={alertTypeRegistry}
|
||||
ruleTypeRegistry={ruleTypeRegistry}
|
||||
/>
|
||||
);
|
||||
|
||||
|
@ -313,7 +313,7 @@ describe('alert_form', () => {
|
|||
delete: true,
|
||||
},
|
||||
};
|
||||
alertTypeRegistry.list.mockReturnValue([
|
||||
ruleTypeRegistry.list.mockReturnValue([
|
||||
{
|
||||
id: 'same-consumer-producer-alert-type',
|
||||
iconClass: 'test',
|
||||
|
@ -337,7 +337,7 @@ describe('alert_form', () => {
|
|||
requiresAppContext: false,
|
||||
},
|
||||
]);
|
||||
alertTypeRegistry.has.mockReturnValue(true);
|
||||
ruleTypeRegistry.has.mockReturnValue(true);
|
||||
actionTypeRegistry.get.mockReturnValue(actionType);
|
||||
|
||||
const initialAlert = ({
|
||||
|
@ -361,7 +361,7 @@ describe('alert_form', () => {
|
|||
errors={{ name: [], interval: [], alertTypeId: [] }}
|
||||
operation="create"
|
||||
actionTypeRegistry={actionTypeRegistry}
|
||||
alertTypeRegistry={alertTypeRegistry}
|
||||
ruleTypeRegistry={ruleTypeRegistry}
|
||||
/>
|
||||
);
|
||||
|
||||
|
@ -394,9 +394,9 @@ describe('alert_form', () => {
|
|||
let wrapper: ReactWrapper<any>;
|
||||
|
||||
async function setup() {
|
||||
alertTypeRegistry.list.mockReturnValue([alertType]);
|
||||
alertTypeRegistry.get.mockReturnValue(alertType);
|
||||
alertTypeRegistry.has.mockReturnValue(true);
|
||||
ruleTypeRegistry.list.mockReturnValue([alertType]);
|
||||
ruleTypeRegistry.get.mockReturnValue(alertType);
|
||||
ruleTypeRegistry.has.mockReturnValue(true);
|
||||
actionTypeRegistry.list.mockReturnValue([actionType]);
|
||||
actionTypeRegistry.has.mockReturnValue(true);
|
||||
actionTypeRegistry.get.mockReturnValue(actionType);
|
||||
|
@ -423,7 +423,7 @@ describe('alert_form', () => {
|
|||
errors={{ name: [], interval: [], alertTypeId: [] }}
|
||||
operation="create"
|
||||
actionTypeRegistry={actionTypeRegistry}
|
||||
alertTypeRegistry={alertTypeRegistry}
|
||||
ruleTypeRegistry={ruleTypeRegistry}
|
||||
/>
|
||||
);
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ import {
|
|||
AlertTypeIndex,
|
||||
AlertType,
|
||||
ValidationResult,
|
||||
AlertTypeRegistryContract,
|
||||
RuleTypeRegistryContract,
|
||||
ActionTypeRegistryContract,
|
||||
} from '../../../types';
|
||||
import { getTimeOptions } from '../../../common/lib/get_time_options';
|
||||
|
@ -176,7 +176,7 @@ interface AlertFormProps<MetaData = Record<string, any>> {
|
|||
alert: InitialAlert;
|
||||
dispatch: React.Dispatch<AlertReducerAction>;
|
||||
errors: IErrorObject;
|
||||
alertTypeRegistry: AlertTypeRegistryContract;
|
||||
ruleTypeRegistry: RuleTypeRegistryContract;
|
||||
actionTypeRegistry: ActionTypeRegistryContract;
|
||||
operation: string;
|
||||
canChangeTrigger?: boolean; // to hide Change trigger button
|
||||
|
@ -193,7 +193,7 @@ export const AlertForm = ({
|
|||
setHasActionsDisabled,
|
||||
setHasActionsWithBrokenConnector,
|
||||
operation,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
actionTypeRegistry,
|
||||
metadata,
|
||||
}: AlertFormProps) => {
|
||||
|
@ -285,11 +285,11 @@ export const AlertForm = ({
|
|||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
setAlertTypeModel(alert.alertTypeId ? alertTypeRegistry.get(alert.alertTypeId) : null);
|
||||
setAlertTypeModel(alert.alertTypeId ? ruleTypeRegistry.get(alert.alertTypeId) : null);
|
||||
if (alert.alertTypeId && alertTypesIndex && alertTypesIndex.has(alert.alertTypeId)) {
|
||||
setDefaultActionGroupId(alertTypesIndex.get(alert.alertTypeId)!.defaultActionGroupId);
|
||||
}
|
||||
}, [alert, alert.alertTypeId, alertTypesIndex, alertTypeRegistry]);
|
||||
}, [alert, alert.alertTypeId, alertTypesIndex, ruleTypeRegistry]);
|
||||
|
||||
const setAlertProperty = useCallback(
|
||||
<Key extends keyof Alert>(key: Key, value: Alert[Key] | null) => {
|
||||
|
@ -344,21 +344,21 @@ export const AlertForm = ({
|
|||
)
|
||||
);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [alertTypeRegistry, availableAlertTypes, searchText, JSON.stringify(solutionsFilter)]);
|
||||
}, [ruleTypeRegistry, availableAlertTypes, searchText, JSON.stringify(solutionsFilter)]);
|
||||
|
||||
const getAvailableAlertTypes = (alertTypesResult: AlertType[]) =>
|
||||
alertTypeRegistry
|
||||
ruleTypeRegistry
|
||||
.list()
|
||||
.reduce(
|
||||
(
|
||||
arr: Array<{ alertType: AlertType; alertTypeModel: AlertTypeModel }>,
|
||||
alertTypeRegistryItem: AlertTypeModel
|
||||
ruleTypeRegistryItem: AlertTypeModel
|
||||
) => {
|
||||
const alertType = alertTypesResult.find((item) => alertTypeRegistryItem.id === item.id);
|
||||
const alertType = alertTypesResult.find((item) => ruleTypeRegistryItem.id === item.id);
|
||||
if (alertType) {
|
||||
arr.push({
|
||||
alertType,
|
||||
alertTypeModel: alertTypeRegistryItem,
|
||||
alertTypeModel: ruleTypeRegistryItem,
|
||||
});
|
||||
}
|
||||
return arr;
|
||||
|
|
|
@ -11,7 +11,7 @@ import { mountWithIntl, nextTick } from '@kbn/test/jest';
|
|||
import { ReactWrapper } from 'enzyme';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
import { actionTypeRegistryMock } from '../../../action_type_registry.mock';
|
||||
import { alertTypeRegistryMock } from '../../../alert_type_registry.mock';
|
||||
import { ruleTypeRegistryMock } from '../../../rule_type_registry.mock';
|
||||
import { AlertsList } from './alerts_list';
|
||||
import { ValidationResult } from '../../../../types';
|
||||
import {
|
||||
|
@ -47,7 +47,7 @@ jest.mock('react-router-dom', () => ({
|
|||
const { loadAlerts, loadAlertTypes } = jest.requireMock('../../../lib/alert_api');
|
||||
const { loadActionTypes, loadAllActions } = jest.requireMock('../../../lib/action_connector_api');
|
||||
const actionTypeRegistry = actionTypeRegistryMock.create();
|
||||
const alertTypeRegistry = alertTypeRegistryMock.create();
|
||||
const ruleTypeRegistry = ruleTypeRegistryMock.create();
|
||||
|
||||
const alertType = {
|
||||
id: 'test_alert_type',
|
||||
|
@ -74,7 +74,7 @@ const alertTypeFromApi = {
|
|||
[ALERTS_FEATURE_ID]: { read: true, all: true },
|
||||
},
|
||||
};
|
||||
alertTypeRegistry.list.mockReturnValue([alertType]);
|
||||
ruleTypeRegistry.list.mockReturnValue([alertType]);
|
||||
actionTypeRegistry.list.mockReturnValue([]);
|
||||
const useKibanaMock = useKibana as jest.Mocked<typeof useKibana>;
|
||||
|
||||
|
@ -101,7 +101,7 @@ describe('alerts_list component empty', () => {
|
|||
loadAllActions.mockResolvedValue([]);
|
||||
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
useKibanaMock().services.alertTypeRegistry = alertTypeRegistry;
|
||||
useKibanaMock().services.ruleTypeRegistry = ruleTypeRegistry;
|
||||
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
useKibanaMock().services.actionTypeRegistry = actionTypeRegistry;
|
||||
|
@ -284,9 +284,9 @@ describe('alerts_list component with items', () => {
|
|||
loadAlertTypes.mockResolvedValue([alertTypeFromApi]);
|
||||
loadAllActions.mockResolvedValue([]);
|
||||
|
||||
alertTypeRegistry.has.mockReturnValue(true);
|
||||
ruleTypeRegistry.has.mockReturnValue(true);
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
useKibanaMock().services.alertTypeRegistry = alertTypeRegistry;
|
||||
useKibanaMock().services.ruleTypeRegistry = ruleTypeRegistry;
|
||||
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
useKibanaMock().services.actionTypeRegistry = actionTypeRegistry;
|
||||
|
@ -435,7 +435,7 @@ describe('alerts_list component empty with show only capability', () => {
|
|||
]);
|
||||
loadAllActions.mockResolvedValue([]);
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
useKibanaMock().services.alertTypeRegistry = alertTypeRegistry;
|
||||
useKibanaMock().services.ruleTypeRegistry = ruleTypeRegistry;
|
||||
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
useKibanaMock().services.actionTypeRegistry = actionTypeRegistry;
|
||||
|
@ -522,9 +522,9 @@ describe('alerts_list with show only capability', () => {
|
|||
loadAlertTypes.mockResolvedValue([alertTypeFromApi]);
|
||||
loadAllActions.mockResolvedValue([]);
|
||||
|
||||
alertTypeRegistry.has.mockReturnValue(false);
|
||||
ruleTypeRegistry.has.mockReturnValue(false);
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
useKibanaMock().services.alertTypeRegistry = alertTypeRegistry;
|
||||
useKibanaMock().services.ruleTypeRegistry = ruleTypeRegistry;
|
||||
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
useKibanaMock().services.actionTypeRegistry = actionTypeRegistry;
|
||||
|
@ -629,9 +629,9 @@ describe('alerts_list with disabled itmes', () => {
|
|||
]);
|
||||
loadAllActions.mockResolvedValue([]);
|
||||
|
||||
alertTypeRegistry.has.mockReturnValue(false);
|
||||
ruleTypeRegistry.has.mockReturnValue(false);
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
useKibanaMock().services.alertTypeRegistry = alertTypeRegistry;
|
||||
useKibanaMock().services.ruleTypeRegistry = ruleTypeRegistry;
|
||||
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
useKibanaMock().services.actionTypeRegistry = actionTypeRegistry;
|
||||
|
|
|
@ -89,7 +89,7 @@ export const AlertsList: React.FunctionComponent = () => {
|
|||
http,
|
||||
notifications: { toasts },
|
||||
application: { capabilities },
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
actionTypeRegistry,
|
||||
kibanaFeatures,
|
||||
} = useKibana().services;
|
||||
|
@ -889,7 +889,7 @@ export const AlertsList: React.FunctionComponent = () => {
|
|||
setAlertFlyoutVisibility(false);
|
||||
}}
|
||||
actionTypeRegistry={actionTypeRegistry}
|
||||
alertTypeRegistry={alertTypeRegistry}
|
||||
ruleTypeRegistry={ruleTypeRegistry}
|
||||
onSave={loadAlertsData}
|
||||
/>
|
||||
)}
|
||||
|
@ -900,7 +900,7 @@ export const AlertsList: React.FunctionComponent = () => {
|
|||
setEditFlyoutVisibility(false);
|
||||
}}
|
||||
actionTypeRegistry={actionTypeRegistry}
|
||||
alertTypeRegistry={alertTypeRegistry}
|
||||
ruleTypeRegistry={ruleTypeRegistry}
|
||||
onSave={loadAlertsData}
|
||||
/>
|
||||
)}
|
||||
|
|
|
@ -57,16 +57,16 @@ beforeEach(() => jest.resetAllMocks());
|
|||
|
||||
describe('register()', () => {
|
||||
test('able to register alert types', () => {
|
||||
const alertTypeRegistry = new TypeRegistry<AlertTypeModel>();
|
||||
alertTypeRegistry.register(getTestAlertType());
|
||||
expect(alertTypeRegistry.has('test-alet-type')).toEqual(true);
|
||||
const ruleTypeRegistry = new TypeRegistry<AlertTypeModel>();
|
||||
ruleTypeRegistry.register(getTestAlertType());
|
||||
expect(ruleTypeRegistry.has('test-alet-type')).toEqual(true);
|
||||
});
|
||||
|
||||
test('throws error if alert type already registered', () => {
|
||||
const alertTypeRegistry = new TypeRegistry<AlertTypeModel>();
|
||||
alertTypeRegistry.register(getTestAlertType('my-test-alert-type-1'));
|
||||
const ruleTypeRegistry = new TypeRegistry<AlertTypeModel>();
|
||||
ruleTypeRegistry.register(getTestAlertType('my-test-alert-type-1'));
|
||||
expect(() =>
|
||||
alertTypeRegistry.register(getTestAlertType('my-test-alert-type-1'))
|
||||
ruleTypeRegistry.register(getTestAlertType('my-test-alert-type-1'))
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Object type \\"my-test-alert-type-1\\" is already registered."`
|
||||
);
|
||||
|
@ -128,13 +128,13 @@ describe('list()', () => {
|
|||
|
||||
describe('has()', () => {
|
||||
test('returns false for unregistered alert types', () => {
|
||||
const alertTypeRegistry = new TypeRegistry<AlertTypeModel>();
|
||||
expect(alertTypeRegistry.has('my-alert-type')).toEqual(false);
|
||||
const ruleTypeRegistry = new TypeRegistry<AlertTypeModel>();
|
||||
expect(ruleTypeRegistry.has('my-alert-type')).toEqual(false);
|
||||
});
|
||||
|
||||
test('returns true after registering an alert type', () => {
|
||||
const alertTypeRegistry = new TypeRegistry<AlertTypeModel>();
|
||||
alertTypeRegistry.register(getTestAlertType());
|
||||
expect(alertTypeRegistry.has('test-alet-type'));
|
||||
const ruleTypeRegistry = new TypeRegistry<AlertTypeModel>();
|
||||
ruleTypeRegistry.register(getTestAlertType());
|
||||
expect(ruleTypeRegistry.has('test-alet-type'));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -12,18 +12,18 @@ import { dataPluginMock } from '../../../../../../../src/plugins/data/public/moc
|
|||
import { coreMock, scopedHistoryMock } from '../../../../../../../src/core/public/mocks';
|
||||
import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public';
|
||||
import { TriggersAndActionsUiServices } from '../../../application/app';
|
||||
import { AlertTypeRegistryContract, ActionTypeRegistryContract } from '../../../types';
|
||||
import { RuleTypeRegistryContract, ActionTypeRegistryContract } from '../../../types';
|
||||
|
||||
export const createStartServicesMock = (): TriggersAndActionsUiServices => {
|
||||
const core = coreMock.createStart();
|
||||
return {
|
||||
...core,
|
||||
alertTypeRegistry: {
|
||||
ruleTypeRegistry: {
|
||||
has: jest.fn(),
|
||||
register: jest.fn(),
|
||||
get: jest.fn(),
|
||||
list: jest.fn(),
|
||||
} as AlertTypeRegistryContract,
|
||||
} as RuleTypeRegistryContract,
|
||||
dataPlugin: jest.fn(),
|
||||
navigateToApp: jest.fn(),
|
||||
alerting: {
|
||||
|
|
|
@ -13,7 +13,7 @@ export type {
|
|||
AlertTypeModel,
|
||||
ActionType,
|
||||
ActionTypeRegistryContract,
|
||||
AlertTypeRegistryContract,
|
||||
RuleTypeRegistryContract,
|
||||
AlertTypeParamsExpressionProps,
|
||||
ValidationResult,
|
||||
ActionVariables,
|
||||
|
|
|
@ -24,10 +24,10 @@ import {
|
|||
|
||||
function createStartMock(): TriggersAndActionsUIPublicPluginStart {
|
||||
const actionTypeRegistry = new TypeRegistry<ActionTypeModel>();
|
||||
const alertTypeRegistry = new TypeRegistry<AlertTypeModel>();
|
||||
const ruleTypeRegistry = new TypeRegistry<AlertTypeModel>();
|
||||
return {
|
||||
actionTypeRegistry,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
getAddConnectorFlyout: (props: Omit<ConnectorAddFlyoutProps, 'actionTypeRegistry'>) => {
|
||||
return getAddConnectorFlyoutLazy({ ...props, actionTypeRegistry });
|
||||
},
|
||||
|
@ -37,20 +37,20 @@ function createStartMock(): TriggersAndActionsUIPublicPluginStart {
|
|||
actionTypeRegistry,
|
||||
});
|
||||
},
|
||||
getAddAlertFlyout: (props: Omit<AlertAddProps, 'actionTypeRegistry' | 'alertTypeRegistry'>) => {
|
||||
getAddAlertFlyout: (props: Omit<AlertAddProps, 'actionTypeRegistry' | 'ruleTypeRegistry'>) => {
|
||||
return getAddAlertFlyoutLazy({
|
||||
...props,
|
||||
actionTypeRegistry,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
});
|
||||
},
|
||||
getEditAlertFlyout: (
|
||||
props: Omit<AlertEditProps, 'actionTypeRegistry' | 'alertTypeRegistry'>
|
||||
props: Omit<AlertEditProps, 'actionTypeRegistry' | 'ruleTypeRegistry'>
|
||||
) => {
|
||||
return getEditAlertFlyoutLazy({
|
||||
...props,
|
||||
actionTypeRegistry,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
|
@ -43,12 +43,12 @@ import type {
|
|||
|
||||
export interface TriggersAndActionsUIPublicPluginSetup {
|
||||
actionTypeRegistry: TypeRegistry<ActionTypeModel>;
|
||||
alertTypeRegistry: TypeRegistry<AlertTypeModel<any>>;
|
||||
ruleTypeRegistry: TypeRegistry<AlertTypeModel<any>>;
|
||||
}
|
||||
|
||||
export interface TriggersAndActionsUIPublicPluginStart {
|
||||
actionTypeRegistry: TypeRegistry<ActionTypeModel>;
|
||||
alertTypeRegistry: TypeRegistry<AlertTypeModel<any>>;
|
||||
ruleTypeRegistry: TypeRegistry<AlertTypeModel<any>>;
|
||||
getAddConnectorFlyout: (
|
||||
props: Omit<ConnectorAddFlyoutProps, 'actionTypeRegistry'>
|
||||
) => ReactElement<ConnectorAddFlyoutProps>;
|
||||
|
@ -56,10 +56,10 @@ export interface TriggersAndActionsUIPublicPluginStart {
|
|||
props: Omit<ConnectorEditFlyoutProps, 'actionTypeRegistry'>
|
||||
) => ReactElement<ConnectorEditFlyoutProps>;
|
||||
getAddAlertFlyout: (
|
||||
props: Omit<AlertAddProps, 'actionTypeRegistry' | 'alertTypeRegistry'>
|
||||
props: Omit<AlertAddProps, 'actionTypeRegistry' | 'ruleTypeRegistry'>
|
||||
) => ReactElement<AlertAddProps>;
|
||||
getEditAlertFlyout: (
|
||||
props: Omit<AlertEditProps, 'actionTypeRegistry' | 'alertTypeRegistry'>
|
||||
props: Omit<AlertEditProps, 'actionTypeRegistry' | 'ruleTypeRegistry'>
|
||||
) => ReactElement<AlertEditProps>;
|
||||
}
|
||||
|
||||
|
@ -86,16 +86,16 @@ export class Plugin
|
|||
PluginsStart
|
||||
> {
|
||||
private actionTypeRegistry: TypeRegistry<ActionTypeModel>;
|
||||
private alertTypeRegistry: TypeRegistry<AlertTypeModel>;
|
||||
private ruleTypeRegistry: TypeRegistry<AlertTypeModel>;
|
||||
|
||||
constructor() {
|
||||
this.actionTypeRegistry = new TypeRegistry<ActionTypeModel>();
|
||||
this.alertTypeRegistry = new TypeRegistry<AlertTypeModel>();
|
||||
this.ruleTypeRegistry = new TypeRegistry<AlertTypeModel>();
|
||||
}
|
||||
|
||||
public setup(core: CoreSetup, plugins: PluginsSetup): TriggersAndActionsUIPublicPluginSetup {
|
||||
const actionTypeRegistry = this.actionTypeRegistry;
|
||||
const alertTypeRegistry = this.alertTypeRegistry;
|
||||
const ruleTypeRegistry = this.ruleTypeRegistry;
|
||||
|
||||
const featureTitle = i18n.translate('xpack.triggersActionsUI.managementSection.displayName', {
|
||||
defaultMessage: 'Rules and Connectors',
|
||||
|
@ -153,7 +153,7 @@ export class Plugin
|
|||
setBreadcrumbs: params.setBreadcrumbs,
|
||||
history: params.history,
|
||||
actionTypeRegistry,
|
||||
alertTypeRegistry,
|
||||
ruleTypeRegistry,
|
||||
kibanaFeatures,
|
||||
});
|
||||
},
|
||||
|
@ -165,14 +165,14 @@ export class Plugin
|
|||
|
||||
return {
|
||||
actionTypeRegistry: this.actionTypeRegistry,
|
||||
alertTypeRegistry: this.alertTypeRegistry,
|
||||
ruleTypeRegistry: this.ruleTypeRegistry,
|
||||
};
|
||||
}
|
||||
|
||||
public start(): TriggersAndActionsUIPublicPluginStart {
|
||||
return {
|
||||
actionTypeRegistry: this.actionTypeRegistry,
|
||||
alertTypeRegistry: this.alertTypeRegistry,
|
||||
ruleTypeRegistry: this.ruleTypeRegistry,
|
||||
getAddConnectorFlyout: (props: Omit<ConnectorAddFlyoutProps, 'actionTypeRegistry'>) => {
|
||||
return getAddConnectorFlyoutLazy({ ...props, actionTypeRegistry: this.actionTypeRegistry });
|
||||
},
|
||||
|
@ -183,21 +183,21 @@ export class Plugin
|
|||
});
|
||||
},
|
||||
getAddAlertFlyout: (
|
||||
props: Omit<AlertAddProps, 'actionTypeRegistry' | 'alertTypeRegistry'>
|
||||
props: Omit<AlertAddProps, 'actionTypeRegistry' | 'ruleTypeRegistry'>
|
||||
) => {
|
||||
return getAddAlertFlyoutLazy({
|
||||
...props,
|
||||
actionTypeRegistry: this.actionTypeRegistry,
|
||||
alertTypeRegistry: this.alertTypeRegistry,
|
||||
ruleTypeRegistry: this.ruleTypeRegistry,
|
||||
});
|
||||
},
|
||||
getEditAlertFlyout: (
|
||||
props: Omit<AlertEditProps, 'actionTypeRegistry' | 'alertTypeRegistry'>
|
||||
props: Omit<AlertEditProps, 'actionTypeRegistry' | 'ruleTypeRegistry'>
|
||||
) => {
|
||||
return getEditAlertFlyoutLazy({
|
||||
...props,
|
||||
actionTypeRegistry: this.actionTypeRegistry,
|
||||
alertTypeRegistry: this.alertTypeRegistry,
|
||||
ruleTypeRegistry: this.ruleTypeRegistry,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
|
@ -66,7 +66,7 @@ export type ActionTypeRegistryContract<
|
|||
ActionConnector = unknown,
|
||||
ActionParams = unknown
|
||||
> = PublicMethodsOf<TypeRegistry<ActionTypeModel<ActionConnector, ActionParams>>>;
|
||||
export type AlertTypeRegistryContract = PublicMethodsOf<TypeRegistry<AlertTypeModel>>;
|
||||
export type RuleTypeRegistryContract = PublicMethodsOf<TypeRegistry<AlertTypeModel>>;
|
||||
|
||||
export interface ActionConnectorFieldsProps<TActionConnector> {
|
||||
action: TActionConnector;
|
||||
|
@ -273,7 +273,7 @@ export interface ConnectorEditFlyoutProps {
|
|||
|
||||
export interface AlertEditProps<MetaData = Record<string, any>> {
|
||||
initialAlert: Alert;
|
||||
alertTypeRegistry: AlertTypeRegistryContract;
|
||||
ruleTypeRegistry: RuleTypeRegistryContract;
|
||||
actionTypeRegistry: ActionTypeRegistryContract;
|
||||
onClose: (reason: AlertFlyoutCloseReason) => void;
|
||||
/** @deprecated use `onSave` as a callback after an alert is saved*/
|
||||
|
@ -284,7 +284,7 @@ export interface AlertEditProps<MetaData = Record<string, any>> {
|
|||
|
||||
export interface AlertAddProps<MetaData = Record<string, any>> {
|
||||
consumer: string;
|
||||
alertTypeRegistry: AlertTypeRegistryContract;
|
||||
ruleTypeRegistry: RuleTypeRegistryContract;
|
||||
actionTypeRegistry: ActionTypeRegistryContract;
|
||||
onClose: (reason: AlertFlyoutCloseReason) => void;
|
||||
alertTypeId?: string;
|
||||
|
|
|
@ -150,7 +150,7 @@ export class UptimePlugin
|
|||
});
|
||||
if (
|
||||
clientPluginsStart.triggersActionsUi &&
|
||||
!clientPluginsStart.triggersActionsUi.alertTypeRegistry.has(alertInitializer.id)
|
||||
!clientPluginsStart.triggersActionsUi.ruleTypeRegistry.has(alertInitializer.id)
|
||||
) {
|
||||
observabilityRuleTypeRegistry.register(alertInitializer);
|
||||
}
|
||||
|
@ -163,9 +163,9 @@ export class UptimePlugin
|
|||
});
|
||||
if (
|
||||
clientPluginsStart.triggersActionsUi &&
|
||||
!clientPluginsStart.triggersActionsUi.alertTypeRegistry.has(alertInitializer.id)
|
||||
!clientPluginsStart.triggersActionsUi.ruleTypeRegistry.has(alertInitializer.id)
|
||||
) {
|
||||
plugins.triggersActionsUi.alertTypeRegistry.register(alertInitializer);
|
||||
plugins.triggersActionsUi.ruleTypeRegistry.register(alertInitializer);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -418,7 +418,7 @@ export default function createAlertTests({ getService }: FtrProviderContext) {
|
|||
expect(response.body).to.eql({
|
||||
statusCode: 400,
|
||||
error: 'Bad Request',
|
||||
message: 'Alert type "test.unregistered-alert-type" is not registered.',
|
||||
message: 'Rule type "test.unregistered-alert-type" is not registered.',
|
||||
});
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -27,7 +27,7 @@ export class AlertingFixturePlugin implements Plugin<Setup, Start, AlertingExamp
|
|||
(alert: SanitizedAlert) => `/rule/${alert.id}`
|
||||
);
|
||||
|
||||
triggersActionsUi.alertTypeRegistry.register({
|
||||
triggersActionsUi.ruleTypeRegistry.register({
|
||||
id: 'test.always-firing',
|
||||
description: 'Always fires',
|
||||
iconClass: 'alert',
|
||||
|
@ -39,7 +39,7 @@ export class AlertingFixturePlugin implements Plugin<Setup, Start, AlertingExamp
|
|||
requiresAppContext: false,
|
||||
});
|
||||
|
||||
triggersActionsUi.alertTypeRegistry.register({
|
||||
triggersActionsUi.ruleTypeRegistry.register({
|
||||
id: 'test.noop',
|
||||
description: `Doesn't do anything`,
|
||||
iconClass: 'alert',
|
||||
|
|
Loading…
Reference in a new issue