Add rating modules PUT endpoint to v2 API
This introduces the PUT method for rating modules in the v2 API. Work items: * Implement the "/v1/rating/modules" endpoints in the v2 API, including unit tests and documentation Change-Id: I202c1021c11926c40ac1d9f5ca51c026ec3b674b Co-Authored-By: Pedro Henrique Pereira Martins <phpm13@gmail.com> Story: 2006572 Task: 36798
This commit is contained in:
parent
eaadb1427e
commit
a8706fffc4
@ -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
|
||||
|
@ -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):
|
||||
|
||||
|
@ -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'}])
|
||||
]
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user