forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Response Ops][Rules] Version Mute All Rule API (elastic#195572)
## Summary `POST /api/alerting/rule/{id}/_mute_all` in elastic#195181
- Loading branch information
Showing
16 changed files
with
222 additions
and
36 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
x-pack/plugins/alerting/common/routes/rule/apis/mute_all/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export { muteAllRuleRequestParamsSchema } from './schemas/latest'; | ||
export type { MuteAllRuleRequestParams } from './types/latest'; | ||
|
||
export { muteAllRuleRequestParamsSchema as muteAllRuleRequestParamsSchemaV1 } from './schemas/v1'; | ||
export type { MuteAllRuleRequestParams as MuteAllRuleRequestParamsV1 } from './types/v1'; |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/common/routes/rule/apis/mute_all/schemas/latest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export * from './v1'; |
16 changes: 16 additions & 0 deletions
16
x-pack/plugins/alerting/common/routes/rule/apis/mute_all/schemas/v1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { schema } from '@kbn/config-schema'; | ||
|
||
export const muteAllRuleRequestParamsSchema = schema.object({ | ||
id: schema.string({ | ||
meta: { | ||
description: 'The identifier for the rule.', | ||
}, | ||
}), | ||
}); |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/common/routes/rule/apis/mute_all/types/latest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export * from './v1'; |
11 changes: 11 additions & 0 deletions
11
x-pack/plugins/alerting/common/routes/rule/apis/mute_all/types/v1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { TypeOf } from '@kbn/config-schema'; | ||
import { muteAllRuleRequestParamsSchemaV1 } from '..'; | ||
|
||
export type MuteAllRuleRequestParams = TypeOf<typeof muteAllRuleRequestParamsSchemaV1>; |
9 changes: 9 additions & 0 deletions
9
x-pack/plugins/alerting/server/application/rule/methods/mute_all/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export type { MuteAllRuleParams } from './types'; | ||
export { muteAll } from './mute_all'; |
75 changes: 75 additions & 0 deletions
75
x-pack/plugins/alerting/server/application/rule/methods/mute_all/mute_all.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { RulesClientContext } from '../../../../rules_client'; | ||
import { muteAll } from './mute_all'; | ||
import { savedObjectsRepositoryMock } from '@kbn/core-saved-objects-api-server-mocks'; | ||
|
||
jest.mock('../../../../lib/retry_if_conflicts', () => ({ | ||
retryIfConflicts: (_: unknown, id: unknown, asyncFn: () => Promise<unknown>) => { | ||
return asyncFn(); | ||
}, | ||
})); | ||
|
||
jest.mock('../../../../rules_client/lib', () => ({ | ||
updateMetaAttributes: () => {}, | ||
})); | ||
|
||
jest.mock('../../../../saved_objects', () => ({ | ||
partiallyUpdateRule: async () => {}, | ||
})); | ||
|
||
const loggerErrorMock = jest.fn(); | ||
const getBulkMock = jest.fn(); | ||
|
||
const savedObjectsMock = savedObjectsRepositoryMock.create(); | ||
savedObjectsMock.get = jest.fn().mockReturnValue({ | ||
attributes: { | ||
actions: [], | ||
}, | ||
version: '9.0.0', | ||
}); | ||
|
||
const context = { | ||
logger: { error: loggerErrorMock }, | ||
getActionsClient: () => { | ||
return { | ||
getBulk: getBulkMock, | ||
}; | ||
}, | ||
unsecuredSavedObjectsClient: savedObjectsMock, | ||
authorization: { ensureAuthorized: async () => {} }, | ||
ruleTypeRegistry: { | ||
ensureRuleTypeEnabled: () => {}, | ||
}, | ||
getUserName: async () => {}, | ||
} as unknown as RulesClientContext; | ||
|
||
describe('validateMuteAllParams', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should not throw an error for valid params', () => { | ||
const validParams = { | ||
id: 'ble', | ||
}; | ||
|
||
expect(() => muteAll(context, validParams)).not.toThrow(); | ||
expect(savedObjectsMock.get).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should throw Boom.badRequest for invalid params', async () => { | ||
const invalidParams = { | ||
id: 22 as unknown as string, // type workaround to send wrong data validation | ||
}; | ||
|
||
await expect(muteAll(context, invalidParams)).rejects.toThrowErrorMatchingInlineSnapshot( | ||
`"Error validating mute all parameters - [id]: expected value of type [string] but got [number]"` | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/server/application/rule/methods/mute_all/schemas/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export * from './mute_all_rule_schemas'; |
12 changes: 12 additions & 0 deletions
12
...lugins/alerting/server/application/rule/methods/mute_all/schemas/mute_all_rule_schemas.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { schema } from '@kbn/config-schema'; | ||
|
||
export const muteAllRuleParamsSchema = schema.object({ | ||
id: schema.string(), | ||
}); |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/server/application/rule/methods/mute_all/types/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export * from './mute_all_rule_types'; |
11 changes: 11 additions & 0 deletions
11
...ck/plugins/alerting/server/application/rule/methods/mute_all/types/mute_all_rule_types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { TypeOf } from '@kbn/config-schema'; | ||
import { muteAllRuleParamsSchema } from '../schemas'; | ||
|
||
export type MuteAllRuleParams = TypeOf<typeof muteAllRuleParamsSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters