Skip to content

Commit

Permalink
Remove reference from security/types to input
Browse files Browse the repository at this point in the history
  • Loading branch information
Yevhen Zavhorodnii committed Jun 6, 2024
1 parent 50a6288 commit 9d66151
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 13 deletions.
30 changes: 25 additions & 5 deletions pkg/model/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func ParseModel(config *common.Config, modelInput *input.Model, builtinRiskRules
parsedModel := types.Model{
ThreagileVersion: modelInput.ThreagileVersion,
Title: modelInput.Title,
Author: modelInput.Author,
Contributors: modelInput.Contributors,
Author: convertAuthor(modelInput.Author),
Contributors: convertAuthors(modelInput.Contributors),
Date: types.Date{Time: reportDate},
AppDescription: removePathElementsFromImageFiles(modelInput.AppDescription),
BusinessOverview: removePathElementsFromImageFiles(modelInput.BusinessOverview),
Expand Down Expand Up @@ -732,6 +732,22 @@ func ParseModel(config *common.Config, modelInput *input.Model, builtinRiskRules
return &parsedModel, nil
}

func convertAuthor(author input.Author) *types.Author {
return &types.Author{
Name: author.Name,
Contact: author.Contact,
Homepage: author.Homepage,
}
}

func convertAuthors(authors []input.Author) []*types.Author {
result := make([]*types.Author, len(authors))
for i, author := range authors {
result[i] = convertAuthor(author)
}
return result
}

func checkIdSyntax(id string) error {
validIdSyntax := regexp.MustCompile(`^[a-zA-Z0-9\-]+$`)
if !validIdSyntax.MatchString(id) {
Expand Down Expand Up @@ -770,15 +786,19 @@ func createSyntheticId(categoryId string,
}

// in order to prevent Path-Traversal like stuff...
func removePathElementsFromImageFiles(overview input.Overview) input.Overview {
func removePathElementsFromImageFiles(overview input.Overview) *types.Overview {
parsedOverview := &types.Overview{
Description: overview.Description,
Images: make([]map[string]string, len(overview.Images)),
}
for i := range overview.Images {
newValue := make(map[string]string)
for file, desc := range overview.Images[i] {
newValue[filepath.Base(file)] = desc
}
overview.Images[i] = newValue
parsedOverview.Images[i] = newValue
}
return overview
return parsedOverview
}

func withDefault(value string, defaultWhenEmpty string) string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ Copyright © 2023 NAME HERE <EMAIL ADDRESS>
package model

import (
"github.com/threagile/threagile/pkg/common"
"testing"

"github.com/google/uuid"

"github.com/stretchr/testify/assert"
"github.com/threagile/threagile/pkg/common"
"github.com/threagile/threagile/pkg/input"
"github.com/threagile/threagile/pkg/security/types"
)
Expand Down
7 changes: 7 additions & 0 deletions pkg/security/types/author.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package types

type Author struct {
Name string
Contact string
Homepage string
}
12 changes: 5 additions & 7 deletions pkg/security/types/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"slices"
"sort"
"strings"

"github.com/threagile/threagile/pkg/input"
)

// TODO: move model out of types package and
Expand All @@ -22,12 +20,12 @@ type Model struct {
ThreagileVersion string `yaml:"threagile_version,omitempty" json:"threagile_version,omitempty"`
Includes []string `yaml:"includes,omitempty" json:"includes,omitempty"`
Title string `json:"title,omitempty" yaml:"title,omitempty"`
Author input.Author `json:"author,omitempty" yaml:"author,omitempty"`
Contributors []input.Author `yaml:"contributors,omitempty" json:"contributors,omitempty"`
Author *Author `json:"author,omitempty" yaml:"author,omitempty"`
Contributors []*Author `yaml:"contributors,omitempty" json:"contributors,omitempty"`
Date Date `json:"date,omitempty" yaml:"date,omitempty"`
AppDescription input.Overview `yaml:"application_description,omitempty" json:"application_description,omitempty"`
BusinessOverview input.Overview `json:"business_overview,omitempty" yaml:"business_overview,omitempty"`
TechnicalOverview input.Overview `json:"technical_overview,omitempty" yaml:"technical_overview,omitempty"`
AppDescription *Overview `yaml:"application_description,omitempty" json:"application_description,omitempty"`
BusinessOverview *Overview `json:"business_overview,omitempty" yaml:"business_overview,omitempty"`
TechnicalOverview *Overview `json:"technical_overview,omitempty" yaml:"technical_overview,omitempty"`
BusinessCriticality Criticality `json:"business_criticality,omitempty" yaml:"business_criticality,omitempty"`
ManagementSummaryComment string `json:"management_summary_comment,omitempty" yaml:"management_summary_comment,omitempty"`
SecurityRequirements map[string]string `json:"security_requirements,omitempty" yaml:"security_requirements,omitempty"`
Expand Down
6 changes: 6 additions & 0 deletions pkg/security/types/overview.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package types

type Overview struct {
Description string
Images []map[string]string // yes, array of map here, as array keeps the order of the image keys
}

0 comments on commit 9d66151

Please sign in to comment.