Skip to content

Commit

Permalink
add flag to skip detonation
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoubfaouzi committed Jun 9, 2024
1 parent 9896536 commit 2378355
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
6 changes: 4 additions & 2 deletions cmd/rescan.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func init() {
"SHA256 of the file to rescan")
reScanCmd.Flags().BoolVarP(&asyncScanFlag, "async", "a", false,
"Scan files in parallel (default=false)")
reScanCmd.Flags().BoolVarP(&skipDetonationFlag, "skipDetonation", "d", false,
"Skip detonation (default=false)")

}

Expand All @@ -41,7 +43,7 @@ func reScanFile(shaList []string, token string, async bool) error {
for _, sha256 := range shaList {
wp.Submit(func() {
log.Printf("rescanning %s", sha256)
err := webapi.Rescan(sha256, token)
err := webapi.Rescan(sha256, token, skipDetonationFlag)
if err != nil {
log.Fatalf("failed to rescan file: %v", sha256)
}
Expand All @@ -57,7 +59,7 @@ func reScanFile(shaList []string, token string, async bool) error {
for _, sha256 := range shaList {

log.Printf("re-scanning %s", sha256)
err := webapi.Rescan(sha256, token)
err := webapi.Rescan(sha256, token, skipDetonationFlag)
if err != nil {
log.Fatalf("failed to rescan file: %v", sha256)
}
Expand Down
7 changes: 5 additions & 2 deletions cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
var filePath string
var forceRescanFlag bool
var asyncScanFlag bool
var skipDetonationFlag bool

func init() {
scanCmd.Flags().StringVarP(&filePath, "path", "p", "",
Expand All @@ -29,6 +30,8 @@ func init() {
"Force rescan the file if it exists (default=false)")
scanCmd.Flags().BoolVarP(&asyncScanFlag, "async", "a", false,
"Scan files in parallel (default=false)")
scanCmd.Flags().BoolVarP(&skipDetonationFlag, "skipDetonation", "d", false,
"Skip detonation (default=false)")
scanCmd.MarkFlagRequired("path")

}
Expand Down Expand Up @@ -84,7 +87,7 @@ func scanFile(filePath, token string, async, forceRescan bool) error {
} else {
// Force rescan the file
if forceRescan {
err = webapi.Rescan(sha256, token)
err = webapi.Rescan(sha256, token, skipDetonationFlag)
if err != nil {
log.Fatalf("failed to rescan file: %v", filename)
}
Expand Down Expand Up @@ -127,7 +130,7 @@ func scanFile(filePath, token string, async, forceRescan bool) error {
} else {
// Force re-scan the file
if forceRescan {
err = webapi.Rescan(sha256, token)
err = webapi.Rescan(sha256, token, skipDetonationFlag)
if err != nil {
log.Fatalf("failed to re-scan file: %v", filename)
}
Expand Down
15 changes: 12 additions & 3 deletions internal/webapi/webapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,19 @@ func Upload(filepath string, authToken string) (string, error) {
return body.String(), nil
}

func Rescan(sha256, authToken string) error {
func Rescan(sha256, authToken string, skipDetonation bool) error {

url := fileURL + sha256 + "/rescan"
request, err := http.NewRequest("POST", url, nil)

requestBody, err := json.Marshal(map[string]bool{
"skip_detonation": skipDetonation,
})
if err != nil {
return err
}

body := bytes.NewBuffer(requestBody)
request, err := http.NewRequest("POST", url, body)
if err != nil {
return err
}
Expand All @@ -152,7 +161,7 @@ func Rescan(sha256, authToken string) error {
}

// Read the response.
body := &bytes.Buffer{}
body = &bytes.Buffer{}
_, err = body.ReadFrom(resp.Body)
if err != nil {
return err
Expand Down

0 comments on commit 2378355

Please sign in to comment.