Skip to content

Commit

Permalink
Fix management of custom rule and decoders files (#5734)
Browse files Browse the repository at this point in the history
* fix: added relative_dirname to endpoints to get the rule or decoder file

* fix: update put and delete custom rules and decoders files

* Fix error deleting decoders

* changelog: add entry

---------

Co-authored-by: Federico Rodriguez <federico.rodriguez@wazuh.com>
Co-authored-by: Tostti <nicolas.guevara@wazuh.com>
  • Loading branch information
3 people authored Aug 11, 2023
1 parent ee587da commit 8500a13
Show file tree
Hide file tree
Showing 10 changed files with 315 additions and 196 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Fixed repeated requests in inventory data and configurations of an agent. [#5460](https://github.com/wazuh/wazuh-kibana-app/pull/5460)
- Fixed repeated requests in the group table when adding a group or refreshing the table [#5465](https://github.com/wazuh/wazuh-kibana-app/pull/5465)
- Fixed an error in the request body suggestions of API Console [#5521](https://github.com/wazuh/wazuh-kibana-app/pull/5521)
- Fixed some errors related to relative dirname of rule and decoder files [#5734](https://github.com/wazuh/wazuh-kibana-app/pull/5734)

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ async function uploadFiles(files, resource, overwrite) {
for (let idx in files) {
const { file, content } = files[idx];
try {
await resourcesHandler.updateFile(file, content, overwrite);
await resourcesHandler.updateFile(
file,
content,
overwrite,
`etc/${resource}`, // upload files to `etc/{resource}` directory. Currently is not possible to select the target directory so it is set by default.
);
results.push({
index: idx,
uploaded: true,
Expand All @@ -58,7 +63,7 @@ async function uploadFiles(files, resource, overwrite) {
}
}

const getUpdatePermissionsFiles = (section) => {
const getUpdatePermissionsFiles = section => {
const { permissionResource } = resourceDictionary[section];
return [
{
Expand All @@ -74,32 +79,34 @@ const getUpdatePermissionsFiles = (section) => {

// Add new rule button
export const AddNewFileButton = ({ section, updateAddingFile }) => (
<>{
section !== SECTION_CDBLIST_SECTION &&
<WzButtonPermissions
permissions={getUpdatePermissionsFiles(section)}
buttonType="empty"
iconType="plusInCircle"
onClick={() =>
updateAddingFile({
name: '',
content: '<!-- Modify it at your will. -->',
path: `etc/${section}`,
})
}
>
{`Add new ${section} file`}
</WzButtonPermissions>
}</>
)
<>
{section !== SECTION_CDBLIST_SECTION && (
<WzButtonPermissions
permissions={getUpdatePermissionsFiles(section)}
buttonType='empty'
iconType='plusInCircle'
onClick={() =>
updateAddingFile({
name: '',
content: '<!-- Modify it at your will. -->',
path: `etc/${section}`,
})
}
>
{`Add new ${section} file`}
</WzButtonPermissions>
)}
</>
);

//Add new CDB list button
export const AddNewCdbListButton = (({ section, updateListContent }) => {
return <>
export const AddNewCdbListButton = ({ section, updateListContent }) => {
return (
<>
<WzButtonPermissions
buttonType="empty"
buttonType='empty'
permissions={getUpdatePermissionsFiles(section)}
iconType="plusInCircle"
iconType='plusInCircle'
onClick={() =>
updateListContent({
name: false,
Expand All @@ -110,15 +117,15 @@ export const AddNewCdbListButton = (({ section, updateListContent }) => {
>
{`Add new ${section} file`}
</WzButtonPermissions>
</>
});
</>
);
};

// Manage files
export const ManageFiles = (({ section, showingFiles, ...props }) => {

export const ManageFiles = ({ section, showingFiles, ...props }) => {
/**
* Toggle between files and rules or decoders
*/
* Toggle between files and rules or decoders
*/
const toggleFiles = async () => {
try {
props.toggleShowFiles(!showingFiles);
Expand All @@ -136,21 +143,22 @@ export const ManageFiles = (({ section, showingFiles, ...props }) => {
};
getErrorOrchestrator().handleError(options);
}
}
};
return (
<>
{section !== SECTION_CDBLIST_SECTION &&
{section !== SECTION_CDBLIST_SECTION && (
<WzButtonPermissions
buttonType="empty"
buttonType='empty'
permissions={getUpdatePermissionsFiles(section)}
iconType={showingFiles ? 'apmTrace' : 'folderClosed'}
onClick={async () => await toggleFiles()}
>
{showingFiles ? `Manage ${section}` : `Manage ${section} files`}
</WzButtonPermissions>}
</WzButtonPermissions>
)}
</>
)
});
);
};

const uploadFile = async (files, resource, overwrite) => {
try {
Expand All @@ -161,16 +169,20 @@ const uploadFile = async (files, resource, overwrite) => {
}
};

export const UploadFilesButton = (({ section, showingFiles, onSuccess, ...props }) => {

export const UploadFilesButton = ({
section,
showingFiles,
onSuccess,
...props
}) => {
return (
<UploadFiles
resource={section}
path={`etc/${section}`}
upload={uploadFile}
onSuccess={() => {
onSuccess && onSuccess(true)
}}
/>
)
});
<UploadFiles
resource={section}
path={`etc/${section}`}
upload={uploadFile}
onSuccess={() => {
onSuccess && onSuccess(true);
}}
/>
);
};
Loading

0 comments on commit 8500a13

Please sign in to comment.