Skip to content

Commit

Permalink
implemented script processing
Browse files Browse the repository at this point in the history
  • Loading branch information
joreiche committed Apr 12, 2024
1 parent 08e59de commit 7c5275e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
5 changes: 3 additions & 2 deletions pkg/script/common/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package common
import (
"encoding/json"
"github.com/threagile/threagile/pkg/security/types"
"gopkg.in/yaml.v3"
"strings"
)

Expand All @@ -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
}
Expand Down
33 changes: 23 additions & 10 deletions pkg/script/risk-rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,39 @@ type RiskRule struct {
risks.RiskRule
category types.RiskCategory
supportedTags []string
script Script
script *Script
}

func (what *RiskRule) Init() *RiskRule {
return what
}

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 {
Expand Down

0 comments on commit 7c5275e

Please sign in to comment.