Skip to content

Commit

Permalink
[8.x] [ResponseOps][Rules] Add OAS schema for handled 4xx errors on r…
Browse files Browse the repository at this point in the history
…ule apis (#192616) (#193454)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ResponseOps][Rules] Add OAS schema for handled 4xx errors on rule
apis (#192616)](#192616)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Zacqary Adam
Xeper","email":"Zacqary@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-09-19T16:52:17Z","message":"[ResponseOps][Rules]
Add OAS schema for handled 4xx errors on rule apis (#192616)\n\n##
Summary\r\n\r\nCloses #188514 \r\n\r\nAdds OAS schemas for the `403
Forbidden` errors that public rule apis\r\ncan return if a license is
invalid, `400 Bad Request` for unregistered\r\nrule types, and `404 Not
Found` for missing saved objects.\r\n\r\n### Checklist\r\n\r\n- [x] Any
text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[x]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n\r\n###
Testing\r\n\r\n1. Start ES\r\n2. Add `server.oas.enabled: true` to
`kibana.dev.yml`\r\n3. Start Kibana `yarn start --no-base-path`\r\n4.
`curl -s
-uelastic:changeme\r\nhttp://localhost:5601/api/oas\\?pathStartsWith\\=/api/alerting/rule/
| jq`\r\n(If you have `jq` installed, otherwise pipe to `pbcopy` and
paste the\r\nresult into a JSON prettifier)\r\n5. Search the output for
the word `Forbidden` to ensure this schema has\r\nbeen added to
`create`, `update`, `enable`, `disable`, `mute`, `unmute`,\r\nand
`update_rule_api_key`\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"18afcae609c9dd142ef158f6f19dd392bc9d6327","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","Feature:Alerting/RulesFramework","v8.16.0","backport:version"],"title":"[ResponseOps][Rules]
Add OAS schema for handled 4xx errors on rule
apis","number":192616,"url":"https://github.com/elastic/kibana/pull/192616","mergeCommit":{"message":"[ResponseOps][Rules]
Add OAS schema for handled 4xx errors on rule apis (#192616)\n\n##
Summary\r\n\r\nCloses #188514 \r\n\r\nAdds OAS schemas for the `403
Forbidden` errors that public rule apis\r\ncan return if a license is
invalid, `400 Bad Request` for unregistered\r\nrule types, and `404 Not
Found` for missing saved objects.\r\n\r\n### Checklist\r\n\r\n- [x] Any
text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[x]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n\r\n###
Testing\r\n\r\n1. Start ES\r\n2. Add `server.oas.enabled: true` to
`kibana.dev.yml`\r\n3. Start Kibana `yarn start --no-base-path`\r\n4.
`curl -s
-uelastic:changeme\r\nhttp://localhost:5601/api/oas\\?pathStartsWith\\=/api/alerting/rule/
| jq`\r\n(If you have `jq` installed, otherwise pipe to `pbcopy` and
paste the\r\nresult into a JSON prettifier)\r\n5. Search the output for
the word `Forbidden` to ensure this schema has\r\nbeen added to
`create`, `update`, `enable`, `disable`, `mute`, `unmute`,\r\nand
`update_rule_api_key`\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"18afcae609c9dd142ef158f6f19dd392bc9d6327"}},"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/192616","number":192616,"mergeCommit":{"message":"[ResponseOps][Rules]
Add OAS schema for handled 4xx errors on rule apis (#192616)\n\n##
Summary\r\n\r\nCloses #188514 \r\n\r\nAdds OAS schemas for the `403
Forbidden` errors that public rule apis\r\ncan return if a license is
invalid, `400 Bad Request` for unregistered\r\nrule types, and `404 Not
Found` for missing saved objects.\r\n\r\n### Checklist\r\n\r\n- [x] Any
text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[x]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n\r\n###
Testing\r\n\r\n1. Start ES\r\n2. Add `server.oas.enabled: true` to
`kibana.dev.yml`\r\n3. Start Kibana `yarn start --no-base-path`\r\n4.
`curl -s
-uelastic:changeme\r\nhttp://localhost:5601/api/oas\\?pathStartsWith\\=/api/alerting/rule/
| jq`\r\n(If you have `jq` installed, otherwise pipe to `pbcopy` and
paste the\r\nresult into a JSON prettifier)\r\n5. Search the output for
the word `Forbidden` to ensure this schema has\r\nbeen added to
`create`, `update`, `enable`, `disable`, `mute`, `unmute`,\r\nand
`update_rule_api_key`\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"18afcae609c9dd142ef158f6f19dd392bc9d6327"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Zacqary Adam Xeper <Zacqary@users.noreply.github.com>
  • Loading branch information
kibanamachine and Zacqary authored Sep 19, 2024
1 parent 04e1921 commit e2edfd5
Show file tree
Hide file tree
Showing 14 changed files with 306 additions and 28 deletions.
93 changes: 93 additions & 0 deletions oas_docs/bundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,15 @@
"responses": {
"204": {
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema or parameters."
},
"403": {
"description": "Indicates that this call is forbidden."
},
"404": {
"description": "Indicates a rule with the given ID does not exist."
}
},
"summary": "Delete a rule",
Expand Down Expand Up @@ -2399,6 +2408,15 @@
}
},
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema or parameters."
},
"403": {
"description": "Indicates that this call is forbidden."
},
"404": {
"description": "Indicates a rule with the given ID does not exist."
}
},
"summary": "Get rule details",
Expand Down Expand Up @@ -3586,6 +3604,15 @@
}
},
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema or parameters."
},
"403": {
"description": "Indicates that this call is forbidden."
},
"409": {
"description": "Indicates that the rule id is already in use."
}
},
"summary": "Create a rule",
Expand Down Expand Up @@ -4756,6 +4783,18 @@
}
},
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema or parameters."
},
"403": {
"description": "Indicates that this call is forbidden."
},
"404": {
"description": "Indicates a rule with the given ID does not exist."
},
"409": {
"description": "Indicates that the rule has already been updated by another user."
}
},
"summary": "Update a rule",
Expand Down Expand Up @@ -4821,6 +4860,15 @@
"responses": {
"204": {
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema."
},
"403": {
"description": "Indicates that this call is forbidden."
},
"404": {
"description": "Indicates a rule with the given ID does not exist."
}
},
"summary": "Disable a rule",
Expand Down Expand Up @@ -4868,6 +4916,15 @@
"responses": {
"204": {
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema or parameters."
},
"403": {
"description": "Indicates that this call is forbidden."
},
"404": {
"description": "Indicates a rule with the given ID does not exist."
}
},
"summary": "Enable a rule",
Expand Down Expand Up @@ -5009,6 +5066,18 @@
"responses": {
"204": {
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema or parameters."
},
"403": {
"description": "Indicates that this call is forbidden."
},
"404": {
"description": "Indicates a rule with the given ID does not exist."
},
"409": {
"description": "Indicates that the rule has already been updated by another user."
}
},
"summary": "Update the API key for a rule",
Expand Down Expand Up @@ -5065,6 +5134,15 @@
"responses": {
"204": {
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema or parameters."
},
"403": {
"description": "Indicates that this call is forbidden."
},
"404": {
"description": "Indicates a rule or alert with the given ID does not exist."
}
},
"summary": "Mute an alert",
Expand Down Expand Up @@ -5121,6 +5199,15 @@
"responses": {
"204": {
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema or parameters."
},
"403": {
"description": "Indicates that this call is forbidden."
},
"404": {
"description": "Indicates a rule or alert with the given ID does not exist."
}
},
"summary": "Unmute an alert",
Expand Down Expand Up @@ -6162,6 +6249,12 @@
}
},
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema or parameters."
},
"403": {
"description": "Indicates that this call is forbidden."
}
},
"summary": "Get information about rules",
Expand Down
93 changes: 93 additions & 0 deletions oas_docs/bundle.serverless.json
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,15 @@
"responses": {
"204": {
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema or parameters."
},
"403": {
"description": "Indicates that this call is forbidden."
},
"404": {
"description": "Indicates a rule with the given ID does not exist."
}
},
"summary": "Delete a rule",
Expand Down Expand Up @@ -2399,6 +2408,15 @@
}
},
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema or parameters."
},
"403": {
"description": "Indicates that this call is forbidden."
},
"404": {
"description": "Indicates a rule with the given ID does not exist."
}
},
"summary": "Get rule details",
Expand Down Expand Up @@ -3586,6 +3604,15 @@
}
},
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema or parameters."
},
"403": {
"description": "Indicates that this call is forbidden."
},
"409": {
"description": "Indicates that the rule id is already in use."
}
},
"summary": "Create a rule",
Expand Down Expand Up @@ -4756,6 +4783,18 @@
}
},
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema or parameters."
},
"403": {
"description": "Indicates that this call is forbidden."
},
"404": {
"description": "Indicates a rule with the given ID does not exist."
},
"409": {
"description": "Indicates that the rule has already been updated by another user."
}
},
"summary": "Update a rule",
Expand Down Expand Up @@ -4821,6 +4860,15 @@
"responses": {
"204": {
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema."
},
"403": {
"description": "Indicates that this call is forbidden."
},
"404": {
"description": "Indicates a rule with the given ID does not exist."
}
},
"summary": "Disable a rule",
Expand Down Expand Up @@ -4868,6 +4916,15 @@
"responses": {
"204": {
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema or parameters."
},
"403": {
"description": "Indicates that this call is forbidden."
},
"404": {
"description": "Indicates a rule with the given ID does not exist."
}
},
"summary": "Enable a rule",
Expand Down Expand Up @@ -5009,6 +5066,18 @@
"responses": {
"204": {
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema or parameters."
},
"403": {
"description": "Indicates that this call is forbidden."
},
"404": {
"description": "Indicates a rule with the given ID does not exist."
},
"409": {
"description": "Indicates that the rule has already been updated by another user."
}
},
"summary": "Update the API key for a rule",
Expand Down Expand Up @@ -5065,6 +5134,15 @@
"responses": {
"204": {
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema or parameters."
},
"403": {
"description": "Indicates that this call is forbidden."
},
"404": {
"description": "Indicates a rule or alert with the given ID does not exist."
}
},
"summary": "Mute an alert",
Expand Down Expand Up @@ -5121,6 +5199,15 @@
"responses": {
"204": {
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema or parameters."
},
"403": {
"description": "Indicates that this call is forbidden."
},
"404": {
"description": "Indicates a rule or alert with the given ID does not exist."
}
},
"summary": "Unmute an alert",
Expand Down Expand Up @@ -6162,6 +6249,12 @@
}
},
"description": "Indicates a successful call."
},
"400": {
"description": "Indicates an invalid schema or parameters."
},
"403": {
"description": "Indicates that this call is forbidden."
}
},
"summary": "Get information about rules",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
*/

import { IRouter } from '@kbn/core/server';
import { verifyAccessAndContext, handleDisabledApiKeysError } from '../../../lib';
import { ILicenseState, RuleTypeDisabledError } from '../../../../lib';
import { AlertingRequestHandlerContext, INTERNAL_BASE_ALERTING_API_PATH } from '../../../../types';
import { handleDisabledApiKeysError, verifyAccessAndContext } from '../../../lib';

import {
bulkDisableRulesRequestBodySchemaV1,
BulkDisableRulesRequestBodyV1,
BulkDisableRulesResponseV1,
} from '../../../../../common/routes/rule/apis/bulk_disable';
import type { RuleParamsV1 } from '../../../../../common/routes/rule/response';
import { transformRuleToRuleResponseV1 } from '../../transforms';
import { Rule } from '../../../../application/rule/types';
import { transformRuleToRuleResponseV1 } from '../../transforms';

export const bulkDisableRulesRoute = ({
router,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
import { IRouter } from '@kbn/core/server';

import { ILicenseState, RuleTypeDisabledError } from '../../../../lib';
import { verifyAccessAndContext, handleDisabledApiKeysError } from '../../../lib';
import { AlertingRequestHandlerContext, INTERNAL_BASE_ALERTING_API_PATH } from '../../../../types';
import { handleDisabledApiKeysError, verifyAccessAndContext } from '../../../lib';

import {
bulkEditRulesRequestBodySchemaV1,
BulkEditRulesRequestBodyV1,
BulkEditRulesResponseV1,
} from '../../../../../common/routes/rule/apis/bulk_edit';
import { Rule } from '../../../../application/rule/types';
import type { RuleParamsV1 } from '../../../../../common/routes/rule/response';
import { Rule } from '../../../../application/rule/types';

import { transformRuleToRuleResponseV1 } from '../../transforms';
import { transformOperationsV1 } from './transforms';
import { validateRequiredGroupInDefaultActionsV1 } from '../../validation';
import { transformOperationsV1 } from './transforms';

interface BuildBulkEditRulesRouteParams {
licenseState: ILicenseState;
Expand Down
Loading

0 comments on commit e2edfd5

Please sign in to comment.