Merge "Add rating modules PUT endpoint to v2 API"

This commit is contained in:
Zuul 2024-05-13 11:58:47 +00:00 committed by Gerrit Code Review
commit f3a3a78ca4
5 changed files with 122 additions and 0 deletions

View File

@ -74,3 +74,38 @@ Response Example
.. literalinclude:: ./api_samples/rating/module_get.json
:language: javascript
Update one module
=================
.. rest_method:: PUT /v2/rating/modules/(module_id)
.. rest_parameters:: rating/modules_parameters.yml
- enabled: enabled_opt
- priority: priority_opt
Status codes
------------
.. rest_status_code:: success http_status.yml
- 204
.. rest_status_code:: error http_status.yml
- 400
- 401
- 403
- 404
Response
--------
.. rest_parameters:: rating/modules_parameters.yml
- module_id: module_id
- description: description
- enabled: enabled
- hot_config: hot_config
- priority: priority

View File

@ -82,6 +82,23 @@ class RatingModule(BaseRatingModule):
'priority': infos['priority'],
}
@api_utils.add_input_schema('body', {
voluptuous.Optional('enabled'): voluptuous.Boolean(),
voluptuous.Optional('priority'): voluptuous.All(int, min=1),
})
def put(self, module_id, enabled=None, priority=None):
policy.authorize(flask.request.context, 'v2_rating:update_module', {})
try:
module = self.rating_modules[module_id].obj
except KeyError:
raise http_exceptions.NotFound(
"Module '{}' not found".format(module_id))
if enabled is not None:
module.set_state(enabled)
if priority is not None:
module.set_priority(priority)
return "", 204
class RatingModuleList(BaseRatingModule):

View File

@ -30,6 +30,12 @@ rating_policies = [
description='Get specified module.',
operations=[{'path': '/v2/rating/modules/{module_id}',
'method': 'GET'}]),
policy.DocumentedRuleDefault(
name='v2_rating:update_module',
check_str=base.ROLE_ADMIN,
description='Change the state and priority of a module.',
operations=[{'path': '/v2/rating/modules/{module_id}',
'method': 'PUT'}])
]

View File

@ -40,3 +40,64 @@ tests:
status: 404
response_json_paths:
$.message: "Module 'fakb' not found"
- name: change priority of a module
url: /v2/rating/modules/fake3
method: PUT
request_headers:
content-type: application/json
x-roles: admin
data:
priority: 5
status: 204
- name: get information of the modified module (priority)
url: /v2/rating/modules/fake3
status: 200
response_json_paths:
$.priority: 5
$.module_id: "fake3"
$.enabled: false
$.description: "fake rating module"
$.hot_config: false
- name: change enabled status of a module
url: /v2/rating/modules/fake3
method: PUT
request_headers:
content-type: application/json
x-roles: admin
data:
enabled: true
status: 204
- name: get information of the modified module (status)
url: /v2/rating/modules/fake3
status: 200
response_json_paths:
$.priority: 5
$.module_id: "fake3"
$.enabled: true
$.description: "fake rating module"
$.hot_config: false
- name: change status and priority of a module
url: /v2/rating/modules/fake3
method: PUT
request_headers:
content-type: application/json
x-roles: admin
data:
priority: 3
enabled: false
status: 204
- name: get information of the modified module (both)
url: /v2/rating/modules/fake3
status: 200
response_json_paths:
$.priority: 3
$.module_id: "fake3"
$.enabled: false
$.description: "fake rating module"
$.hot_config: false

View File

@ -125,3 +125,6 @@
# GET /v2/task/reprocesses
#"schedule:get_task_reprocesses": "role:admin"
# Change the state and priority of a module.
# PUT /v2/rating/modules/{module_id}
#"v2_rating:update_module": "role:admin"