File tree Expand file tree Collapse file tree 2 files changed +26
-12
lines changed Expand file tree Collapse file tree 2 files changed +26
-12
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package common
3
3
import (
4
4
"encoding/json"
5
5
"github.com/threagile/threagile/pkg/security/types"
6
+ "gopkg.in/yaml.v3"
6
7
"strings"
7
8
)
8
9
@@ -18,12 +19,12 @@ type Scope struct {
18
19
19
20
func (what * Scope ) Init (risk * types.RiskCategory , methods map [string ]Statement ) error {
20
21
if risk != nil {
21
- data , marshalError := json .Marshal (risk )
22
+ data , marshalError := yaml .Marshal (risk )
22
23
if marshalError != nil {
23
24
return marshalError
24
25
}
25
26
26
- unmarshalError := json .Unmarshal (data , & what .Risk )
27
+ unmarshalError := yaml .Unmarshal (data , & what .Risk )
27
28
if unmarshalError != nil {
28
29
return unmarshalError
29
30
}
Original file line number Diff line number Diff line change @@ -13,26 +13,39 @@ type RiskRule struct {
13
13
risks.RiskRule
14
14
category types.RiskCategory
15
15
supportedTags []string
16
- script Script
16
+ script * Script
17
17
}
18
18
19
19
func (what * RiskRule ) Init () * RiskRule {
20
20
return what
21
21
}
22
22
23
23
func (what * RiskRule ) ParseFromData (text []byte ) (* RiskRule , error ) {
24
- items := make (map [string ]any )
25
- parseError := yaml .Unmarshal (text , & items )
26
- if parseError != nil {
27
- return nil , parseError
24
+ categoryError := yaml .Unmarshal (text , & what .category )
25
+ if categoryError != nil {
26
+ return nil , categoryError
28
27
}
29
28
30
- return what .Parse (items )
31
- }
29
+ var rule struct {
30
+ Category string `yaml:"category"`
31
+ SupportedTags []string `yaml:"supported-tags"`
32
+ Script map [string ]any `yaml:"script"`
33
+ }
34
+
35
+ ruleError := yaml .Unmarshal (text , & rule )
36
+ if ruleError != nil {
37
+ return nil , ruleError
38
+ }
39
+
40
+ what .supportedTags = rule .SupportedTags
41
+ script , scriptError := new (Script ).ParseScript (rule .Script )
42
+ if scriptError != nil {
43
+ return nil , scriptError
44
+ }
45
+
46
+ what .script = script
32
47
33
- func (what * RiskRule ) Parse (items map [string ]any ) (* RiskRule , error ) {
34
- // todo
35
- return nil , fmt .Errorf ("not implemented" )
48
+ return what , nil
36
49
}
37
50
38
51
func (what * RiskRule ) Category () * types.RiskCategory {
You can’t perform that action at this time.
0 commit comments