Skip to content

print cidr in graph in case of a single cidr #895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/vpcmodel/drawioGenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ func (g *groupedExternalNodes) GenerateDrawioTreeNode(gen *DrawioGenerator) draw
name := "Various IP ranges"
if all, _ := isEntirePublicInternetRange(*g); all {
name = publicInternetNodeName
} else {
ipBlock := g.toIPBlock()
if len(ipBlock.ListToPrint()) == 1 {
name = ipBlock.String()
}
}
tn := drawio.NewInternetTreeNode(gen.PublicNetwork(), name)
tn.SetTooltip(tooltip)
Expand Down
12 changes: 9 additions & 3 deletions pkg/vpcmodel/grouping.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,22 +643,28 @@ func listEndpointElemStrWithConfig(eps []EndpointElem, fn func(ep EndpointElem,
}

func (g *groupedExternalNodes) String() string {
// 1 gets list and a union of all IPBlocks
unionBlock := g.toIPBlock()
// 2. print a list s.t. each element contains either a single cidr or an ip range
return strings.Join(unionBlock.ListToPrint(), commaSeparator)
}

func (g *groupedExternalNodes) toIPBlock() *ipblock.IPBlock {
// 1. Created a list of IPBlocks
cidrList := make([]string, len(*g))
for i, n := range *g {
cidrList[i] = n.CidrStr
}
ipbList, _, err := ipStringsToIPblocks(cidrList)
if err != nil {
return ""
return ipblock.New()
}
// 2. union all IPBlocks in a single one; its intervals will be the cidr blocks or ranges that should be printed, after all possible merges
unionBlock := ipblock.New()
for _, ipBlock := range ipbList {
unionBlock = unionBlock.Union(ipBlock)
}
// 3. print a list s.t. each element contains either a single cidr or an ip range
return strings.Join(unionBlock.ListToPrint(), commaSeparator)
return unionBlock
}

// connDiffEncode encodes connectivesDiff information for grouping:
Expand Down