diff --git a/pkg/ibmvpc/examples/acl_testing5_all_vpcs_subnetsBased_withPGW.md b/pkg/ibmvpc/examples/acl_testing5_all_vpcs_subnetsBased_withPGW.md index 651d5bd9d..26c7c8efa 100644 --- a/pkg/ibmvpc/examples/acl_testing5_all_vpcs_subnetsBased_withPGW.md +++ b/pkg/ibmvpc/examples/acl_testing5_all_vpcs_subnetsBased_withPGW.md @@ -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 * diff --git a/pkg/ibmvpc/examples/acl_testing5_all_vpcs_subnetsBased_withPGW.txt b/pkg/ibmvpc/examples/acl_testing5_all_vpcs_subnetsBased_withPGW.txt index 9fd4a126a..d4fa9c66f 100644 --- a/pkg/ibmvpc/examples/acl_testing5_all_vpcs_subnetsBased_withPGW.txt +++ b/pkg/ibmvpc/examples/acl_testing5_all_vpcs_subnetsBased_withPGW.txt @@ -14,5 +14,3 @@ sub2-1-ky => sub3-1-ky : protocol: ICMP icmp-type: 0 icmp-code: 0; protocol: TCP 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 * diff --git a/pkg/ibmvpc/examples/acl_testing5_old_all_vpcs_subnetsBased_withPGW.md b/pkg/ibmvpc/examples/acl_testing5_old_all_vpcs_subnetsBased_withPGW.md index c2f3eba91..9803523af 100644 --- a/pkg/ibmvpc/examples/acl_testing5_old_all_vpcs_subnetsBased_withPGW.md +++ b/pkg/ibmvpc/examples/acl_testing5_old_all_vpcs_subnetsBased_withPGW.md @@ -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 * diff --git a/pkg/ibmvpc/examples/acl_testing5_old_all_vpcs_subnetsBased_withPGW.txt b/pkg/ibmvpc/examples/acl_testing5_old_all_vpcs_subnetsBased_withPGW.txt index 884a033cf..72dc08d14 100644 --- a/pkg/ibmvpc/examples/acl_testing5_old_all_vpcs_subnetsBased_withPGW.txt +++ b/pkg/ibmvpc/examples/acl_testing5_old_all_vpcs_subnetsBased_withPGW.txt @@ -10,5 +10,3 @@ sub1-3-ky => sub1-2-ky : protocol: TCP 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 * diff --git a/pkg/ibmvpc/examples/demo_with_instances_all_vpcs_.md b/pkg/ibmvpc/examples/demo_with_instances_all_vpcs_.md index 41f6393d4..a55fcf74a 100644 --- a/pkg/ibmvpc/examples/demo_with_instances_all_vpcs_.md +++ b/pkg/ibmvpc/examples/demo_with_instances_all_vpcs_.md @@ -77,5 +77,3 @@ | transit-2-instance-ky[192.168.24.4] | private-2-instance-ky[192.168.8.4] | protocol: TCP src-ports: 443 | | transit-2-instance-ky[192.168.24.4] | transit-0-instance-ky[192.168.16.4] | All Connections | | transit-2-instance-ky[192.168.24.4] | transit-1-instance-ky[192.168.20.4] | All Connections | - -connections are stateful unless marked with * diff --git a/pkg/ibmvpc/examples/demo_with_instances_all_vpcs_.txt b/pkg/ibmvpc/examples/demo_with_instances_all_vpcs_.txt index 7cc214218..f0b256d92 100644 --- a/pkg/ibmvpc/examples/demo_with_instances_all_vpcs_.txt +++ b/pkg/ibmvpc/examples/demo_with_instances_all_vpcs_.txt @@ -74,5 +74,3 @@ transit-2-instance-ky[192.168.24.4] => private-1-instance-ky[192.168.4.4] : prot transit-2-instance-ky[192.168.24.4] => private-2-instance-ky[192.168.8.4] : protocol: TCP src-ports: 443 transit-2-instance-ky[192.168.24.4] => transit-0-instance-ky[192.168.16.4] : All Connections transit-2-instance-ky[192.168.24.4] => transit-1-instance-ky[192.168.20.4] : All Connections - -connections are stateful unless marked with * diff --git a/pkg/ibmvpc/examples/demo_with_instances_all_vpcs__debug.txt b/pkg/ibmvpc/examples/demo_with_instances_all_vpcs__debug.txt index 48ccdb7f4..50fa71169 100644 --- a/pkg/ibmvpc/examples/demo_with_instances_all_vpcs__debug.txt +++ b/pkg/ibmvpc/examples/demo_with_instances_all_vpcs__debug.txt @@ -6032,5 +6032,3 @@ transit-2-instance-ky[192.168.24.4] => private-1-instance-ky[192.168.4.4] : prot transit-2-instance-ky[192.168.24.4] => private-2-instance-ky[192.168.8.4] : protocol: TCP src-ports: 443 transit-2-instance-ky[192.168.24.4] => transit-0-instance-ky[192.168.16.4] : All Connections transit-2-instance-ky[192.168.24.4] => transit-1-instance-ky[192.168.20.4] : All Connections - -connections are stateful unless marked with * diff --git a/pkg/ibmvpc/examples/demo_with_instances_all_vpcs__with_grouping.txt b/pkg/ibmvpc/examples/demo_with_instances_all_vpcs__with_grouping.txt index 7cc214218..f0b256d92 100644 --- a/pkg/ibmvpc/examples/demo_with_instances_all_vpcs__with_grouping.txt +++ b/pkg/ibmvpc/examples/demo_with_instances_all_vpcs__with_grouping.txt @@ -74,5 +74,3 @@ transit-2-instance-ky[192.168.24.4] => private-1-instance-ky[192.168.4.4] : prot transit-2-instance-ky[192.168.24.4] => private-2-instance-ky[192.168.8.4] : protocol: TCP src-ports: 443 transit-2-instance-ky[192.168.24.4] => transit-0-instance-ky[192.168.16.4] : All Connections transit-2-instance-ky[192.168.24.4] => transit-1-instance-ky[192.168.20.4] : All Connections - -connections are stateful unless marked with * diff --git a/pkg/ibmvpc/examples/demo_with_instances_all_vpcs_subnetsBased_withPGW.txt b/pkg/ibmvpc/examples/demo_with_instances_all_vpcs_subnetsBased_withPGW.txt index 107635ff4..18416d0a3 100644 --- a/pkg/ibmvpc/examples/demo_with_instances_all_vpcs_subnetsBased_withPGW.txt +++ b/pkg/ibmvpc/examples/demo_with_instances_all_vpcs_subnetsBased_withPGW.txt @@ -75,5 +75,3 @@ ky-testenv-transit-subnet-3 => ky-testenv-private-subnet-2 : protocol: TCP src-p ky-testenv-transit-subnet-3 => ky-testenv-private-subnet-3 : protocol: TCP src-ports: 443 ky-testenv-transit-subnet-3 => ky-testenv-transit-subnet-1 : All Connections ky-testenv-transit-subnet-3 => ky-testenv-transit-subnet-2 : All Connections - -connections are stateful unless marked with * diff --git a/pkg/ibmvpc/examples/demo_with_instances_vpes_all_vpcs_.txt b/pkg/ibmvpc/examples/demo_with_instances_vpes_all_vpcs_.txt index 445e83512..21943b09b 100644 --- a/pkg/ibmvpc/examples/demo_with_instances_vpes_all_vpcs_.txt +++ b/pkg/ibmvpc/examples/demo_with_instances_vpes_all_vpcs_.txt @@ -134,5 +134,3 @@ transit-2-instance-ky[192.168.24.4] => private-1-instance-ky[192.168.4.4] : prot transit-2-instance-ky[192.168.24.4] => private-2-instance-ky[192.168.8.4] : protocol: TCP src-ports: 443 transit-2-instance-ky[192.168.24.4] => transit-0-instance-ky[192.168.16.4] : All Connections transit-2-instance-ky[192.168.24.4] => transit-1-instance-ky[192.168.20.4] : All Connections - -connections are stateful unless marked with * diff --git a/pkg/ibmvpc/examples/experiments_env_all_vpcs_.txt b/pkg/ibmvpc/examples/experiments_env_all_vpcs_.txt index d44d81ccb..7b9edaaf5 100644 --- a/pkg/ibmvpc/examples/experiments_env_all_vpcs_.txt +++ b/pkg/ibmvpc/examples/experiments_env_all_vpcs_.txt @@ -12,5 +12,3 @@ vsi2-ky[10.240.2.4] => vsi1-ky[10.240.1.4] : All Connections Connectivity for VPC test-vpc2-ky vsi20-ky[10.240.128.4] => vsi21-ky[10.240.128.5] : All Connections vsi21-ky[10.240.128.5] => vsi20-ky[10.240.128.4] : All Connections - -connections are stateful unless marked with * diff --git a/pkg/ibmvpc/examples/iks_config_object_all_vpcs__with_grouping.txt b/pkg/ibmvpc/examples/iks_config_object_all_vpcs__with_grouping.txt index e46cc6907..1d3e91dea 100644 --- a/pkg/ibmvpc/examples/iks_config_object_all_vpcs__with_grouping.txt +++ b/pkg/ibmvpc/examples/iks_config_object_all_vpcs__with_grouping.txt @@ -128,5 +128,3 @@ iks-node[192.168.8.4] => iks-node[192.168.32.4] : All Connections iks-node[192.168.8.4] => iks-node[192.168.36.4] : All Connections iks-node[192.168.8.4] => iks-node[192.168.4.4] : All Connections iks-node[192.168.8.4] => iks-node[192.168.40.4] : All Connections - -connections are stateful unless marked with * diff --git a/pkg/ibmvpc/examples/multiple_vpcs_all_vpcs_subnetsBased_withPGW.txt b/pkg/ibmvpc/examples/multiple_vpcs_all_vpcs_subnetsBased_withPGW.txt index 76e94d0fe..37aa98baf 100644 --- a/pkg/ibmvpc/examples/multiple_vpcs_all_vpcs_subnetsBased_withPGW.txt +++ b/pkg/ibmvpc/examples/multiple_vpcs_all_vpcs_subnetsBased_withPGW.txt @@ -92,5 +92,3 @@ sub2-1-ky => sub3-1-ky : protocol: ICMP icmp-type: 0 icmp-code: 0; protocol: TCP 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 * diff --git a/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs_.md b/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs_.md index 4729747d6..fd22b9f4a 100644 --- a/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs_.md +++ b/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs_.md @@ -16,5 +16,3 @@ | vsi3b-ky[10.240.30.4] | vsi1-ky[10.240.10.4] | All Connections | | vsi3b-ky[10.240.30.4] | vsi2-ky[10.240.20.4] | protocol: TCP | | vsi3b-ky[10.240.30.4] | vsi3a-ky[10.240.30.5] | All Connections | - -connections are stateful unless marked with * diff --git a/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs_.txt b/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs_.txt index 4422e63f5..eb049674a 100644 --- a/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs_.txt +++ b/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs_.txt @@ -13,5 +13,3 @@ vsi3b-ky[10.240.30.4] => db-endpoint-gateway-ky[10.240.30.6] : All Connections vsi3b-ky[10.240.30.4] => vsi1-ky[10.240.10.4] : All Connections vsi3b-ky[10.240.30.4] => vsi2-ky[10.240.20.4] : protocol: TCP vsi3b-ky[10.240.30.4] => vsi3a-ky[10.240.30.5] : All Connections - -connections are stateful unless marked with * diff --git a/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs__debug.txt b/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs__debug.txt index 4d3c223a8..caa66afdc 100644 --- a/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs__debug.txt +++ b/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs__debug.txt @@ -3292,5 +3292,3 @@ vsi3b-ky[10.240.30.4] => db-endpoint-gateway-ky[10.240.30.6] : All Connections vsi3b-ky[10.240.30.4] => vsi1-ky[10.240.10.4] : All Connections vsi3b-ky[10.240.30.4] => vsi2-ky[10.240.20.4] : protocol: TCP vsi3b-ky[10.240.30.4] => vsi3a-ky[10.240.30.5] : All Connections - -connections are stateful unless marked with * diff --git a/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs__with_grouping.txt b/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs__with_grouping.txt index 74a65bc6c..fc5558b64 100644 --- a/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs__with_grouping.txt +++ b/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs__with_grouping.txt @@ -8,5 +8,3 @@ vsi2-ky[10.240.20.4] => Public Internet 142.0.0.0/8 : protocol: ICMP vsi2-ky[10.240.20.4] => vsi1-ky[10.240.10.4] : All Connections vsi2-ky[10.240.20.4] => vsi3b-ky[10.240.30.4] : protocol: TCP vsi3b-ky[10.240.30.4] => vsi2-ky[10.240.20.4] : protocol: TCP - -connections are stateful unless marked with * diff --git a/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs_endpointsDiff.txt b/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs_endpointsDiff.txt index 3d077bd0a..ee84122a3 100644 --- a/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs_endpointsDiff.txt +++ b/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs_endpointsDiff.txt @@ -4,5 +4,3 @@ diff-type: removed, source: vsi1-ky[10.240.10.4], destination: Public Internet 1 diff-type: removed, source: vsi3a-ky[10.240.30.5], destination: db-endpoint-gateway-ky[10.240.30.6], config1: All Connections, config2: No Connections, vsis-diff-info: vsi3a-ky[10.240.30.5] removed diff-type: removed, source: vsi3a-ky[10.240.30.5], destination: vsi1-ky[10.240.10.4], config1: All Connections, config2: No Connections, vsis-diff-info: vsi3a-ky[10.240.30.5] removed diff-type: removed, source: vsi3b-ky[10.240.30.4], destination: vsi3a-ky[10.240.30.5], config1: All Connections, config2: No Connections, vsis-diff-info: vsi3a-ky[10.240.30.5] removed - -connections are stateful unless marked with * diff --git a/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs_subnetsBased_withPGW.txt b/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs_subnetsBased_withPGW.txt index e83d17f3f..258a7428c 100644 --- a/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs_subnetsBased_withPGW.txt +++ b/pkg/ibmvpc/examples/sg_testing1_new_all_vpcs_subnetsBased_withPGW.txt @@ -7,5 +7,3 @@ subnet2-ky => subnet1-ky : All Connections subnet2-ky => subnet3-ky : All Connections subnet3-ky => subnet1-ky : All Connections subnet3-ky => subnet2-ky : All Connections - -connections are stateful unless marked with * diff --git a/pkg/ibmvpc/examples/sg_testing1_new_grouping_all_vpcs_subnetsBased_withPGW_with_grouping.txt b/pkg/ibmvpc/examples/sg_testing1_new_grouping_all_vpcs_subnetsBased_withPGW_with_grouping.txt index 2639d7ffc..631a31486 100644 --- a/pkg/ibmvpc/examples/sg_testing1_new_grouping_all_vpcs_subnetsBased_withPGW_with_grouping.txt +++ b/pkg/ibmvpc/examples/sg_testing1_new_grouping_all_vpcs_subnetsBased_withPGW_with_grouping.txt @@ -2,5 +2,3 @@ Connectivity for VPC test-vpc1-ky combined connections between subnets: subnet1-ky => Public Internet (all ranges) : All Connections subnet1-ky,subnet2-ky,subnet3-ky => subnet1-ky,subnet2-ky,subnet3-ky : All Connections - -connections are stateful unless marked with * diff --git a/pkg/ibmvpc/examples/tgw_basic_example_all_vpcs_.txt b/pkg/ibmvpc/examples/tgw_basic_example_all_vpcs_.txt index e32a4eca0..07582dd6c 100644 --- a/pkg/ibmvpc/examples/tgw_basic_example_all_vpcs_.txt +++ b/pkg/ibmvpc/examples/tgw_basic_example_all_vpcs_.txt @@ -8,5 +8,3 @@ ky-vpc1-vsi[10.240.0.5] => Public Internet (all ranges) : All Connections Connectivity for VPC ky-vpc2 - -connections are stateful unless marked with * diff --git a/pkg/ibmvpc/examples/tgw_basic_example_all_vpcs_subnetsBased_withPGW.txt b/pkg/ibmvpc/examples/tgw_basic_example_all_vpcs_subnetsBased_withPGW.txt index 1581a52d9..fbe8df087 100644 --- a/pkg/ibmvpc/examples/tgw_basic_example_all_vpcs_subnetsBased_withPGW.txt +++ b/pkg/ibmvpc/examples/tgw_basic_example_all_vpcs_subnetsBased_withPGW.txt @@ -10,5 +10,3 @@ combined connections between subnets: Connectivity for VPC ky-vpc2 combined connections between subnets: - -connections are stateful unless marked with * diff --git a/pkg/vpcmodel/debugOutput.go b/pkg/vpcmodel/debugOutput.go index 644990263..2290e0b98 100644 --- a/pkg/vpcmodel/debugOutput.go +++ b/pkg/vpcmodel/debugOutput.go @@ -12,6 +12,7 @@ func (t *DebugOutputFormatter) WriteOutput(c1, c2 *VPCConfig, grouping bool, uc OutputUseCase) (*SingleAnalysisOutput, error) { out, err := headerOfAnalyzedVPC(uc, c1.VPC.Name(), "", c1) + hasStatelessConns := false if err != nil { return nil, err } @@ -20,10 +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() + 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}, err + return &SingleAnalysisOutput{Output: out, VPC1Name: c1.VPC.Name(), VPC2Name: "", format: Debug, hasStatelessConn: hasStatelessConns}, err } diff --git a/pkg/vpcmodel/grouping.go b/pkg/vpcmodel/grouping.go index ab24d809c..3cb0e859c 100644 --- a/pkg/vpcmodel/grouping.go +++ b/pkg/vpcmodel/grouping.go @@ -494,6 +494,18 @@ func (g *GroupConnLines) String() string { return strings.Join(linesStr, "\n") + "\n" } +// get indication if the connections contain a stateless connection +func (g *GroupConnLines) hasStatelessConns() bool { + hasStatelessConns := false + for _, line := range g.GroupedLines { + if line.commonProperties.conn.IsStateful == common.StatefulFalse { + hasStatelessConns = true + break + } + } + return hasStatelessConns +} + func listEndpointElemStr(eps []EndpointElem, fn func(ep EndpointElem) string) string { endpointsStrings := make([]string, len(eps)) for i, ep := range eps { diff --git a/pkg/vpcmodel/mdOutput.go b/pkg/vpcmodel/mdOutput.go index 2cecf5e6f..bc9ee5fb7 100644 --- a/pkg/vpcmodel/mdOutput.go +++ b/pkg/vpcmodel/mdOutput.go @@ -41,13 +41,16 @@ func (m *MDoutputFormatter) WriteOutput(c1, c2 *VPCConfig, out = "# " + out var lines []string var connLines []string + hasStatelessConns := false switch uc { case AllEndpoints: lines = []string{mdDefaultTitle, mdDefaultHeader} connLines = m.getGroupedOutput(conn.GroupedConnectivity) + hasStatelessConns = conn.GroupedConnectivity.hasStatelessConns() case AllSubnets: lines = []string{mdSubnetsTitle, mdDefaultHeader} connLines = m.getGroupedOutput(subnetsConn.GroupedConnectivity) + hasStatelessConns = subnetsConn.GroupedConnectivity.hasStatelessConns() case SubnetsDiff, EndpointsDiff: var mdTitle, mdHeader string if uc == EndpointsDiff { @@ -59,13 +62,14 @@ func (m *MDoutputFormatter) WriteOutput(c1, c2 *VPCConfig, } lines = []string{mdTitle, mdHeader} connLines = m.getGroupedDiffOutput(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}, err + return &SingleAnalysisOutput{Output: out, VPC1Name: c1.VPC.Name(), VPC2Name: v2Name, format: MD, hasStatelessConn: hasStatelessConns}, err } func linesToOutput(connLines, lines []string) string { diff --git a/pkg/vpcmodel/output.go b/pkg/vpcmodel/output.go index b0037a66a..7ed253bcd 100644 --- a/pkg/vpcmodel/output.go +++ b/pkg/vpcmodel/output.go @@ -106,6 +106,8 @@ type SingleAnalysisOutput struct { 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 @@ -188,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) { @@ -199,6 +201,15 @@ func WriteToFile(content, fileName string) (string, error) { return content, nil } +// getAsteriskDetails returns the info message about how non stateful conns are marked in the output, when relevant +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) { @@ -213,14 +224,15 @@ func (of *serialOutputFormatter) AggregateVPCsOutput(outputList []*SingleAnalysi case Text, MD, Debug: // plain concatenation vpcsOut := make([]string, len(outputList)) + hasStatelessConn := false for i, o := range outputList { vpcsOut[i] = o.Output + if o.hasStatelessConn { + hasStatelessConn = true + } } - infoMessage := asteriskDetails sort.Strings(vpcsOut) - if uc == SingleSubnet { - infoMessage = "" - } + infoMessage := getAsteriskDetails(uc, hasStatelessConn, of.outFormat) res, err = WriteToFile(strings.Join(vpcsOut, "\n")+infoMessage, outFile) case JSON: @@ -234,12 +246,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 - res, err = WriteToFile(output.Output+asteriskDetails, outFile) + infoMessage := getAsteriskDetails(uc, output.hasStatelessConn, of.outFormat) + res, err = WriteToFile(output.Output+infoMessage, outFile) case JSON: all := map[string]interface{}{} head := fmt.Sprintf("diff-%s-%s", output.VPC1Name, output.VPC2Name) diff --git a/pkg/vpcmodel/semanticDiff.go b/pkg/vpcmodel/semanticDiff.go index a49ba19b6..79811dad2 100644 --- a/pkg/vpcmodel/semanticDiff.go +++ b/pkg/vpcmodel/semanticDiff.go @@ -271,6 +271,21 @@ func (diffCfgs *diffBetweenCfgs) String() string { return strings.Join(strList, "") } +// get the grouped diff connectivity stateLessness +func (diffCfgs *diffBetweenCfgs) hasStatelessConns() bool { + hasStatelessConns := false + for _, grouped := range diffCfgs.groupedLines { + 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) { + hasStatelessConns = true + break + } + } + return hasStatelessConns +} + // prints connection for the above string(..) where the connection could be empty func connStr(conn *common.ConnectionSet) string { if conn == nil { diff --git a/pkg/vpcmodel/textOutput.go b/pkg/vpcmodel/textOutput.go index bbf49133a..3c81c3663 100644 --- a/pkg/vpcmodel/textOutput.go +++ b/pkg/vpcmodel/textOutput.go @@ -41,18 +41,24 @@ func (t *TextOutputFormatter) WriteOutput(c1, c2 *VPCConfig, if err != nil { return nil, err } + hasStatelessConns := false + // get output by analysis type switch uc { case AllEndpoints: out += conn.GroupedConnectivity.String() + hasStatelessConns = conn.GroupedConnectivity.hasStatelessConns() case AllSubnets: out += subnetsConn.String() + hasStatelessConns = subnetsConn.GroupedConnectivity.hasStatelessConns() case SingleSubnet: out += c1.GetConnectivityOutputPerEachSubnetSeparately() case SubnetsDiff, EndpointsDiff: out += cfgsDiff.String() + 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}, err + return &SingleAnalysisOutput{Output: out, VPC1Name: c1.VPC.Name(), + VPC2Name: vpc2Name, format: Text, hasStatelessConn: hasStatelessConns}, err }