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

Fix management of custom rule and decoders files #5734

Merged
merged 6 commits into from
Aug 11, 2023
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 @@ -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