-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
73 lines (56 loc) · 2.03 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"encoding/json"
"log"
"os"
"strings"
"github.com/Devang-Solanki/Varunastra/pkg/config"
"github.com/Devang-Solanki/Varunastra/pkg/docker"
"github.com/alecthomas/kong"
)
// handleScan processes the scan command.
func handleScan(cli config.CLI, regexDB []config.RegexDB, excludedPatterns config.ExcludedPatterns) {
if len(os.Args) < 2 {
log.Fatalf("Usage: %s <docker-image>", os.Args[0])
}
scanMap := config.CreateScanMap(cli.Scans)
imageName := cli.Target
// Process each image
output, err := docker.ProcessImage(imageName, scanMap, regexDB, excludedPatterns, cli.All)
if err != nil {
log.Fatalln(err)
}
log.Println("Scanning completed.")
data, _ := json.MarshalIndent(output, "", " ")
config.HandleOutput(data, cli)
}
func main() {
var cli config.CLI
ctx := kong.Parse(&cli,
kong.Name("varunastra"),
kong.Description("Varunastra is a tool designed to detect and assist in mitigating vulnerabilities within Docker images.\n\n- For images hosted on Docker Hub, simply provide the repository name (e.g., `datadog/agent`).\n\n- For images from AWS or GCP, include the full registry URL (e.g., `public.ecr.aws/hashicorp/vault`). \n\nIf no tag is specified in the repository URL, the tool will automatically choose a tag from the available options for scanning. \n\n Note: Domains are resolved via DNS queries, while URLs are extracted using regular expressions without resolution."),
)
// Process scans
scanMap := make(map[string]bool)
defaultScans := []string{"secrets", "vuln", "assets"}
if cli.Scans == "" {
for _, scan := range defaultScans {
scanMap[scan] = true
}
} else {
scanList := strings.Split(cli.Scans, ",")
for _, scan := range defaultScans {
scanMap[scan] = false // Default to false
}
for _, scan := range scanList {
scanMap[scan] = true // Set specified scans to true
}
}
regexDB, excludedPatterns, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
// Process the command based on the context
handleScan(cli, regexDB, excludedPatterns)
ctx.Exit(0)
}