Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an error sending payload parameters as arrays on the Dev Tools application #6908

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to the Wazuh app project will be documented in this file.

- Fixed windows-agent-deployment-command from deploy new agent [#6905](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6905)
- Fixed rendering an active response as disabled when is active [#6901](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6901)
- Fixed an error on Dev Tools when using payload properties as arrays [#6908](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6908)

## Wazuh v4.9.0 - OpenSearch Dashboards 2.13.0 - Revision 03

Expand Down
35 changes: 0 additions & 35 deletions plugins/main/server/controllers/wazuh-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,27 +529,6 @@ export class WazuhApiCtrl {
});
}

/**
* Helper method for Dev Tools.
* https://documentation.wazuh.com/current/user-manual/api/reference.html
* Depending on the method and the path some parameters should be an array or not.
* Since we allow the user to write the request using both comma-separated and array as well,
* we need to check if it should be transformed or not.
* @param {*} method The request method
* @param {*} path The Wazuh API path
*/
shouldKeepArrayAsIt(method, path) {
// Methods that we must respect a do not transform them
const isAgentsRestart = method === 'POST' && path === '/agents/restart';
const isActiveResponse =
method === 'PUT' && path.startsWith('/active-response');
const isAddingAgentsToGroup =
method === 'POST' && path.startsWith('/agents/group/');

// Returns true only if one of the above conditions is true
return isAgentsRestart || isActiveResponse || isAddingAgentsToGroup;
}

/**
* This performs a request over Wazuh API and returns its response
* @param {String} method Method: GET, PUT, POST, DELETE
Expand Down Expand Up @@ -671,20 +650,6 @@ export class WazuhApiCtrl {

context.wazuh.logger.debug(`${method} ${path}`);

// Extract keys from parameters
const dataProperties = Object.keys(data);

// Transform arrays into comma-separated string if applicable.
// The reason is that we are accepting arrays for comma-separated
// parameters in the Dev Tools
if (!this.shouldKeepArrayAsIt(method, path)) {
for (const key of dataProperties) {
if (Array.isArray(data[key])) {
data[key] = data[key].join();
}
}
}

const responseToken =
await context.wazuh.api.client.asCurrentUser.request(
method,
Expand Down
Loading