Skip to content

Commit

Permalink
print cidr in graph in case of a single cidr (#895)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiriMoran authored Oct 1, 2024
1 parent 7497375 commit 22fd40b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
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

0 comments on commit 22fd40b

Please sign in to comment.