Skip to content

Commit 9ee9329

Browse files
committed
CR
1 parent 4b53121 commit 9ee9329

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

pkg/linter/lintFilterRuleSplitSubnet.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ func (lint *filterRuleSplitSubnet) lintDescription() string {
4141
return "Firewall rules implying different connectivity for different endpoints within a subnet"
4242
}
4343

44-
func (lint *filterRuleSplitSubnet) check() (bool, error) {
45-
lintOK := true
44+
func (lint *filterRuleSplitSubnet) check() ([]finding, error) {
4645
findingRes := []*splitRuleSubnet{}
4746
for _, config := range lint.configs {
4847
if config.IsMultipleVPCsConfig {
@@ -52,17 +51,16 @@ func (lint *filterRuleSplitSubnet) check() (bool, error) {
5251
filterLayer := config.GetFilterTrafficResourceOfKind(layer)
5352
rules, err := filterLayer.GetRules()
5453
if err != nil {
55-
return false, err
54+
return nil, err
5655
}
5756
for _, rule := range rules {
5857
subnetsSplitByRule := []vpcmodel.Subnet{}
5958
for _, subnet := range config.Subnets {
6059
splitSubnet, err := ruleSplitSubnet(subnet, rule.IPBlocks)
6160
if err != nil {
62-
return false, err
61+
return nil, err
6362
}
6463
if splitSubnet {
65-
lintOK = false
6664
subnetsSplitByRule = append(subnetsSplitByRule, subnet)
6765
}
6866
}
@@ -74,7 +72,7 @@ func (lint *filterRuleSplitSubnet) check() (bool, error) {
7472
}
7573
}
7674
lint.findings = findingRes
77-
return lintOK, nil
75+
return lint.convertToFindings(), nil
7876
}
7977

8078
func (lint *filterRuleSplitSubnet) string() string {
@@ -103,7 +101,8 @@ func ruleSplitSubnet(subnet vpcmodel.Subnet, ruleIPBlocks []*ipblock.IPBlock) (b
103101
return false, nil
104102
}
105103

106-
func (lint *filterRuleSplitSubnet) getFindings() []finding {
104+
// todo: is there a better way?
105+
func (lint *filterRuleSplitSubnet) convertToFindings() []finding {
107106
resFinding := make([]finding, len(lint.findings))
108107
for i, issue := range lint.findings {
109108
resFinding[i] = issue

pkg/linter/linterExecute.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ func LinterExecute(configs map[string]*vpcmodel.VPCConfig) (issueFound bool, res
2828
strPerLint := []string{}
2929
for _, thisLinter := range linters {
3030
thisLintStr := ""
31-
lintOK, err := thisLinter.check()
31+
lintFindings, err := thisLinter.check()
3232
if err != nil {
3333
return false, "", err
3434
}
35-
if lintOK {
35+
if len(lintFindings) == 0 {
3636
thisLintStr = fmt.Sprintf("no lint %q issues\n", thisLinter.lintDescription())
3737
} else {
3838
issueFound = true

pkg/linter/linterTypes.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ import "github.com/np-guard/vpc-network-config-analyzer/pkg/vpcmodel"
1010

1111
// todo: export certain functionality
1212
type linter interface {
13-
check() (bool, error) // false if issues found
14-
lintName() string // this lint Name
15-
lintDescription() string // this string Name
16-
string() string // string with this lint's finding
17-
toJSON() []any // this lint finding in JSON
18-
getFindings() []finding
13+
check() ([]finding, error) // false if issues found
14+
lintName() string // this lint Name
15+
lintDescription() string // this string Name
16+
string() string // string with this lint's finding
17+
toJSON() []any // this lint finding in JSON
1918
}
2019

2120
type finding interface {

0 commit comments

Comments
 (0)