diff --git a/pkg/script/common/scope.go b/pkg/script/common/scope.go index 01c2e63e..88bcb64f 100644 --- a/pkg/script/common/scope.go +++ b/pkg/script/common/scope.go @@ -3,6 +3,7 @@ package common import ( "encoding/json" "github.com/threagile/threagile/pkg/security/types" + "gopkg.in/yaml.v3" "strings" ) @@ -18,12 +19,12 @@ type Scope struct { func (what *Scope) Init(risk *types.RiskCategory, methods map[string]Statement) error { if risk != nil { - data, marshalError := json.Marshal(risk) + data, marshalError := yaml.Marshal(risk) if marshalError != nil { return marshalError } - unmarshalError := json.Unmarshal(data, &what.Risk) + unmarshalError := yaml.Unmarshal(data, &what.Risk) if unmarshalError != nil { return unmarshalError } diff --git a/pkg/script/risk-rule.go b/pkg/script/risk-rule.go index 27167c09..a7981859 100644 --- a/pkg/script/risk-rule.go +++ b/pkg/script/risk-rule.go @@ -13,7 +13,7 @@ type RiskRule struct { risks.RiskRule category types.RiskCategory supportedTags []string - script Script + script *Script } func (what *RiskRule) Init() *RiskRule { @@ -21,18 +21,31 @@ func (what *RiskRule) Init() *RiskRule { } func (what *RiskRule) ParseFromData(text []byte) (*RiskRule, error) { - items := make(map[string]any) - parseError := yaml.Unmarshal(text, &items) - if parseError != nil { - return nil, parseError + categoryError := yaml.Unmarshal(text, &what.category) + if categoryError != nil { + return nil, categoryError } - return what.Parse(items) -} + var rule struct { + Category string `yaml:"category"` + SupportedTags []string `yaml:"supported-tags"` + Script map[string]any `yaml:"script"` + } + + ruleError := yaml.Unmarshal(text, &rule) + if ruleError != nil { + return nil, ruleError + } + + what.supportedTags = rule.SupportedTags + script, scriptError := new(Script).ParseScript(rule.Script) + if scriptError != nil { + return nil, scriptError + } + + what.script = script -func (what *RiskRule) Parse(items map[string]any) (*RiskRule, error) { - // todo - return nil, fmt.Errorf("not implemented") + return what, nil } func (what *RiskRule) Category() *types.RiskCategory {