Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
olasaadi99 committed Jan 14, 2024
1 parent 11d71d8 commit c060cae
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,3 @@
| sub2-2-ky | sub2-1-ky | All Connections |
| sub3-1-ky | sub1-1-ky | protocol: ICMP icmp-type: 0 icmp-code: 0 |
| sub3-1-ky | sub2-1-ky | protocol: ICMP icmp-type: 0 icmp-code: 0; protocol: TCP dst-ports: 443 |

connections are stateful unless marked with *
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@
| sub2-1-ky | Public Internet 8.8.8.8/32 | protocol: UDP dst-ports: 53 |
| sub2-1-ky | sub2-2-ky | All Connections |
| sub2-2-ky | sub2-1-ky | All Connections |

connections are stateful unless marked with *
5 changes: 4 additions & 1 deletion pkg/vpcmodel/grouping.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,10 @@ func (g *GroupConnLines) String() string {
func (g *GroupConnLines) hasStatelessConns() bool {
hasStatelessConns := false
for _, line := range g.GroupedLines {
hasStatelessConns = hasStatelessConns || line.commonProperties.conn.IsStateful == common.StatefulFalse
if line.commonProperties.conn.IsStateful == common.StatefulFalse {
hasStatelessConns = true
break
}
}
return hasStatelessConns
}
Expand Down
20 changes: 12 additions & 8 deletions pkg/vpcmodel/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (of *serialOutputFormatter) WriteOutput(c1, c2 map[string]*VPCConfig, conns
if err2 != nil {
return "", err2
}
return of.WriteDiffOutput(vpcAnalysisOutput, outFile)
return of.WriteDiffOutput(vpcAnalysisOutput, uc, outFile)
}

func WriteToFile(content, fileName string) (string, error) {
Expand All @@ -201,6 +201,14 @@ func WriteToFile(content, fileName string) (string, error) {
return content, nil
}

func getAsteriskDetails(uc OutputUseCase, hasStatelessConn bool, outFormat OutFormat) string {
if uc != SingleSubnet && (outFormat == Text || outFormat == MD || outFormat == Debug) && hasStatelessConn {
return asteriskDetails
}

return ""
}

// AggregateVPCsOutput returns the output string for a list of SingleAnalysisOutput objects
// and writes the output to outFile
func (of *serialOutputFormatter) AggregateVPCsOutput(outputList []*SingleAnalysisOutput, uc OutputUseCase, outFile string) (string, error) {
Expand All @@ -218,9 +226,7 @@ func (of *serialOutputFormatter) AggregateVPCsOutput(outputList []*SingleAnalysi
vpcsOut := make([]string, len(outputList))
for i, o := range outputList {
vpcsOut[i] = o.Output
if uc != SingleSubnet && o.hasStatelessConn {
infoMessage = asteriskDetails
}
infoMessage = getAsteriskDetails(uc, o.hasStatelessConn, of.outFormat)
}
sort.Strings(vpcsOut)
res, err = WriteToFile(strings.Join(vpcsOut, "\n")+infoMessage, outFile)
Expand All @@ -236,15 +242,13 @@ func (of *serialOutputFormatter) AggregateVPCsOutput(outputList []*SingleAnalysi
}

// WriteDiffOutput actual writing the output into file, with required format adjustments
func (of *serialOutputFormatter) WriteDiffOutput(output *SingleAnalysisOutput, outFile string) (string, error) {
func (of *serialOutputFormatter) WriteDiffOutput(output *SingleAnalysisOutput, uc OutputUseCase, outFile string) (string, error) {
var res string
var err error
switch of.outFormat {
case Text, MD, Debug: // currently, return out as is
infoMessage := ""
if output.hasStatelessConn {
infoMessage = asteriskDetails
}
infoMessage = getAsteriskDetails(uc, output.hasStatelessConn, of.outFormat)
res, err = WriteToFile(output.Output+infoMessage, outFile)
case JSON:
all := map[string]interface{}{}
Expand Down
10 changes: 6 additions & 4 deletions pkg/vpcmodel/semanticDiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,13 @@ func (diffCfgs *diffBetweenCfgs) String() string {
func (diffCfgs *diffBetweenCfgs) hasStatelessConns() bool {
hasStatelessConns := false
for _, grouped := range diffCfgs.groupedLines {
hasStatelessConns = hasStatelessConns ||
(grouped.commonProperties.connDiff.conn1 != nil &&
grouped.commonProperties.connDiff.conn1.IsStateful == common.StatefulFalse) ||
if (grouped.commonProperties.connDiff.conn1 != nil &&
grouped.commonProperties.connDiff.conn1.IsStateful == common.StatefulFalse) ||
(grouped.commonProperties.connDiff.conn2 != nil &&
grouped.commonProperties.connDiff.conn2.IsStateful == common.StatefulFalse)
grouped.commonProperties.connDiff.conn2.IsStateful == common.StatefulFalse) {
hasStatelessConns = true
break
}
}
return hasStatelessConns
}
Expand Down

0 comments on commit c060cae

Please sign in to comment.