Skip to content

Commit

Permalink
Merge pull request #154 from weslambert/filestream_processedDir
Browse files Browse the repository at this point in the history
Add option to move files to processed directory after submission
  • Loading branch information
phutelmyer authored Feb 26, 2021
2 parents fc642ba + c841715 commit caa55db
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ For the options below, only one response setting may be configured.
* "files.chunk": size of file chunks that will be sent to the frontend server (defaults to 32768b / 32kb)
* "files.patterns": list of glob patterns that determine which files will be sent for scanning (defaults to example glob pattern)
* "files.delete": boolean that determines if files should be deleted after being sent for scanning (defaults to false -- does not delete files)
* "files.processed": directory where files will be moved after being submitted for scanning (defaults to "", and files stay in staging directory)
* "response.log": location where worker scan results are logged to (defaults to /var/log/strelka/strelka.log)
* "response.report": frequency at which the frontend reports the number of files processed (no default)
* "delta": time value that determines how much time must pass since a file was last modified before it is sent for scanning (defaults to 5 seconds)
Expand Down
2 changes: 2 additions & 0 deletions src/go/cmd/strelka-filestream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func main() {
Chunk: conf.Throughput.Chunk,
Delay: conf.Throughput.Delay,
Delete: conf.Files.Delete,
Processed: conf.Files.Processed,
}

sem <- 1
Expand Down Expand Up @@ -197,6 +198,7 @@ func main() {
Chunk: conf.Throughput.Chunk,
Delay: conf.Throughput.Delay,
Delete: conf.Files.Delete,
Processed: conf.Files.Processed,
}

sem <- 1
Expand Down
12 changes: 11 additions & 1 deletion src/go/pkg/rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"runtime"
"time"
"path/filepath"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
Expand Down Expand Up @@ -127,7 +128,16 @@ func ScanFile(client strelka.FrontendClient, timeout time.Duration, req structs.
}
if req.Delete {
defer os.Remove(req.Attributes.Filename)
}
} else if req.Processed != "" {
defer func() {
_, name := filepath.Split(req.Attributes.Filename)
m := filepath.Join(req.Processed, name)
err := os.Rename(req.Attributes.Filename, m)
if err != nil {
log.Printf("failed to move file %s to directory %s: %v", name, req.Processed, err)
}
}()
}
defer file.Close()

scanFile, err := client.ScanFile(ctx, grpc.WaitForReady(true))
Expand Down
2 changes: 2 additions & 0 deletions src/go/pkg/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type ConfFiles struct {
Patterns []string // required
Delete bool // optional
Gatekeeper bool // required
Processed string // optional
}

type ConfCoordinator struct {
Expand Down Expand Up @@ -96,4 +97,5 @@ type ScanFileRequest struct {
Chunk int // required
Delay time.Duration // optional
Delete bool // optional, only use if files must be deleted!
Processed string // optional
}

0 comments on commit caa55db

Please sign in to comment.