forked from p15670423/monkey
Island: Change `POST` to `PUT` in `api/island/mode`
This commit is contained in:
parent
c56c866263
commit
1b562e723f
|
@ -120,7 +120,7 @@ class MonkeyIslandClient(object):
|
|||
assert False
|
||||
|
||||
def _reset_island_mode(self):
|
||||
if self.requests.post("api/island/mode", data='{"mode": "unset"}').ok:
|
||||
if self.requests.put("api/island/mode", data='{"mode": "unset"}').ok:
|
||||
LOGGER.info("Resseting island mode after the test.")
|
||||
else:
|
||||
LOGGER.error("Failed to reset island mode")
|
||||
|
|
|
@ -82,6 +82,12 @@ class MonkeyIslandRequests(object):
|
|||
self.addr + url, data=data, headers=self.get_jwt_header(), verify=False
|
||||
)
|
||||
|
||||
@_Decorators.refresh_jwt_token
|
||||
def put(self, url, data):
|
||||
return requests.put( # noqa: DUO123
|
||||
self.addr + url, data=data, headers=self.get_jwt_header(), verify=False
|
||||
)
|
||||
|
||||
@_Decorators.refresh_jwt_token
|
||||
def post_json(self, url, json: Dict):
|
||||
return requests.post( # noqa: DUO123
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import json
|
||||
import logging
|
||||
from http import HTTPStatus
|
||||
|
||||
from flask import make_response, request
|
||||
|
||||
|
@ -17,9 +18,8 @@ class IslandMode(AbstractResource):
|
|||
def __init__(self, island_mode_service: IslandModeService):
|
||||
self._island_mode_service = island_mode_service
|
||||
|
||||
# API Spec: Instead of POST, this should be PUT
|
||||
@jwt_required
|
||||
def post(self):
|
||||
def put(self):
|
||||
try:
|
||||
body = json.loads(request.data)
|
||||
mode = IslandModeEnum(body.get("mode"))
|
||||
|
@ -29,13 +29,13 @@ class IslandMode(AbstractResource):
|
|||
# TODO: Do any of these returns need a body and make_response? What happens if we just
|
||||
# return the response code?
|
||||
# API Spec: This should be 204 (NO CONTENT)
|
||||
return make_response({}, 200)
|
||||
return make_response({}, HTTPStatus.NO_CONTENT)
|
||||
except (AttributeError, json.decoder.JSONDecodeError):
|
||||
return make_response({}, 400)
|
||||
return make_response({}, HTTPStatus.BAD_REQUEST)
|
||||
except ValueError:
|
||||
return make_response({}, 422)
|
||||
return make_response({}, HTTPStatus.UNPROCESSABLE_ENTITY)
|
||||
|
||||
@jwt_required
|
||||
def get(self):
|
||||
island_mode = self._island_mode_service.get_mode()
|
||||
return make_response({"mode": island_mode.value}, 200)
|
||||
return make_response({"mode": island_mode.value}, HTTPStatus.OK)
|
||||
|
|
|
@ -12,11 +12,11 @@ export class Response{
|
|||
}
|
||||
|
||||
class IslandHttpClient extends AuthComponent {
|
||||
post(endpoint: string, contents: any): Promise<Response>{
|
||||
put(endpoint: string, contents: any): Promise<Response>{
|
||||
let status = null;
|
||||
return this.authFetch(endpoint,
|
||||
{
|
||||
method: 'POST',
|
||||
method: 'PUT',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify(contents)
|
||||
})
|
||||
|
|
|
@ -74,7 +74,7 @@ const LandingPageComponent = (props: Props) => {
|
|||
}
|
||||
|
||||
function setScenario(scenario: string) {
|
||||
IslandHttpClient.post('/api/island/mode', {'mode': scenario})
|
||||
IslandHttpClient.put('/api/island/mode', {'mode': scenario})
|
||||
.then(() => {
|
||||
props.onStatusChange();
|
||||
});
|
||||
|
|
|
@ -113,7 +113,7 @@ const IslandResetModal = (props: Props) => {
|
|||
}})
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
return auth.authFetch('/api/island/mode', {method: 'POST', body: '{"mode": "unset"}'})
|
||||
return auth.authFetch('/api/island/mode', {method: 'PUT', body: '{"mode": "unset"}'})
|
||||
}})
|
||||
.then(res => {
|
||||
if (res.status !== 200) {
|
||||
|
|
Loading…
Reference in New Issue