| skipped 1 lines |
2 | 2 | | |
3 | 3 | | import ( |
4 | 4 | | "embed" |
| 5 | + | "fmt" |
5 | 6 | | "io/fs" |
| 7 | + | "os" |
6 | 8 | | "path/filepath" |
7 | 9 | | "strings" |
8 | | - | |
9 | | - | "github.com/zan8in/afrog/pkg/catalog" |
10 | 10 | | ) |
11 | 11 | | |
12 | 12 | | //go:embed afrog-pocs/* |
13 | 13 | | var f embed.FS |
14 | 14 | | |
15 | 15 | | func GetPocs() ([]string, error) { |
16 | | - | c := catalog.New("") |
17 | | - | allTargets := []string{} |
| 16 | + | allPocs := []string{} |
18 | 17 | | err := fs.WalkDir(f, ".", func(path string, d fs.DirEntry, err error) error { |
19 | 18 | | if err != nil { |
20 | 19 | | return err |
| skipped 1 lines |
22 | 21 | | // fmt.Printf("path=%q, isDir=%v\n", path, d.IsDir()) |
23 | 22 | | if !d.IsDir() && strings.HasSuffix(path, ".yaml") || strings.HasSuffix(path, ".yml") { |
24 | 23 | | file := filepath.Base(path) |
25 | | - | absPath, err := c.ResolvePath(filepath.Dir(path), "") |
| 24 | + | absPath, err := resolvePath(filepath.Dir(path)) |
26 | 25 | | if err != nil { |
27 | 26 | | return err |
28 | 27 | | } |
29 | | - | allTargets = append(allTargets, filepath.Join(absPath, file)) |
| 28 | + | allPocs = append(allPocs, filepath.Join(absPath, file)) |
30 | 29 | | } |
31 | 30 | | return nil |
32 | 31 | | }) |
33 | | - | return allTargets, err |
| 32 | + | return allPocs, err |
| 33 | + | } |
| 34 | + | |
| 35 | + | func resolvePath(pocName string) (string, error) { |
| 36 | + | if filepath.IsAbs(pocName) { |
| 37 | + | return pocName, nil |
| 38 | + | } |
| 39 | + | |
| 40 | + | curDirectory, err := os.Getwd() |
| 41 | + | if err != nil { |
| 42 | + | return "", err |
| 43 | + | } |
| 44 | + | |
| 45 | + | pocPath := filepath.Join(curDirectory, "pocs", pocName) |
| 46 | + | if len(pocPath) > 0 { |
| 47 | + | return pocPath, nil |
| 48 | + | } |
| 49 | + | |
| 50 | + | return "", fmt.Errorf("no such path found: %s", pocName) |
34 | 51 | | } |
35 | 52 | | |