From bf745db0fb0e27350f3b6f0396628150fc4180fd Mon Sep 17 00:00:00 2001 From: Hari Krishna Date: Tue, 18 Jun 2024 12:46:21 +0000 Subject: [PATCH] fixing some issues with file removing --- functions/onprem/orborus/orborus.go | 31 ++++++++++++----------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/functions/onprem/orborus/orborus.go b/functions/onprem/orborus/orborus.go index 71c9955d..f1459c00 100755 --- a/functions/onprem/orborus/orborus.go +++ b/functions/onprem/orborus/orborus.go @@ -2040,7 +2040,7 @@ func main() { toBeRemoved.Data = append(toBeRemoved.Data, incRequest) - } else if incRequest.Type == "DISABLE_SIGMA_RULES" { + } else if incRequest.Type == "DISABLE_SIGMA_FOLDER" { err := removeAllFiles() if err != nil { log.Printf("[ERROR] Failed to disable the sigma rules: %s", err) @@ -2426,11 +2426,6 @@ func handlePipeline(incRequest shuffle.ExecutionRequest) error { log.Printf("[ERROR] Failed to create pipeline: %s", err) return err } - err = handleFileCategoryChange() - if err != nil { - log.Printf("[ERROR] Failed to download rules: %s", err) - return err - } } else if incRequest.Type == "PIPELINE_DELETE" { log.Printf("[INFO] Should delete pipeline %#v", identifier) pipelineId, err := searchPipeline(identifier) @@ -2999,7 +2994,7 @@ func extractFile(f *zip.File, destDir string) error { func copyToTenzir(srcPath, destPath string) error { containerName := "tenzir-node" - // Check if the extracted_files directory exists in the container + // Check if the sigma_rules directory exists in the container checkCmd := exec.Command("docker", "exec", containerName, "test", "-d", destPath) if err := checkCmd.Run(); err == nil { rmCmd := exec.Command("docker", "exec", "-u", "root", containerName, "rm", "-rf", destPath) @@ -3022,6 +3017,13 @@ func copyToTenzir(srcPath, destPath string) error { return nil } +func removeAllFiles() error { + containerName := "tenzir-node" + sigmaPath := "/var/lib/tenzir/sigma_rules/*" + + return removePath(containerName, sigmaPath) +} + func removeFile(fileName string) error { containerName := "tenzir-node" srcPath := fmt.Sprintf("/var/lib/tenzir/sigma_rules/%s", fileName) @@ -3034,22 +3036,15 @@ func removeFile(fileName string) error { return removePath(containerName, srcPath) } -func removeAllFiles() error { - containerName := "tenzir-node" - sigmaPath := "/var/lib/tenzir/sigma_rules/*" - - return removePath(containerName, sigmaPath) -} - func removePath(containerName, path string) error { - rmCmd := exec.Command("docker", "exec", "-u", "root", containerName, "rm", "-r", path) - if err := rmCmd.Run(); err != nil { - return fmt.Errorf("error removing path: %v", err) + rmCmd := exec.Command("docker", "exec", "-u", "root", containerName, "rm", "-rf", path) + output, err := rmCmd.CombinedOutput() + if err != nil { + return fmt.Errorf("error removing path: %v, output: %s", err, output) } return nil } - // func savePipelineData(pipelineId, identifier, status string) error { // url := fmt.Sprintf("%s/api/v1/triggers/pipeline/save", baseUrl)