Skip to content

Commit

Permalink
fix names
Browse files Browse the repository at this point in the history
  • Loading branch information
olasaadi99 committed Jan 14, 2024
1 parent 78696e2 commit 14e352b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 39 deletions.
6 changes: 3 additions & 3 deletions pkg/vpcmodel/debugOutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func (t *DebugOutputFormatter) WriteOutput(c1, c2 *VPCConfig,
grouping bool,
uc OutputUseCase) (*SingleAnalysisOutput, error) {
out, err := headerOfAnalyzedVPC(uc, c1.VPC.Name(), "", c1)
unStateFul := false
hasStatelessConns := false
if err != nil {
return nil, err
}
Expand All @@ -21,11 +21,11 @@ func (t *DebugOutputFormatter) WriteOutput(c1, c2 *VPCConfig,
// TODO: add a flag of whether to include grouped output or not
// TODO: add another 'debug' format that includes all detailed output
out = conn.DetailedString()
unStateFul = conn.GroupedConnectivity.HasStatelessConns()
hasStatelessConns = conn.GroupedConnectivity.hasStatelessConns()
case AllSubnets:
case SingleSubnet:
case SubnetsDiff, EndpointsDiff:
}
_, err = WriteToFile(out, outFile)
return &SingleAnalysisOutput{Output: out, VPC1Name: c1.VPC.Name(), VPC2Name: "", format: Debug, HaveUnStateFulConn: unStateFul}, err
return &SingleAnalysisOutput{Output: out, VPC1Name: c1.VPC.Name(), VPC2Name: "", format: Debug, hasStatelessConn: hasStatelessConns}, err
}
10 changes: 5 additions & 5 deletions pkg/vpcmodel/grouping.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,13 @@ func (g *GroupConnLines) String() string {
return strings.Join(linesStr, "\n") + "\n"
}

// get the grouped connectivity stateLessness
func (g *GroupConnLines) HasStatelessConns() bool {
unStateFul := false
// get indication if the connections contain a stateless connection
func (g *GroupConnLines) hasStatelessConns() bool {
hasStatelessConns := false
for _, line := range g.GroupedLines {
unStateFul = unStateFul || line.commonProperties.conn.IsStateful == common.StatefulFalse
hasStatelessConns = hasStatelessConns || line.commonProperties.conn.IsStateful == common.StatefulFalse
}
return unStateFul
return hasStatelessConns
}

func listEndpointElemStr(eps []EndpointElem, fn func(ep EndpointElem) string) string {
Expand Down
15 changes: 5 additions & 10 deletions pkg/vpcmodel/mdOutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ func (m *MDoutputFormatter) WriteOutput(c1, c2 *VPCConfig,
out = "# " + out
var lines []string
var connLines []string
unStateFul := false
hasStatelessConns := false
switch uc {
case AllEndpoints:
lines = []string{mdDefaultTitle, mdDefaultHeader}
connLines = m.getGroupedOutput(conn.GroupedConnectivity)
unStateFul = conn.GroupedConnectivity.HasStatelessConns()
hasStatelessConns = conn.GroupedConnectivity.hasStatelessConns()
case AllSubnets:
lines = []string{mdSubnetsTitle, mdDefaultHeader}
connLines = m.getGroupedOutput(subnetsConn.GroupedConnectivity)
unStateFul = subnetsConn.GroupedConnectivity.HasStatelessConns()
hasStatelessConns = subnetsConn.GroupedConnectivity.hasStatelessConns()
case SubnetsDiff, EndpointsDiff:
var mdTitle, mdHeader string
if uc == EndpointsDiff {
Expand All @@ -62,14 +62,14 @@ func (m *MDoutputFormatter) WriteOutput(c1, c2 *VPCConfig,
}
lines = []string{mdTitle, mdHeader}
connLines = m.getGroupedDiffOutput(cfgsDiff)
unStateFul = m.DiffHasStatelessConns(cfgsDiff)
hasStatelessConns = cfgsDiff.hasStatelessConns()
case SingleSubnet:
return nil, errors.New("DebugSubnet use case not supported for md format currently ")
}
out += linesToOutput(connLines, lines)

_, err = WriteToFile(out, outFile)
return &SingleAnalysisOutput{Output: out, VPC1Name: c1.VPC.Name(), VPC2Name: v2Name, format: MD, HaveUnStateFulConn: unStateFul}, err
return &SingleAnalysisOutput{Output: out, VPC1Name: c1.VPC.Name(), VPC2Name: v2Name, format: MD, hasStatelessConn: hasStatelessConns}, err
}

func linesToOutput(connLines, lines []string) string {
Expand Down Expand Up @@ -100,11 +100,6 @@ func (m *MDoutputFormatter) getGroupedDiffOutput(diff *diffBetweenCfgs) []string
return lines
}

// get the diff grouped connectivity stateLessness
func (m *MDoutputFormatter) DiffHasStatelessConns(diff *diffBetweenCfgs) bool {
return diff.HasStatelessConns()
}

// formats a connection line for md output
func connectivityLineMD(src, dst, conn string) string {
return fmt.Sprintf("| %s | %s | %s |", src, dst, conn)
Expand Down
17 changes: 9 additions & 8 deletions pkg/vpcmodel/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ func NewOutputGenerator(c1, c2 map[string]*VPCConfig, grouping bool, uc OutputUs
// SingleAnalysisOutput captures output per connectivity analysis of a single VPC, or per semantic diff between 2 VPCs
// in the former case VPC2Name will be empty
type SingleAnalysisOutput struct {
VPC1Name string
VPC2Name string
Output string
jsonStruct interface{}
format OutFormat
HaveUnStateFulConn bool
VPC1Name string
VPC2Name string
Output string
jsonStruct interface{}
format OutFormat
// hasStatelessConn indicates if the connectivity results contain a stateless conn
hasStatelessConn bool
}

// Generate returns a string representing the analysis output for all input VPCs
Expand Down Expand Up @@ -217,7 +218,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.HaveUnStateFulConn {
if uc != SingleSubnet && o.hasStatelessConn {
infoMessage = asteriskDetails
}
}
Expand All @@ -241,7 +242,7 @@ func (of *serialOutputFormatter) WriteDiffOutput(output *SingleAnalysisOutput, o
switch of.outFormat {
case Text, MD, Debug: // currently, return out as is
infoMessage := ""
if output.HaveUnStateFulConn {
if output.hasStatelessConn {
infoMessage = asteriskDetails
}
res, err = WriteToFile(output.Output+infoMessage, outFile)
Expand Down
8 changes: 4 additions & 4 deletions pkg/vpcmodel/semanticDiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,16 @@ func (diffCfgs *diffBetweenCfgs) String() string {
}

// get the grouped diff connectivity stateLessness
func (diffCfgs *diffBetweenCfgs) HasStatelessConns() bool {
unStateFul := false
func (diffCfgs *diffBetweenCfgs) hasStatelessConns() bool {
hasStatelessConns := false
for _, grouped := range diffCfgs.groupedLines {
unStateFul = unStateFul ||
hasStatelessConns = hasStatelessConns ||
(grouped.commonProperties.connDiff.conn1 != nil &&
grouped.commonProperties.connDiff.conn1.IsStateful == common.StatefulFalse) ||
(grouped.commonProperties.connDiff.conn2 != nil &&
grouped.commonProperties.connDiff.conn2.IsStateful == common.StatefulFalse)
}
return unStateFul
return hasStatelessConns
}

// prints connection for the above string(..) where the connection could be empty
Expand Down
8 changes: 4 additions & 4 deletions pkg/vpcmodel/subnetsConnectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,12 @@ func (v *VPCsubnetConnectivity) String() string {
}

// get the grouped subnet connectivity stateLessness
func (v *VPCsubnetConnectivity) HasStatelessConns() bool {
unStateFul := false
func (v *VPCsubnetConnectivity) hasStatelessConns() bool {
hasStatelessConns := false
for _, line := range v.GroupedConnectivity.GroupedLines {
unStateFul = unStateFul || line.commonProperties.conn.IsStateful == common.StatefulFalse
hasStatelessConns = hasStatelessConns || line.commonProperties.conn.IsStateful == common.StatefulFalse
}
return unStateFul
return hasStatelessConns
}

// GetConnectivityOutputPerEachSubnetSeparately returns string results of connectivity analysis per
Expand Down
10 changes: 5 additions & 5 deletions pkg/vpcmodel/textOutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ func (t *TextOutputFormatter) WriteOutput(c1, c2 *VPCConfig,
if err != nil {
return nil, err
}
unStateFul := false
hasStatelessConns := false

// get output by analysis type
switch uc {
case AllEndpoints:
out += conn.GroupedConnectivity.String()
unStateFul = conn.GroupedConnectivity.HasStatelessConns()
hasStatelessConns = conn.GroupedConnectivity.hasStatelessConns()
case AllSubnets:
out += subnetsConn.String()
unStateFul = subnetsConn.GroupedConnectivity.HasStatelessConns()
hasStatelessConns = subnetsConn.GroupedConnectivity.hasStatelessConns()
case SingleSubnet:
out += c1.GetConnectivityOutputPerEachSubnetSeparately()
case SubnetsDiff, EndpointsDiff:
out += cfgsDiff.String()
unStateFul = cfgsDiff.HasStatelessConns()
hasStatelessConns = cfgsDiff.hasStatelessConns()
}
// write output to file and return the output string
_, err = WriteToFile(out, outFile)
return &SingleAnalysisOutput{Output: out, VPC1Name: c1.VPC.Name(), VPC2Name: vpc2Name, format: Text, HaveUnStateFulConn: unStateFul}, err
return &SingleAnalysisOutput{Output: out, VPC1Name: c1.VPC.Name(), VPC2Name: vpc2Name, format: Text, hasStatelessConn: hasStatelessConns}, err
}

0 comments on commit 14e352b

Please sign in to comment.