Skip to content

Commit

Permalink
Merge pull request #50 from deepfence/issue-49
Browse files Browse the repository at this point in the history
Make es index name configurable
  • Loading branch information
ramanan-ravi authored Apr 6, 2022
2 parents 1f67a40 + b4b0326 commit 4b321b2
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,30 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/Jeffail/tunny"
"github.com/deepfence/SecretScanner/core"
"github.com/deepfence/SecretScanner/output"
"github.com/deepfence/SecretScanner/scan"
"net/http"
"net/url"
"os"
"os/exec"
"reflect"
"strconv"

"github.com/Jeffail/tunny"
"github.com/deepfence/SecretScanner/core"
"github.com/deepfence/SecretScanner/output"
"github.com/deepfence/SecretScanner/scan"
)

const (
secretScanIndexName = "secret-scan"
secretScanLogsIndexName = "secret-scan-logs"
scanStatusComplete = "COMPLETE"
scanStatusError = "ERROR"
defaultScanConcurrency = 5
scanStatusComplete = "COMPLETE"
scanStatusError = "ERROR"
defaultScanConcurrency = 5
)

var (
scanConcurrency int
httpScanWorkerPool *tunny.Pool
scanConcurrency int
httpScanWorkerPool *tunny.Pool
secretScanIndexName = "secret-scan"
secretScanLogsIndexName = "secret-scan-logs"
)

type imageParameters struct {
Expand All @@ -43,6 +44,12 @@ func init() {
scanConcurrency = defaultScanConcurrency
}
httpScanWorkerPool = tunny.NewFunc(scanConcurrency, processImageWrapper)

customerUniqueId := os.Getenv("CUSTOMER_UNIQUE_ID")
if customerUniqueId != "" {
secretScanIndexName += fmt.Sprintf("-%s", customerUniqueId)
secretScanLogsIndexName += fmt.Sprintf("-%s", customerUniqueId)
}
}

func runSecretScan(writer http.ResponseWriter, request *http.Request) {
Expand All @@ -66,7 +73,7 @@ func processScans(form url.Values) {
}
}

func processImageWrapper(imageParamsInterface interface{}) interface {} {
func processImageWrapper(imageParamsInterface interface{}) interface{} {
imageParams, ok := imageParamsInterface.(imageParameters)
if !ok {
fmt.Println("Error reading input from API")
Expand All @@ -76,16 +83,16 @@ func processImageWrapper(imageParamsInterface interface{}) interface {} {
return nil
}

func processImage(imageName string, scanId string, form url.Values) {
tempFolder, err := core.GetTmpDir(imageName)
func processImage(imageName string, scanId string, form url.Values) {
tempFolder, err := core.GetTmpDir(imageName)
if err != nil {
fmt.Println("error creating temp dirs:" + err.Error())
return
}
imageSaveCommand := exec.Command("python3", "/home/deepfence/usr/registry_image_save.py", "--image_name_with_tag", imageName, "--registry_type", form.Get("registry_type"),
"--mgmt_console_url", output.MgmtConsoleUrl, "--deepfence_key", output.DeepfenceKey, "--credential_id", form.Get("credential_id"),
"--output_folder", tempFolder)
_, err = runCommand(imageSaveCommand, "Image Save:" + imageName)
_, err = runCommand(imageSaveCommand, "Image Save:"+imageName)
if err != nil {
fmt.Println("error saving image:" + err.Error())
return
Expand Down

0 comments on commit 4b321b2

Please sign in to comment.