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