From 99537683ffb468dbca8724ae82a68cceb5554064 Mon Sep 17 00:00:00 2001 From: Ola Saadi Date: Tue, 9 Jan 2024 11:49:32 +0200 Subject: [PATCH] Support md output format with all_subnets analysis type Signed-off-by: Ola Saadi --- cmd/analyzer/parse_args.go | 4 ++-- pkg/vpcmodel/mdOutput.go | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cmd/analyzer/parse_args.go b/cmd/analyzer/parse_args.go index 2be1351af..c4f440cee 100644 --- a/cmd/analyzer/parse_args.go +++ b/cmd/analyzer/parse_args.go @@ -212,8 +212,8 @@ func errorInErgs(args *InArgs, flagset *flag.FlagSet) error { func notSupportedYetArgs(args *InArgs) error { diffAnalysis := *args.AnalysisType == allEndpointsDiff || *args.AnalysisType == allSubnetsDiff - if !diffAnalysis && *args.AnalysisType != allEndpoints && *args.OutputFormat != TEXTFormat && - *args.OutputFormat != JSONFormat { + if !diffAnalysis && *args.AnalysisType != allEndpoints && *args.AnalysisType != allSubnets && + *args.OutputFormat != TEXTFormat && *args.OutputFormat != JSONFormat { return fmt.Errorf("currently only txt/json output format supported with %s analysis type", *args.AnalysisType) } if diffAnalysis && *args.OutputFormat != TEXTFormat && *args.OutputFormat != MDFormat { diff --git a/pkg/vpcmodel/mdOutput.go b/pkg/vpcmodel/mdOutput.go index ad4994ceb..282416ca2 100644 --- a/pkg/vpcmodel/mdOutput.go +++ b/pkg/vpcmodel/mdOutput.go @@ -41,7 +41,11 @@ func (m *MDoutputFormatter) WriteOutput(c1, c2 *VPCConfig, switch uc { case AllEndpoints: lines := []string{mdDefaultTitle, mdDefaultHeader} - connLines := m.getGroupedOutput(conn) + connLines := m.getGroupedOutput(conn.GroupedConnectivity) + out += linesToOutput(connLines, lines) + case AllSubnets: + lines := []string{mdDefaultTitle, mdDefaultHeader} + connLines := m.getGroupedOutput(subnetsConn.GroupedConnectivity) out += linesToOutput(connLines, lines) case SubnetsDiff, EndpointsDiff: var mdTitle, mdHeader string @@ -55,8 +59,6 @@ func (m *MDoutputFormatter) WriteOutput(c1, c2 *VPCConfig, lines := []string{mdTitle, mdHeader} connLines := m.getGroupedDiffOutput(cfgsDiff) out += linesToOutput(connLines, lines) - case AllSubnets: - return nil, errors.New("SubnetLevel use case not supported for md format currently ") case SingleSubnet: return nil, errors.New("DebugSubnet use case not supported for md format currently ") } @@ -73,9 +75,9 @@ func linesToOutput(connLines, lines []string) string { return out } -func (m *MDoutputFormatter) getGroupedOutput(conn *VPCConnectivity) []string { - lines := make([]string, len(conn.GroupedConnectivity.GroupedLines)) - for i, line := range conn.GroupedConnectivity.GroupedLines { +func (m *MDoutputFormatter) getGroupedOutput(connLines *GroupConnLines) []string { + lines := make([]string, len(connLines.GroupedLines)) + for i, line := range connLines.GroupedLines { lines[i] = getGroupedMDLine(line) } return lines