Merge pull request #2158 from guardicore/2071-POST-to-PUT

Change POST to PUT in /api/agent-configuration
This commit is contained in:
Mike Salvatore 2022-08-03 13:31:47 -04:00 committed by GitHub
commit efec473b08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 10 deletions

View File

@ -24,7 +24,7 @@ class AgentConfiguration(AbstractResource):
return make_response(configuration_json, 200)
@jwt_required
def post(self):
def put(self):
try:
configuration_object = AgentConfigurationObject.from_mapping(request.json)
self._agent_configuration_repository.store_configuration(configuration_object)

View File

@ -97,7 +97,7 @@ const ConfigImportModal = (props: Props) => {
delete config['advanced'];
authComponent.authFetch(configImportEndpoint,
{
method: 'POST',
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(config)
}
@ -107,7 +107,7 @@ const ConfigImportModal = (props: Props) => {
props.onClose(true);
} else {
setUploadStatus(UploadStatuses.error);
setErrorMessage("Configuration file is corrupt or in an outdated format.");
setErrorMessage("Configuration file is corrupt or in an outdated format");
}
})
}
@ -142,9 +142,20 @@ const ConfigImportModal = (props: Props) => {
setErrorMessage('File is not in a valid json format');
return
}
setConfigEncrypted(importContents['metadata']['encrypted']);
setConfigContents(importContents['configuration']);
setConfigCredentials(importContents['credentials']);
try {
setConfigEncrypted(importContents['metadata']['encrypted']);
setConfigContents(importContents['configuration']);
setConfigCredentials(importContents['credentials']);
} catch (e) {
if (e instanceof TypeError) {
setErrorMessage('Missing required fields; configuration file is most '
+ 'likely from an older version of Infection Monkey.')
}
else {
throw e;
}
}
};
reader.readAsText(event.target.files[0]);
}

View File

@ -276,7 +276,7 @@ class ConfigurePageComponent extends AuthComponent {
return (
this.authFetch(CONFIG_URL,
{
method: 'POST',
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(config)
})

View File

@ -26,7 +26,7 @@ def flask_client(build_flask_client):
def test_agent_configuration_endpoint(flask_client):
resp = flask_client.post(
resp = flask_client.put(
AGENT_CONFIGURATION_URL,
json=AgentConfiguration.to_mapping(AGENT_CONFIGURATION),
follow_redirects=True,
@ -39,12 +39,12 @@ def test_agent_configuration_endpoint(flask_client):
def test_agent_configuration_invalid_config(flask_client):
resp = flask_client.post(AGENT_CONFIGURATION_URL, json={"invalid_config": "invalid_stuff"})
resp = flask_client.put(AGENT_CONFIGURATION_URL, json={"invalid_config": "invalid_stuff"})
assert resp.status_code == 400
def test_agent_configuration_invalid_json(flask_client):
resp = flask_client.post(AGENT_CONFIGURATION_URL, data="InvalidJson!")
resp = flask_client.put(AGENT_CONFIGURATION_URL, data="InvalidJson!")
assert resp.status_code == 400