From 628db8feadebdb2fc3ee99179d32a3320b2e29e8 Mon Sep 17 00:00:00 2001 From: Yevhen Zavhorodnii Date: Mon, 5 Feb 2024 20:35:23 +0000 Subject: [PATCH] Address most of lint comments --- pkg/common/config.go | 33 ----- pkg/input/model.go | 30 +--- pkg/input/shared-runtime.go | 2 +- pkg/macros/add-build-pipeline-macro.go | 52 ++++--- pkg/macros/add-vault-macro.go | 8 +- pkg/macros/macros.go | 5 +- pkg/model/parse.go | 5 +- pkg/report/excel.go | 194 ++++++++++++++----------- pkg/security/types/risks.go | 4 +- pkg/security/types/technical_asset.go | 8 +- 10 files changed, 151 insertions(+), 190 deletions(-) diff --git a/pkg/common/config.go b/pkg/common/config.go index 8fe33471..3f4c535d 100644 --- a/pkg/common/config.go +++ b/pkg/common/config.go @@ -195,135 +195,102 @@ func (c *Config) Merge(config Config, values map[string]any) { switch strings.ToLower(key) { case strings.ToLower("Verbose"): c.Verbose = config.Verbose - break case strings.ToLower("AppFolder"): c.AppFolder = config.AppFolder - break case strings.ToLower("BinFolder"): c.BinFolder = config.BinFolder - break case strings.ToLower("DataFolder"): c.DataFolder = config.DataFolder - break case strings.ToLower("OutputFolder"): c.OutputFolder = config.OutputFolder - break case strings.ToLower("ServerFolder"): c.ServerFolder = config.ServerFolder - break case strings.ToLower("TempFolder"): c.TempFolder = config.TempFolder - break case strings.ToLower("KeyFolder"): c.KeyFolder = config.KeyFolder - break case strings.ToLower("InputFile"): c.InputFile = config.InputFile - break case strings.ToLower("DataFlowDiagramFilenamePNG"): c.DataFlowDiagramFilenamePNG = config.DataFlowDiagramFilenamePNG - break case strings.ToLower("DataAssetDiagramFilenamePNG"): c.DataAssetDiagramFilenamePNG = config.DataAssetDiagramFilenamePNG - break case strings.ToLower("DataFlowDiagramFilenameDOT"): c.DataFlowDiagramFilenameDOT = config.DataFlowDiagramFilenameDOT - break case strings.ToLower("DataAssetDiagramFilenameDOT"): c.DataAssetDiagramFilenameDOT = config.DataAssetDiagramFilenameDOT - break case strings.ToLower("ReportFilename"): c.ReportFilename = config.ReportFilename - break case strings.ToLower("ExcelRisksFilename"): c.ExcelRisksFilename = config.ExcelRisksFilename - break case strings.ToLower("ExcelTagsFilename"): c.ExcelTagsFilename = config.ExcelTagsFilename - break case strings.ToLower("JsonRisksFilename"): c.JsonRisksFilename = config.JsonRisksFilename - break case strings.ToLower("JsonTechnicalAssetsFilename"): c.JsonTechnicalAssetsFilename = config.JsonTechnicalAssetsFilename - break case strings.ToLower("JsonStatsFilename"): c.JsonStatsFilename = config.JsonStatsFilename - break case strings.ToLower("TemplateFilename"): c.TemplateFilename = config.TemplateFilename - break case strings.ToLower("RAAPlugin"): c.RAAPlugin = config.RAAPlugin - break case strings.ToLower("RiskRulesPlugins"): c.RiskRulesPlugins = config.RiskRulesPlugins - break case strings.ToLower("SkipRiskRules"): c.SkipRiskRules = config.SkipRiskRules - break case strings.ToLower("ExecuteModelMacro"): c.ExecuteModelMacro = config.ExecuteModelMacro - break case strings.ToLower("DiagramDPI"): c.DiagramDPI = config.DiagramDPI - break case strings.ToLower("ServerPort"): c.ServerPort = config.ServerPort - break case strings.ToLower("GraphvizDPI"): c.GraphvizDPI = config.GraphvizDPI - break case strings.ToLower("MaxGraphvizDPI"): c.MaxGraphvizDPI = config.MaxGraphvizDPI - break case strings.ToLower("BackupHistoryFilesToKeep"): c.BackupHistoryFilesToKeep = config.BackupHistoryFilesToKeep - break case strings.ToLower("AddModelTitle"): c.AddModelTitle = config.AddModelTitle - break case strings.ToLower("KeepDiagramSourceFiles"): c.KeepDiagramSourceFiles = config.KeepDiagramSourceFiles - break case strings.ToLower("IgnoreOrphanedRiskTracking"): c.IgnoreOrphanedRiskTracking = config.IgnoreOrphanedRiskTracking - break case strings.ToLower("Attractiveness"): c.Attractiveness = config.Attractiveness - break } } } diff --git a/pkg/input/model.go b/pkg/input/model.go index 2d6db1c2..9b7d4782 100644 --- a/pkg/input/model.go +++ b/pkg/input/model.go @@ -6,7 +6,6 @@ package input import ( "fmt" - "github.com/mpvl/unique" "log" "os" "path/filepath" @@ -14,6 +13,8 @@ import ( "sort" "strings" + "github.com/mpvl/unique" + "gopkg.in/yaml.v3" ) @@ -115,167 +116,140 @@ func (model *Model) Merge(dir string, includeFilename string) error { return fmt.Errorf("failed to merge model include %q: %v", includeFile, mergeError) } } - break case strings.ToLower("threagile_version"): model.ThreagileVersion, mergeError = new(Strings).MergeSingleton(model.ThreagileVersion, includedModel.ThreagileVersion) if mergeError != nil { return fmt.Errorf("failed to merge threagile version: %v", mergeError) } - break case strings.ToLower("title"): model.Title, mergeError = new(Strings).MergeSingleton(model.Title, includedModel.Title) if mergeError != nil { return fmt.Errorf("failed to merge title: %v", mergeError) } - break case strings.ToLower("author"): mergeError = model.Author.Merge(includedModel.Author) if mergeError != nil { return fmt.Errorf("failed to merge author: %v", mergeError) } - break case strings.ToLower("contributors"): model.Contributors, mergeError = new(Author).MergeList(append(model.Contributors, includedModel.Author)) if mergeError != nil { return fmt.Errorf("failed to merge contributors: %v", mergeError) } - break case strings.ToLower("date"): model.Date, mergeError = new(Strings).MergeSingleton(model.Date, includedModel.Date) if mergeError != nil { return fmt.Errorf("failed to merge date: %v", mergeError) } - break case strings.ToLower("application_description"): mergeError = model.AppDescription.Merge(includedModel.AppDescription) if mergeError != nil { return fmt.Errorf("failed to merge application description: %v", mergeError) } - break case strings.ToLower("business_overview"): mergeError = model.BusinessOverview.Merge(includedModel.BusinessOverview) if mergeError != nil { return fmt.Errorf("failed to merge business overview: %v", mergeError) } - break case strings.ToLower("technical_overview"): mergeError = model.TechnicalOverview.Merge(includedModel.TechnicalOverview) if mergeError != nil { return fmt.Errorf("failed to merge technical overview: %v", mergeError) } - break case strings.ToLower("business_criticality"): model.BusinessCriticality, mergeError = new(Strings).MergeSingleton(model.BusinessCriticality, includedModel.BusinessCriticality) if mergeError != nil { return fmt.Errorf("failed to merge business criticality: %v", mergeError) } - break case strings.ToLower("management_summary_comment"): model.ManagementSummaryComment = new(Strings).MergeMultiline(model.ManagementSummaryComment, includedModel.ManagementSummaryComment) - break case strings.ToLower("security_requirements"): model.SecurityRequirements, mergeError = new(Strings).MergeMap(model.SecurityRequirements, includedModel.SecurityRequirements) if mergeError != nil { return fmt.Errorf("failed to merge security requirements: %v", mergeError) } - break case strings.ToLower("questions"): model.Questions, mergeError = new(Strings).MergeMap(model.Questions, includedModel.Questions) if mergeError != nil { return fmt.Errorf("failed to merge questions: %v", mergeError) } - break case strings.ToLower("abuse_cases"): model.AbuseCases, mergeError = new(Strings).MergeMap(model.AbuseCases, includedModel.AbuseCases) if mergeError != nil { return fmt.Errorf("failed to merge abuse cases: %v", mergeError) } - break case strings.ToLower("tags_available"): model.TagsAvailable = new(Strings).MergeUniqueSlice(model.TagsAvailable, includedModel.TagsAvailable) - break case strings.ToLower("data_assets"): model.DataAssets, mergeError = new(DataAsset).MergeMap(model.DataAssets, includedModel.DataAssets) if mergeError != nil { return fmt.Errorf("failed to merge data assets: %v", mergeError) } - break case strings.ToLower("technical_assets"): model.TechnicalAssets, mergeError = new(TechnicalAsset).MergeMap(model.TechnicalAssets, includedModel.TechnicalAssets) if mergeError != nil { return fmt.Errorf("failed to merge technical assets: %v", mergeError) } - break case strings.ToLower("trust_boundaries"): model.TrustBoundaries, mergeError = new(TrustBoundary).MergeMap(model.TrustBoundaries, includedModel.TrustBoundaries) if mergeError != nil { return fmt.Errorf("failed to merge trust boundaries: %v", mergeError) } - break case strings.ToLower("shared_runtimes"): model.SharedRuntimes, mergeError = new(SharedRuntime).MergeMap(model.SharedRuntimes, includedModel.SharedRuntimes) if mergeError != nil { return fmt.Errorf("failed to merge shared runtimes: %v", mergeError) } - break case strings.ToLower("individual_risk_categories"): model.IndividualRiskCategories, mergeError = new(IndividualRiskCategory).MergeMap(model.IndividualRiskCategories, includedModel.IndividualRiskCategories) if mergeError != nil { return fmt.Errorf("failed to merge risk categories: %v", mergeError) } - break case strings.ToLower("risk_tracking"): model.RiskTracking, mergeError = new(RiskTracking).MergeMap(model.RiskTracking, includedModel.RiskTracking) if mergeError != nil { return fmt.Errorf("failed to merge risk tracking: %v", mergeError) } - break case "diagram_tweak_nodesep": model.DiagramTweakNodesep = includedModel.DiagramTweakNodesep - break case "diagram_tweak_ranksep": model.DiagramTweakRanksep = includedModel.DiagramTweakRanksep - break case "diagram_tweak_edge_layout": model.DiagramTweakEdgeLayout = includedModel.DiagramTweakEdgeLayout - break case "diagram_tweak_suppress_edge_labels": model.DiagramTweakSuppressEdgeLabels = includedModel.DiagramTweakSuppressEdgeLabels - break case "diagram_tweak_layout_left_to_right": model.DiagramTweakLayoutLeftToRight = includedModel.DiagramTweakLayoutLeftToRight - break case "diagram_tweak_invisible_connections_between_assets": model.DiagramTweakInvisibleConnectionsBetweenAssets = append(model.DiagramTweakInvisibleConnectionsBetweenAssets, includedModel.DiagramTweakInvisibleConnectionsBetweenAssets...) sort.Strings(model.DiagramTweakInvisibleConnectionsBetweenAssets) unique.Strings(&model.DiagramTweakInvisibleConnectionsBetweenAssets) - break case "diagram_tweak_same_rank_assets": model.DiagramTweakSameRankAssets = append(model.DiagramTweakSameRankAssets, includedModel.DiagramTweakSameRankAssets...) diff --git a/pkg/input/shared-runtime.go b/pkg/input/shared-runtime.go index caa43c2e..dcd6bf3c 100644 --- a/pkg/input/shared-runtime.go +++ b/pkg/input/shared-runtime.go @@ -5,7 +5,7 @@ import "fmt" type SharedRuntime struct { ID string `yaml:"id,omitempty" json:"id,omitempty"` Description string `yaml:"description,omitempty" json:"description,omitempty"` - Tags []string `yaml:"tags,omitempty" json:"tag,omitemptys"` + Tags []string `yaml:"tags,omitempty" json:"tag,omitempty"` TechnicalAssetsRunning []string `yaml:"technical_assets_running,omitempty" json:"technical_assets_running,omitempty"` } diff --git a/pkg/macros/add-build-pipeline-macro.go b/pkg/macros/add-build-pipeline-macro.go index d032d344..52cfba01 100644 --- a/pkg/macros/add-build-pipeline-macro.go +++ b/pkg/macros/add-build-pipeline-macro.go @@ -236,13 +236,13 @@ func (m *addBuildPipeline) ApplyAnswer(questionID string, answer ...string) (mes m.macroState[questionID] = answer m.questionsAnswered = append(m.questionsAnswered, questionID) if questionID == "code-inspection-used" { - m.codeInspectionUsed = strings.ToLower(m.macroState["code-inspection-used"][0]) == "yes" + m.codeInspectionUsed = strings.EqualFold(m.macroState["code-inspection-used"][0], "yes") } else if questionID == "container-technology-used" { - m.containerTechUsed = strings.ToLower(m.macroState["container-technology-used"][0]) == "yes" + m.containerTechUsed = strings.EqualFold(m.macroState["container-technology-used"][0], "yes") } else if questionID == "within-trust-boundary" { - m.withinTrustBoundary = strings.ToLower(m.macroState["within-trust-boundary"][0]) == "yes" + m.withinTrustBoundary = strings.EqualFold(m.macroState["within-trust-boundary"][0], "yes") } else if questionID == "selected-trust-boundary" { - m.createNewTrustBoundary = strings.ToLower(m.macroState["selected-trust-boundary"][0]) == strings.ToLower(createNewTrustBoundaryLabel) + m.createNewTrustBoundary = strings.EqualFold(m.macroState["selected-trust-boundary"][0], createNewTrustBoundaryLabel) } return "Answer processed", true, nil } @@ -346,7 +346,7 @@ func (m *addBuildPipeline) applyChange(modelInput *input.Model, parsedModel *typ if _, exists := parsedModel.TechnicalAssets[id]; !exists { //fmt.Println("Adding technical asset:", id) // ################################################ encryption := types.NoneEncryption.String() - if strings.ToLower(m.macroState["encryption"][0]) == "yes" { + if strings.EqualFold(m.macroState["encryption"][0], "yes") { encryption = types.Transparent.String() } @@ -463,7 +463,7 @@ func (m *addBuildPipeline) applyChange(modelInput *input.Model, parsedModel *typ Size: types.System.String(), Technology: types.DevOpsClient.String(), Tags: []string{}, - Internet: strings.ToLower(m.macroState["internet"][0]) == "yes", + Internet: strings.EqualFold(m.macroState["internet"][0], "yes"), Machine: types.Physical.String(), Encryption: encryption, Owner: owner, @@ -491,7 +491,7 @@ func (m *addBuildPipeline) applyChange(modelInput *input.Model, parsedModel *typ //fmt.Println("Adding technical asset:", id) // ################################################ serverSideTechAssets = append(serverSideTechAssets, id) encryption := types.NoneEncryption.String() - if strings.ToLower(m.macroState["encryption"][0]) == "yes" { + if strings.EqualFold(m.macroState["encryption"][0], "yes") { encryption = types.Transparent.String() } techAsset := input.TechnicalAsset{ @@ -505,7 +505,7 @@ func (m *addBuildPipeline) applyChange(modelInput *input.Model, parsedModel *typ Size: types.Service.String(), Technology: types.SourcecodeRepository.String(), Tags: []string{input.NormalizeTag(m.macroState["source-repository"][0])}, - Internet: strings.ToLower(m.macroState["internet"][0]) == "yes", + Internet: strings.EqualFold(m.macroState["internet"][0], "yes"), Machine: types.Virtual.String(), Encryption: encryption, Owner: owner, @@ -514,7 +514,7 @@ func (m *addBuildPipeline) applyChange(modelInput *input.Model, parsedModel *typ Availability: types.Important.String(), JustificationCiaRating: "Sourcecode processing components are at least rated as 'critical' in terms of integrity, because any " + "malicious modification of it might lead to a backdoored production system.", - MultiTenant: strings.ToLower(m.macroState["multi-tenant"][0]) == "yes", + MultiTenant: strings.EqualFold(m.macroState["multi-tenant"][0], "yes"), Redundant: false, CustomDevelopedParts: false, DataAssetsProcessed: []string{"sourcecode"}, @@ -534,7 +534,7 @@ func (m *addBuildPipeline) applyChange(modelInput *input.Model, parsedModel *typ //fmt.Println("Adding technical asset:", id) // ################################################ serverSideTechAssets = append(serverSideTechAssets, id) encryption := types.NoneEncryption.String() - if strings.ToLower(m.macroState["encryption"][0]) == "yes" { + if strings.EqualFold(m.macroState["encryption"][0], "yes") { encryption = types.Transparent.String() } techAsset := input.TechnicalAsset{ @@ -548,7 +548,7 @@ func (m *addBuildPipeline) applyChange(modelInput *input.Model, parsedModel *typ Size: types.Service.String(), Technology: types.ArtifactRegistry.String(), Tags: []string{input.NormalizeTag(m.macroState["container-registry"][0])}, - Internet: strings.ToLower(m.macroState["internet"][0]) == "yes", + Internet: strings.EqualFold(m.macroState["internet"][0], "yes"), Machine: types.Virtual.String(), Encryption: encryption, Owner: owner, @@ -557,7 +557,7 @@ func (m *addBuildPipeline) applyChange(modelInput *input.Model, parsedModel *typ Availability: types.Important.String(), JustificationCiaRating: "Container registry components are at least rated as 'critical' in terms of integrity, because any " + "malicious modification of it might lead to a backdoored production system.", - MultiTenant: strings.ToLower(m.macroState["multi-tenant"][0]) == "yes", + MultiTenant: strings.EqualFold(m.macroState["multi-tenant"][0], "yes"), Redundant: false, CustomDevelopedParts: false, DataAssetsProcessed: []string{"deployment"}, @@ -576,7 +576,7 @@ func (m *addBuildPipeline) applyChange(modelInput *input.Model, parsedModel *typ //fmt.Println("Adding technical asset:", id) // ################################################ serverSideTechAssets = append(serverSideTechAssets, id) encryption := types.NoneEncryption.String() - if strings.ToLower(m.macroState["encryption"][0]) == "yes" { + if strings.EqualFold(m.macroState["encryption"][0], "yes") { encryption = types.Transparent.String() } techAsset := input.TechnicalAsset{ @@ -590,7 +590,7 @@ func (m *addBuildPipeline) applyChange(modelInput *input.Model, parsedModel *typ Size: types.System.String(), Technology: types.ContainerPlatform.String(), Tags: []string{input.NormalizeTag(m.macroState["container-platform"][0])}, - Internet: strings.ToLower(m.macroState["internet"][0]) == "yes", + Internet: strings.EqualFold(m.macroState["internet"][0], "yes"), Machine: types.Virtual.String(), Encryption: encryption, Owner: owner, @@ -599,7 +599,7 @@ func (m *addBuildPipeline) applyChange(modelInput *input.Model, parsedModel *typ Availability: types.MissionCritical.String(), JustificationCiaRating: "Container platform components are rated as 'mission-critical' in terms of integrity and availability, because any " + "malicious modification of it might lead to a backdoored production system.", - MultiTenant: strings.ToLower(m.macroState["multi-tenant"][0]) == "yes", + MultiTenant: strings.EqualFold(m.macroState["multi-tenant"][0], "yes"), Redundant: false, CustomDevelopedParts: false, DataAssetsProcessed: []string{"deployment"}, @@ -619,7 +619,7 @@ func (m *addBuildPipeline) applyChange(modelInput *input.Model, parsedModel *typ //fmt.Println("Adding technical asset:", id) // ################################################ serverSideTechAssets = append(serverSideTechAssets, id) encryption := types.NoneEncryption.String() - if strings.ToLower(m.macroState["encryption"][0]) == "yes" { + if strings.EqualFold(m.macroState["encryption"][0], "yes") { encryption = types.Transparent.String() } @@ -843,7 +843,7 @@ func (m *addBuildPipeline) applyChange(modelInput *input.Model, parsedModel *typ Size: types.Service.String(), Technology: types.BuildPipeline.String(), Tags: []string{input.NormalizeTag(m.macroState["build-pipeline"][0])}, - Internet: strings.ToLower(m.macroState["internet"][0]) == "yes", + Internet: strings.EqualFold(m.macroState["internet"][0], "yes"), Machine: types.Virtual.String(), Encryption: encryption, Owner: owner, @@ -852,7 +852,7 @@ func (m *addBuildPipeline) applyChange(modelInput *input.Model, parsedModel *typ Availability: types.Important.String(), JustificationCiaRating: "Build pipeline components are at least rated as 'critical' in terms of integrity, because any " + "malicious modification of it might lead to a backdoored production system.", - MultiTenant: strings.ToLower(m.macroState["multi-tenant"][0]) == "yes", + MultiTenant: strings.EqualFold(m.macroState["multi-tenant"][0], "yes"), Redundant: false, CustomDevelopedParts: false, DataAssetsProcessed: []string{"sourcecode", "deployment"}, @@ -871,7 +871,7 @@ func (m *addBuildPipeline) applyChange(modelInput *input.Model, parsedModel *typ //fmt.Println("Adding technical asset:", id) // ################################################ serverSideTechAssets = append(serverSideTechAssets, id) encryption := types.NoneEncryption.String() - if strings.ToLower(m.macroState["encryption"][0]) == "yes" { + if strings.EqualFold(m.macroState["encryption"][0], "yes") { encryption = types.Transparent.String() } techAsset := input.TechnicalAsset{ @@ -885,7 +885,7 @@ func (m *addBuildPipeline) applyChange(modelInput *input.Model, parsedModel *typ Size: types.Service.String(), Technology: types.ArtifactRegistry.String(), Tags: []string{input.NormalizeTag(m.macroState["artifact-registry"][0])}, - Internet: strings.ToLower(m.macroState["internet"][0]) == "yes", + Internet: strings.EqualFold(m.macroState["internet"][0], "yes"), Machine: types.Virtual.String(), Encryption: encryption, Owner: owner, @@ -894,7 +894,7 @@ func (m *addBuildPipeline) applyChange(modelInput *input.Model, parsedModel *typ Availability: types.Important.String(), JustificationCiaRating: "Artifact registry components are at least rated as 'critical' in terms of integrity, because any " + "malicious modification of it might lead to a backdoored production system.", - MultiTenant: strings.ToLower(m.macroState["multi-tenant"][0]) == "yes", + MultiTenant: strings.EqualFold(m.macroState["multi-tenant"][0], "yes"), Redundant: false, CustomDevelopedParts: false, DataAssetsProcessed: []string{"sourcecode", "deployment"}, @@ -914,7 +914,7 @@ func (m *addBuildPipeline) applyChange(modelInput *input.Model, parsedModel *typ //fmt.Println("Adding technical asset:", id) // ################################################ serverSideTechAssets = append(serverSideTechAssets, id) encryption := types.NoneEncryption.String() - if strings.ToLower(m.macroState["encryption"][0]) == "yes" { + if strings.EqualFold(m.macroState["encryption"][0], "yes") { encryption = types.Transparent.String() } techAsset := input.TechnicalAsset{ @@ -928,7 +928,7 @@ func (m *addBuildPipeline) applyChange(modelInput *input.Model, parsedModel *typ Size: types.Service.String(), Technology: types.CodeInspectionPlatform.String(), Tags: []string{input.NormalizeTag(m.macroState["code-inspection-platform"][0])}, - Internet: strings.ToLower(m.macroState["internet"][0]) == "yes", + Internet: strings.EqualFold(m.macroState["internet"][0], "yes"), Machine: types.Virtual.String(), Encryption: encryption, Owner: owner, @@ -937,7 +937,7 @@ func (m *addBuildPipeline) applyChange(modelInput *input.Model, parsedModel *typ Availability: types.Operational.String(), JustificationCiaRating: "Sourcecode inspection platforms are rated at least 'important' in terms of integrity, because any " + "malicious modification of it might lead to vulnerabilities found by the scanner engine not being shown.", - MultiTenant: strings.ToLower(m.macroState["multi-tenant"][0]) == "yes", + MultiTenant: strings.EqualFold(m.macroState["multi-tenant"][0], "yes"), Redundant: false, CustomDevelopedParts: false, DataAssetsProcessed: []string{"sourcecode"}, @@ -1000,9 +1000,7 @@ func (m *addBuildPipeline) applyChange(modelInput *input.Model, parsedModel *typ if m.containerTechUsed { // create shared runtime assetsRunning := make([]string, 0) - for _, deployTargetID := range m.macroState["deploy-targets"] { - assetsRunning = append(assetsRunning, deployTargetID) - } + assetsRunning = append(assetsRunning, m.macroState["deploy-targets"]...) title := m.macroState["container-platform"][0] + " Runtime" sharedRuntime := input.SharedRuntime{ ID: containerSharedRuntimeID, diff --git a/pkg/macros/add-vault-macro.go b/pkg/macros/add-vault-macro.go index f879f620..b672fabb 100644 --- a/pkg/macros/add-vault-macro.go +++ b/pkg/macros/add-vault-macro.go @@ -156,9 +156,9 @@ func (m *addVaultMacro) ApplyAnswer(questionID string, answer ...string) (messag m.macroState[questionID] = answer m.questionsAnswered = append(m.questionsAnswered, questionID) if questionID == "within-trust-boundary" { - m.withinTrustBoundary = strings.ToLower(m.macroState["within-trust-boundary"][0]) == "yes" + m.withinTrustBoundary = strings.EqualFold(m.macroState["within-trust-boundary"][0], "yes") } else if questionID == "selected-trust-boundary" { - m.createNewTrustBoundary = strings.ToLower(m.macroState["selected-trust-boundary"][0]) == strings.ToLower(createNewTrustBoundaryLabel) + m.createNewTrustBoundary = strings.EqualFold(m.macroState["selected-trust-boundary"][0], createNewTrustBoundaryLabel) } return "Answer processed", true, nil } @@ -242,7 +242,7 @@ func (m *addVaultMacro) applyChange(modelInput *input.Model, parsedModel *types. Integrity: types.Critical.String(), Availability: types.Critical.String(), JustificationCiaRating: "Vault components are only rated as 'confidential' as vaults usually apply a trust barrier to encrypt all data-at-rest with a vault key.", - MultiTenant: strings.ToLower(m.macroState["multi-tenant"][0]) == "yes", + MultiTenant: strings.EqualFold(m.macroState["multi-tenant"][0], "yes"), Redundant: false, CustomDevelopedParts: false, DataAssetsProcessed: nil, @@ -357,7 +357,7 @@ func (m *addVaultMacro) applyChange(modelInput *input.Model, parsedModel *types. Integrity: types.Critical.String(), Availability: types.Critical.String(), JustificationCiaRating: "Vault components are rated as 'strictly-confidential'.", - MultiTenant: strings.ToLower(m.macroState["multi-tenant"][0]) == "yes", + MultiTenant: strings.EqualFold(m.macroState["multi-tenant"][0], "yes"), Redundant: false, CustomDevelopedParts: false, DataAssetsProcessed: []string{"configuration-secrets"}, diff --git a/pkg/macros/macros.go b/pkg/macros/macros.go index c1f3bcaa..e3b2fffb 100644 --- a/pkg/macros/macros.go +++ b/pkg/macros/macros.go @@ -204,9 +204,8 @@ func ExecuteModelMacro(modelInput *input.Model, inputFile string, parsedModel *t fmt.Println("The following changes will be applied:") var changes []string message := "" - validResult := true - changes, message, validResult, err = macros.GetFinalChangeImpact(modelInput, parsedModel) + changes, message, validResult, err := macros.GetFinalChangeImpact(modelInput, parsedModel) if err != nil { return err } @@ -339,7 +338,7 @@ func (what MacroQuestion) IsValueConstrained() bool { func (what MacroQuestion) IsMatchingValueConstraint(answer string) bool { if what.IsValueConstrained() { for _, val := range what.PossibleAnswers { - if strings.ToLower(val) == strings.ToLower(answer) { + if strings.EqualFold(val, answer) { return true } } diff --git a/pkg/model/parse.go b/pkg/model/parse.go index dc22391c..623106ff 100644 --- a/pkg/model/parse.go +++ b/pkg/model/parse.go @@ -208,7 +208,6 @@ func ParseModel(modelInput *input.Model, builtinRiskRules map[string]risks.RiskR communicationLinks := make([]types.CommunicationLink, 0) if asset.CommunicationLinks != nil { for commLinkTitle, commLink := range asset.CommunicationLinks { - constraint := true weight := 1 var dataAssetsSent []string var dataAssetsReceived []string @@ -270,8 +269,6 @@ func ParseModel(modelInput *input.Model, builtinRiskRules map[string]risks.RiskR weight = commLink.DiagramTweakWeight } - constraint = !commLink.DiagramTweakConstraint - dataFlowTitle := fmt.Sprintf("%v", commLinkTitle) if err != nil { return nil, err @@ -301,7 +298,7 @@ func ParseModel(modelInput *input.Model, builtinRiskRules map[string]risks.RiskR DataAssetsSent: dataAssetsSent, DataAssetsReceived: dataAssetsReceived, DiagramTweakWeight: weight, - DiagramTweakConstraint: constraint, + DiagramTweakConstraint: !commLink.DiagramTweakConstraint, } communicationLinks = append(communicationLinks, commLink) // track all comm links diff --git a/pkg/report/excel.go b/pkg/report/excel.go index 9ca38650..42247f1e 100644 --- a/pkg/report/excel.go +++ b/pkg/report/excel.go @@ -54,52 +54,58 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro return fmt.Errorf("unable to set header/footer: %w", err) } - err = excel.SetCellValue(sheetName, "A1", "Severity") - err = excel.SetCellValue(sheetName, "B1", "Likelihood") - err = excel.SetCellValue(sheetName, "C1", "Impact") - err = excel.SetCellValue(sheetName, "D1", "STRIDE") - err = excel.SetCellValue(sheetName, "E1", "Function") - err = excel.SetCellValue(sheetName, "F1", "CWE") - err = excel.SetCellValue(sheetName, "G1", "Risk Category") - err = excel.SetCellValue(sheetName, "H1", "Technical Asset") - err = excel.SetCellValue(sheetName, "I1", "Communication Link") - err = excel.SetCellValue(sheetName, "J1", "RAA %") - err = excel.SetCellValue(sheetName, "K1", "Identified Risk") - err = excel.SetCellValue(sheetName, "L1", "Action") - err = excel.SetCellValue(sheetName, "M1", "Mitigation") - err = excel.SetCellValue(sheetName, "N1", "Check") - err = excel.SetCellValue(sheetName, "O1", "ID") - err = excel.SetCellValue(sheetName, "P1", "Status") - err = excel.SetCellValue(sheetName, "Q1", "Justification") - err = excel.SetCellValue(sheetName, "R1", "Date") - err = excel.SetCellValue(sheetName, "S1", "Checked by") - err = excel.SetCellValue(sheetName, "T1", "Ticket") - - err = excel.SetColWidth(sheetName, "A", "A", 12) - err = excel.SetColWidth(sheetName, "B", "B", 15) - err = excel.SetColWidth(sheetName, "C", "C", 15) - err = excel.SetColWidth(sheetName, "D", "D", 22) - err = excel.SetColWidth(sheetName, "E", "E", 16) - err = excel.SetColWidth(sheetName, "F", "F", 12) - err = excel.SetColWidth(sheetName, "G", "G", 50) - err = excel.SetColWidth(sheetName, "H", "H", 50) - err = excel.SetColWidth(sheetName, "I", "I", 50) - err = excel.SetColWidth(sheetName, "J", "J", 10) - err = excel.SetColWidth(sheetName, "K", "K", 75) - err = excel.SetColWidth(sheetName, "L", "L", 45) - err = excel.SetColWidth(sheetName, "M", "M", 75) - err = excel.SetColWidth(sheetName, "N", "N", 50) - err = excel.SetColWidth(sheetName, "O", "O", 10) - err = excel.SetColWidth(sheetName, "P", "P", 18) - err = excel.SetColWidth(sheetName, "Q", "Q", 75) - err = excel.SetColWidth(sheetName, "R", "R", 18) - err = excel.SetColWidth(sheetName, "S", "S", 20) - err = excel.SetColWidth(sheetName, "T", "T", 20) + err = setCellValue(excel, sheetName, []setCellValueCommand{ + {"A1", "Severity"}, + {"B1", "Likelihood"}, + {"C1", "Impact"}, + {"D1", "STRIDE"}, + {"E1", "Function"}, + {"F1", "CWE"}, + {"G1", "Risk Category"}, + {"H1", "Technical Asset"}, + {"I1", "Communication Link"}, + {"J1", "RAA %"}, + {"K1", "Identified Risk"}, + {"L1", "Action"}, + {"M1", "Mitigation"}, + {"N1", "Check"}, + {"O1", "ID"}, + {"P1", "Status"}, + {"Q1", "Justification"}, + {"R1", "Date"}, + {"S1", "Checked by"}, + {"T1", "Ticket"}, + }) + if err != nil { + return fmt.Errorf("unable to set cell value: %w", err) + } + + err = setColumnWidth(excel, sheetName, []setColumnWidthCommand{ + {"A", 12}, + {"B", 15}, + {"C", 15}, + {"D", 22}, + {"E", 16}, + {"F", 12}, + {"G", 50}, + {"H", 50}, + {"I", 50}, + {"J", 10}, + {"K", 75}, + {"L", 45}, + {"M", 75}, + {"N", 50}, + {"O", 10}, + {"P", 18}, + {"Q", 75}, + {"R", 18}, + {"S", 20}, + {"T", 20}, + }) if err != nil { return fmt.Errorf("unable to set column width: %w", err) } - // styleSeverityCriticalBold, err := excel.NewStyle(`{"font":{"color":"` + rgbHexColorCriticalRisk() + `","size":12,"bold":true}}`) styleSeverityCriticalBold, err := excel.NewStyle(&excelize.Style{ Font: &excelize.Font{ Color: rgbHexColorCriticalRisk(), @@ -107,7 +113,6 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro Bold: true, }, }) - // styleSeverityCriticalCenter, err := excel.NewStyle(`{"alignment":{"horizontal":"center","shrink_to_fit":true,"wrap_text":false},"font":{"color":"` + rgbHexColorCriticalRisk() + `","size":12}}`) styleSeverityCriticalCenter, err := excel.NewStyle(&excelize.Style{ Alignment: &excelize.Alignment{ Horizontal: "center", @@ -119,7 +124,6 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro Size: 12, }, }) - // styleSeverityHighBold, err := excel.NewStyle(`{"font":{"color":"` + rgbHexColorHighRisk() + `","size":12,"bold":true}}`) styleSeverityHighBold, err := excel.NewStyle(&excelize.Style{ Font: &excelize.Font{ Color: rgbHexColorHighRisk(), @@ -127,7 +131,6 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro Bold: true, }, }) - // styleSeverityHighCenter, err := excel.NewStyle(`{"alignment":{"horizontal":"center","shrink_to_fit":true,"wrap_text":false},"font":{"color":"` + rgbHexColorHighRisk() + `","size":12}}`) styleSeverityHighCenter, err := excel.NewStyle(&excelize.Style{ Alignment: &excelize.Alignment{ Horizontal: "center", @@ -139,7 +142,6 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro Size: 12, }, }) - // styleSeverityElevatedBold, err := excel.NewStyle(`{"font":{"color":"` + rgbHexColorElevatedRisk() + `","size":12,"bold":true}}`) styleSeverityElevatedBold, err := excel.NewStyle(&excelize.Style{ Font: &excelize.Font{ Color: rgbHexColorElevatedRisk(), @@ -147,7 +149,6 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro Bold: true, }, }) - // styleSeverityElevatedCenter, err := excel.NewStyle(`{"alignment":{"horizontal":"center","shrink_to_fit":true,"wrap_text":false},"font":{"color":"` + rgbHexColorElevatedRisk() + `","size":12}}`) styleSeverityElevatedCenter, err := excel.NewStyle(&excelize.Style{ Alignment: &excelize.Alignment{ Horizontal: "center", @@ -159,7 +160,6 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro Size: 12, }, }) - // styleSeverityMediumBold, err := excel.NewStyle(`{"font":{"color":"` + rgbHexColorMediumRisk() + `","size":12,"bold":true}}`) styleSeverityMediumBold, err := excel.NewStyle(&excelize.Style{ Font: &excelize.Font{ Color: rgbHexColorMediumRisk(), @@ -167,7 +167,6 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro Bold: true, }, }) - // styleSeverityMediumCenter, err := excel.NewStyle(`{"alignment":{"horizontal":"center","shrink_to_fit":true,"wrap_text":false},"font":{"color":"` + rgbHexColorMediumRisk() + `","size":12}}`) styleSeverityMediumCenter, err := excel.NewStyle(&excelize.Style{ Alignment: &excelize.Alignment{ Horizontal: "center", @@ -179,7 +178,6 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro Size: 12, }, }) - // styleSeverityLowBold, err := excel.NewStyle(`{"font":{"color":"` + rgbHexColorLowRisk() + `","size":12,"bold":true}}`) styleSeverityLowBold, err := excel.NewStyle(&excelize.Style{ Font: &excelize.Font{ Color: rgbHexColorLowRisk(), @@ -187,7 +185,6 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro Bold: true, }, }) - // styleSeverityLowCenter, err := excel.NewStyle(`{"alignment":{"horizontal":"center","shrink_to_fit":true,"wrap_text":false},"font":{"color":"` + rgbHexColorLowRisk() + `","size":12}}`) styleSeverityLowCenter, err := excel.NewStyle(&excelize.Style{ Alignment: &excelize.Alignment{ Horizontal: "center", @@ -200,7 +197,6 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro }, }) - // styleRedCenter, err := excel.NewStyle(`{"alignment":{"horizontal":"center","shrink_to_fit":true,"wrap_text":false},"font":{"color":"` + RgbHexColorRiskStatusUnchecked() + `","size":12}}`) styleRedCenter, err := excel.NewStyle(&excelize.Style{ Alignment: &excelize.Alignment{ Horizontal: "center", @@ -212,7 +208,6 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro Size: 12, }, }) - // styleGreenCenter, err := excel.NewStyle(`{"alignment":{"horizontal":"center","shrink_to_fit":true,"wrap_text":false},"font":{"color":"` + rgbHexColorRiskStatusMitigated() + `","size":12}}`) styleGreenCenter, err := excel.NewStyle(&excelize.Style{ Alignment: &excelize.Alignment{ Horizontal: "center", @@ -224,7 +219,6 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro Size: 12, }, }) - // styleBlueCenter, err := excel.NewStyle(`{"alignment":{"horizontal":"center","shrink_to_fit":true,"wrap_text":false},"font":{"color":"#` + rgbHexColorRiskStatusInProgress() + `","size":12}}`) styleBlueCenter, err := excel.NewStyle(&excelize.Style{ Alignment: &excelize.Alignment{ Horizontal: "center", @@ -236,7 +230,6 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro Size: 12, }, }) - // styleYellowCenter, err := excel.NewStyle(`{"alignment":{"horizontal":"center","shrink_to_fit":true,"wrap_text":false},"font":{"color":"#` + rgbHexColorRiskStatusAccepted() + `","size":12}}`) styleYellowCenter, err := excel.NewStyle(&excelize.Style{ Alignment: &excelize.Alignment{ Horizontal: "center", @@ -248,7 +241,6 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro Size: 12, }, }) - // styleOrangeCenter, err := excel.NewStyle(`{"alignment":{"horizontal":"center","shrink_to_fit":true,"wrap_text":false},"font":{"color":"#` + rgbHexColorRiskStatusInDiscussion() + `","size":12}}`) styleOrangeCenter, err := excel.NewStyle(&excelize.Style{ Alignment: &excelize.Alignment{ Horizontal: "center", @@ -260,7 +252,6 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro Size: 12, }, }) - // styleGrayCenter, err := excel.NewStyle(`{"alignment":{"horizontal":"center","shrink_to_fit":true,"wrap_text":false},"font":{"color":"#` + rgbHexColorRiskStatusFalsePositive() + `","size":12}}`) styleGrayCenter, err := excel.NewStyle(&excelize.Style{ Alignment: &excelize.Alignment{ Horizontal: "center", @@ -272,7 +263,6 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro Size: 12, }, }) - // styleBlackLeft, err := excel.NewStyle(`{"alignment":{"horizontal":"left","shrink_to_fit":true,"wrap_text":false},"font":{"color":"#000000","size":12}}`) styleBlackLeft, err := excel.NewStyle(&excelize.Style{ Alignment: &excelize.Alignment{ Horizontal: "left", @@ -284,7 +274,6 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro Size: 12, }, }) - // styleBlackCenter, err := excel.NewStyle(`{"alignment":{"horizontal":"center","shrink_to_fit":true,"wrap_text":false},"font":{"color":"#000000","size":12}}`) styleBlackCenter, err := excel.NewStyle(&excelize.Style{ Alignment: &excelize.Alignment{ Horizontal: "center", @@ -296,7 +285,6 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro Size: 12, }, }) - // styleBlackRight, err := excel.NewStyle(`{"alignment":{"horizontal":"right","shrink_to_fit":true,"wrap_text":false},"font":{"color":"#000000","size":12}}`) styleBlackRight, err := excel.NewStyle(&excelize.Style{ Alignment: &excelize.Alignment{ Horizontal: "right", @@ -308,21 +296,18 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro Size: 12, }, }) - // styleBlackSmall, err := excel.NewStyle(`{"font":{"color":"#000000","size":10}}`) styleBlackSmall, err := excel.NewStyle(&excelize.Style{ Font: &excelize.Font{ Color: "#000000", Size: 10, }, }) - // styleGraySmall, err := excel.NewStyle(`{"font":{"color":"` + rgbHexColorOutOfScope() + `","size":10}}`) styleGraySmall, err := excel.NewStyle(&excelize.Style{ Font: &excelize.Font{ Color: rgbHexColorOutOfScope(), Size: 10, }, }) - // styleBlackBold, err := excel.NewStyle(`{"alignment":{"horizontal":"left","shrink_to_fit":true,"wrap_text":false},"font":{"color":"#000000","size":12,"bold":true}}`) styleBlackBold, err := excel.NewStyle(&excelize.Style{ Alignment: &excelize.Alignment{ Horizontal: "right", @@ -335,7 +320,6 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro Bold: true, }, }) - // styleMitigation, err := excel.NewStyle(`{"font":{"color":"` + rgbHexColorRiskStatusMitigated() + `","size":10}}`) styleMitigation, err := excel.NewStyle(&excelize.Style{ Font: &excelize.Font{ Color: rgbHexColorRiskStatusMitigated(), @@ -352,25 +336,37 @@ func WriteRisksExcelToFile(parsedModel *types.ParsedModel, filename string) erro commLink := parsedModel.CommunicationLinks[risk.MostRelevantCommunicationLinkId] riskTrackingStatus := risk.GetRiskTrackingStatusDefaultingUnchecked(parsedModel) // content - err := excel.SetCellValue(sheetName, "A"+strconv.Itoa(excelRow), risk.Severity.Title()) - err = excel.SetCellValue(sheetName, "B"+strconv.Itoa(excelRow), risk.ExploitationLikelihood.Title()) - err = excel.SetCellValue(sheetName, "C"+strconv.Itoa(excelRow), risk.ExploitationImpact.Title()) - err = excel.SetCellValue(sheetName, "D"+strconv.Itoa(excelRow), category.STRIDE.Title()) - err = excel.SetCellValue(sheetName, "E"+strconv.Itoa(excelRow), category.Function.Title()) - err = excel.SetCellValue(sheetName, "F"+strconv.Itoa(excelRow), "CWE-"+strconv.Itoa(category.CWE)) - err = excel.SetCellValue(sheetName, "G"+strconv.Itoa(excelRow), category.Title) - err = excel.SetCellValue(sheetName, "H"+strconv.Itoa(excelRow), techAsset.Title) - err = excel.SetCellValue(sheetName, "I"+strconv.Itoa(excelRow), commLink.Title) + err := setCellValue(excel, sheetName, []setCellValueCommand{ + {"A" + strconv.Itoa(excelRow), risk.Severity.Title()}, + {"B" + strconv.Itoa(excelRow), risk.ExploitationLikelihood.Title()}, + {"C" + strconv.Itoa(excelRow), risk.ExploitationImpact.Title()}, + {"D" + strconv.Itoa(excelRow), category.STRIDE.Title()}, + {"E" + strconv.Itoa(excelRow), category.Function.Title()}, + {"F" + strconv.Itoa(excelRow), "CWE-" + strconv.Itoa(category.CWE)}, + {"G" + strconv.Itoa(excelRow), category.Title}, + {"H" + strconv.Itoa(excelRow), techAsset.Title}, + {"I" + strconv.Itoa(excelRow), commLink.Title}, + {"K" + strconv.Itoa(excelRow), removeFormattingTags(risk.Title)}, + {"L" + strconv.Itoa(excelRow), category.Action}, + {"M" + strconv.Itoa(excelRow), category.Mitigation}, + {"N" + strconv.Itoa(excelRow), category.Check}, + {"O" + strconv.Itoa(excelRow), risk.SyntheticId}, + {"P" + strconv.Itoa(excelRow), riskTrackingStatus.Title()}, + }) + if err != nil { + return err + } + err = excel.SetCellFloat(sheetName, "J"+strconv.Itoa(excelRow), techAsset.RAA, 0, 32) - err = excel.SetCellValue(sheetName, "K"+strconv.Itoa(excelRow), removeFormattingTags(risk.Title)) - err = excel.SetCellValue(sheetName, "L"+strconv.Itoa(excelRow), category.Action) - err = excel.SetCellValue(sheetName, "M"+strconv.Itoa(excelRow), category.Mitigation) - err = excel.SetCellValue(sheetName, "N"+strconv.Itoa(excelRow), category.Check) - err = excel.SetCellValue(sheetName, "O"+strconv.Itoa(excelRow), risk.SyntheticId) - err = excel.SetCellValue(sheetName, "P"+strconv.Itoa(excelRow), riskTrackingStatus.Title()) + if err != nil { + return fmt.Errorf("unable to set cell float: %w", err) + } if riskTrackingStatus != types.Unchecked { riskTracking := risk.GetRiskTracking(parsedModel) err = excel.SetCellValue(sheetName, "Q"+strconv.Itoa(excelRow), riskTracking.Justification) + if err != nil { + return fmt.Errorf("unable to set cell value: %w", err) + } if !riskTracking.Date.IsZero() { err = excel.SetCellValue(sheetName, "R"+strconv.Itoa(excelRow), riskTracking.Date.Format("2006-01-02")) } @@ -513,12 +509,19 @@ func WriteTagsExcelToFile(parsedModel *types.ParsedModel, filename string) error } err = excel.SetCellValue(sheetName, "A1", "Element") // TODO is "Element" the correct generic name when referencing assets, links, trust boundaries etc.? Eventually add separate column "type of element" like "technical asset" or "data asset"? + if err != nil { + return err + } + sortedTagsAvailable := parsedModel.TagsActuallyUsed() sort.Strings(sortedTagsAvailable) axis := "" for i, tag := range sortedTagsAvailable { axis = determineColumnLetter(i) err = excel.SetCellValue(sheetName, axis+"1", tag) + if err != nil { + return err + } } err = excel.SetColWidth(sheetName, "A", "A", 60) @@ -688,9 +691,8 @@ func writeRow(excel *excelize.File, excelRow *int, sheetName string, axis string return nil } -var alphabet = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"} - func determineColumnLetter(i int) string { + alphabet := []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"} // can only have 700 columns in Excel that way, but that should be more than usable anyway ;)... otherwise think about your model... i++ if i < 26 { @@ -705,3 +707,33 @@ func removeFormattingTags(content string) interface{} { result = strings.ReplaceAll(strings.ReplaceAll(result, "", ""), "", "") return result } + +type setCellValueCommand struct { + cell string + value interface{} +} + +func setCellValue(excel *excelize.File, sheetName string, cmds []setCellValueCommand) error { + for _, cmd := range cmds { + err := excel.SetCellValue(sheetName, cmd.cell, cmd.value) + if err != nil { + return err + } + } + return nil +} + +type setColumnWidthCommand struct { + column string + width float64 +} + +func setColumnWidth(excel *excelize.File, sheetName string, cmds []setColumnWidthCommand) error { + for _, cmd := range cmds { + err := excel.SetColWidth(sheetName, cmd.column, cmd.column, cmd.width) + if err != nil { + return err + } + } + return nil +} diff --git a/pkg/security/types/risks.go b/pkg/security/types/risks.go index 72bb3569..e9018f04 100644 --- a/pkg/security/types/risks.go +++ b/pkg/security/types/risks.go @@ -46,9 +46,7 @@ func GetRiskCategories(parsedModel *ParsedModel, categoryIDs []string) []RiskCat func AllRisks(parsedModel *ParsedModel) []Risk { result := make([]Risk, 0) for _, risks := range parsedModel.GeneratedRisksByCategory { - for _, risk := range risks { - result = append(result, risk) - } + result = append(result, risks...) } return result } diff --git a/pkg/security/types/technical_asset.go b/pkg/security/types/technical_asset.go index eda65cca..f5d71607 100644 --- a/pkg/security/types/technical_asset.go +++ b/pkg/security/types/technical_asset.go @@ -133,18 +133,14 @@ func (what TechnicalAsset) DataAssetsStoredSorted(parsedModel *ParsedModel) []Da func (what TechnicalAsset) DataFormatsAcceptedSorted() []DataFormat { result := make([]DataFormat, 0) - for _, format := range what.DataFormatsAccepted { - result = append(result, format) - } + result = append(result, what.DataFormatsAccepted...) sort.Sort(ByDataFormatAcceptedSort(result)) return result } func (what TechnicalAsset) CommunicationLinksSorted() []CommunicationLink { result := make([]CommunicationLink, 0) - for _, format := range what.CommunicationLinks { - result = append(result, format) - } + result = append(result, what.CommunicationLinks...) sort.Sort(ByTechnicalCommunicationLinkTitleSort(result)) return result }