From 47a87e14e6b62f77e74ef1910e591025514469a4 Mon Sep 17 00:00:00 2001 From: vakarisz Date: Fri, 15 Jul 2022 17:18:18 +0300 Subject: [PATCH] Island: Add a patch method for PropagationConfig Patch method is required to change the whole collection with one request. We need to change all configured credentials for configuration use case --- .../cc/resources/propagation_credentials.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/monkey/monkey_island/cc/resources/propagation_credentials.py b/monkey/monkey_island/cc/resources/propagation_credentials.py index c5dfc42fe..9ef22f832 100644 --- a/monkey/monkey_island/cc/resources/propagation_credentials.py +++ b/monkey/monkey_island/cc/resources/propagation_credentials.py @@ -29,7 +29,7 @@ class PropagationCredentials(AbstractResource): return propagation_credentials, HTTPStatus.OK def post(self, collection=None): - credentials = [Credentials.from_json(c) for c in request.json] + credentials = [Credentials.from_mapping(c) for c in request.json] if collection == _configured_collection: self._credentials_repository.save_configured_credentials(credentials) @@ -42,6 +42,15 @@ class PropagationCredentials(AbstractResource): return {}, HTTPStatus.NO_CONTENT + def patch(self, collection=None): + if collection != _configured_collection: + return {}, HTTPStatus.METHOD_NOT_ALLOWED + + credentials = [Credentials.from_mapping(c) for c in request.json] + self._credentials_repository.remove_configured_credentials() + self._credentials_repository.save_configured_credentials(credentials) + return {}, HTTPStatus.NO_CONTENT + def delete(self, collection=None): if collection == _configured_collection: self._credentials_repository.remove_configured_credentials()