Skip to content

Commit 7c5275e

Browse files
committed
implemented script processing
1 parent 08e59de commit 7c5275e

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

pkg/script/common/scope.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package common
33
import (
44
"encoding/json"
55
"github.com/threagile/threagile/pkg/security/types"
6+
"gopkg.in/yaml.v3"
67
"strings"
78
)
89

@@ -18,12 +19,12 @@ type Scope struct {
1819

1920
func (what *Scope) Init(risk *types.RiskCategory, methods map[string]Statement) error {
2021
if risk != nil {
21-
data, marshalError := json.Marshal(risk)
22+
data, marshalError := yaml.Marshal(risk)
2223
if marshalError != nil {
2324
return marshalError
2425
}
2526

26-
unmarshalError := json.Unmarshal(data, &what.Risk)
27+
unmarshalError := yaml.Unmarshal(data, &what.Risk)
2728
if unmarshalError != nil {
2829
return unmarshalError
2930
}

pkg/script/risk-rule.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,39 @@ type RiskRule struct {
1313
risks.RiskRule
1414
category types.RiskCategory
1515
supportedTags []string
16-
script Script
16+
script *Script
1717
}
1818

1919
func (what *RiskRule) Init() *RiskRule {
2020
return what
2121
}
2222

2323
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
2827
}
2928

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
3247

33-
func (what *RiskRule) Parse(items map[string]any) (*RiskRule, error) {
34-
// todo
35-
return nil, fmt.Errorf("not implemented")
48+
return what, nil
3649
}
3750

3851
func (what *RiskRule) Category() *types.RiskCategory {

0 commit comments

Comments
 (0)