-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…96170) # Backport This will backport the following commits from `main` to `8.x`: - [[Response Ops][Rules] Version Unmute All Rule API (#196070)](#196070) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Julian Gernun","email":"17549662+jcger@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-10-14T15:28:57Z","message":"[Response Ops][Rules] Version Unmute All Rule API (#196070)\n\n## Summary\r\n\r\n`POST /api/alerting/rule/{id}/_unmute_all` in\r\nhttps://github.com//issues/195181","sha":"c901fec4f1ea9407265e6f450a5a9390fa31454b","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","v9.0.0","backport:prev-minor","v8.16.0"],"title":"[Response Ops][Rules] Version Unmute All Rule API","number":196070,"url":"https://github.com/elastic/kibana/pull/196070","mergeCommit":{"message":"[Response Ops][Rules] Version Unmute All Rule API (#196070)\n\n## Summary\r\n\r\n`POST /api/alerting/rule/{id}/_unmute_all` in\r\nhttps://github.com//issues/195181","sha":"c901fec4f1ea9407265e6f450a5a9390fa31454b"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/196070","number":196070,"mergeCommit":{"message":"[Response Ops][Rules] Version Unmute All Rule API (#196070)\n\n## Summary\r\n\r\n`POST /api/alerting/rule/{id}/_unmute_all` in\r\nhttps://github.com//issues/195181","sha":"c901fec4f1ea9407265e6f450a5a9390fa31454b"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Julian Gernun <17549662+jcger@users.noreply.github.com>
- Loading branch information
1 parent
26c0e9e
commit fadc976
Showing
17 changed files
with
224 additions
and
33 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
x-pack/plugins/alerting/common/routes/rule/apis/unmute_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 { unmuteAllRuleRequestParamsSchema } from './schemas/latest'; | ||
export type { UnmuteAllRuleRequestParams } from './types/latest'; | ||
|
||
export { unmuteAllRuleRequestParamsSchema as unmuteAllRuleRequestParamsSchemaV1 } from './schemas/v1'; | ||
export type { UnmuteAllRuleRequestParams as UnmuteAllRuleRequestParamsV1 } from './types/v1'; |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/common/routes/rule/apis/unmute_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/unmute_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 unmuteAllRuleRequestParamsSchema = 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/unmute_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/unmute_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 { unmuteAllRuleRequestParamsSchemaV1 } from '..'; | ||
|
||
export type UnmuteAllRuleRequestParams = TypeOf<typeof unmuteAllRuleRequestParamsSchemaV1>; |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/server/application/rule/methods/unmute_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,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 { unmuteAll } from './unmute_all'; |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/server/application/rule/methods/unmute_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 './unmute_all_rule_schemas'; |
12 changes: 12 additions & 0 deletions
12
...ns/alerting/server/application/rule/methods/unmute_all/schemas/unmute_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 unmuteAllRuleParamsSchema = schema.object({ | ||
id: schema.string(), | ||
}); |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/alerting/server/application/rule/methods/unmute_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 './unmute_all_rule_types'; |
11 changes: 11 additions & 0 deletions
11
...lugins/alerting/server/application/rule/methods/unmute_all/types/unmute_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 { unmuteAllRuleParamsSchema } from '../schemas'; | ||
|
||
export type UnmuteAllRuleParams = TypeOf<typeof unmuteAllRuleParamsSchema>; |
76 changes: 76 additions & 0 deletions
76
x-pack/plugins/alerting/server/application/rule/methods/unmute_all/unmute_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,76 @@ | ||
/* | ||
* 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 { unmuteAll } from './unmute_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('validate unmuteAll parameters', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should not throw an error for valid params', () => { | ||
const validParams = { | ||
id: 'ble', | ||
}; | ||
|
||
expect(() => unmuteAll(context, validParams)).not.toThrow(); | ||
expect(savedObjectsMock.get).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should throw Boom.badRequest for invalid params', async () => { | ||
const invalidParams = { | ||
id: 22, | ||
}; | ||
|
||
// @ts-expect-error wrong type for testing purposes | ||
await expect(unmuteAll(context, invalidParams)).rejects.toThrowErrorMatchingInlineSnapshot( | ||
`"Error validating unmute 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
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/routes/rule/apis/unmute_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,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 { unmuteAllRuleRoute } from './unmute_all_rule'; |
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