Skip to content

Commit cf35e9a

Browse files
committed
add: ai config
1 parent 7da345d commit cf35e9a

4 files changed

Lines changed: 33 additions & 10 deletions

File tree

internal/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/ptaas-tool/base-api/internal/config/ftp"
99
"github.com/ptaas-tool/base-api/internal/config/migration"
1010
"github.com/ptaas-tool/base-api/internal/config/scanner"
11+
"github.com/ptaas-tool/base-api/internal/core/ai"
1112
"github.com/ptaas-tool/base-api/internal/storage/sql"
1213

1314
"github.com/knadh/koanf"
@@ -23,6 +24,7 @@ type Config struct {
2324
Migrate migration.Config `koanf:"migrate"`
2425
Scanner scanner.Config `koanf:"scanner"`
2526
FTP ftp.Config `koanf:"ftp"`
27+
AI ai.Config `koanf:"ai"`
2628
}
2729

2830
func Load(path string) Config {

internal/config/default.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/ptaas-tool/base-api/internal/config/ftp"
66
"github.com/ptaas-tool/base-api/internal/config/migration"
77
"github.com/ptaas-tool/base-api/internal/config/scanner"
8+
"github.com/ptaas-tool/base-api/internal/core/ai"
89
"github.com/ptaas-tool/base-api/internal/storage/sql"
910
)
1011

@@ -34,5 +35,11 @@ func Default() Config {
3435
Secret: "",
3536
Access: "",
3637
},
38+
AI: ai.Config{
39+
Enable: true,
40+
Method: "random",
41+
Limit: 10,
42+
Factor: 7,
43+
},
3744
}
3845
}

internal/core/ai/ai.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,27 @@ package ai
22

33
import "math/rand"
44

5-
type AI struct{}
5+
type AI struct {
6+
Cfg Config
7+
}
68

79
func (a AI) GetAttacks(list, vulnerabilities []string) []string {
810
records := make([]string, 0)
911

10-
// logic goes here (now it's random)
11-
for _, item := range list {
12-
if item == "injection" || item == "payload" {
13-
records = append(records, item)
14-
15-
continue
16-
}
12+
if !a.Cfg.Enable {
13+
return list
14+
}
1715

18-
if rand.Intn(10) > 8 {
19-
records = append(records, item)
16+
switch a.Cfg.Method {
17+
case "svm":
18+
break
19+
case "nbias":
20+
break
21+
default:
22+
for _, item := range list {
23+
if rand.Intn(a.Cfg.Limit) > a.Cfg.Factor {
24+
records = append(records, item)
25+
}
2026
}
2127
}
2228

internal/core/ai/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package ai
2+
3+
type Config struct {
4+
Method string `koanf:"method"`
5+
Factor int `koanf:"factor"`
6+
Limit int `koanf:"limit"`
7+
Enable bool `koanf:"enable"`
8+
}

0 commit comments

Comments
 (0)