Skip to content

Commit d8e6830

Browse files
committed
fix
1 parent 34cdf3f commit d8e6830

File tree

7 files changed

+18
-18
lines changed

7 files changed

+18
-18
lines changed

pkg/vpcmodel/explainabilityConnectivity.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func (details *rulesAndConnDetails) computeRoutersAndFilters(c *VPCConfig) (err
184184
// RoutingResources are computed by the parser for []Nodes of the VPC,
185185
src := singleSrcDstDetails.src
186186
dst := singleSrcDstDetails.dst
187-
singleSrcDstDetails.loadBalancerRule = getLoadBalancerRule(c, src, dst)
187+
singleSrcDstDetails.loadBalancerRule = c.getLoadBalancerRule(src, dst)
188188
singleSrcDstDetails.privateSubnetRule = getPrivateSubnetRule(src, dst)
189189
if src.IsInternal() && dst.IsInternal() { // internal (including cross vpcs)
190190
singleSrcDstDetails.crossVpcRouter, _, err = c.getRoutingResource(src, dst)

pkg/vpcmodel/explainabilityInput.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,15 @@ func getSrcOrDstInputNode(c *VPCConfig, name, srcOrDst string) (nodes []Node,
298298
func getNodesFromInputString(c *VPCConfig, cidrOrName string) (nodes []Node,
299299
errType int, err error) {
300300
// 1. cidrOrName references endpoint
301-
endpoint, errType1, err1 := getNodesOfEndpoint(c, cidrOrName)
301+
endpoint, errType1, err1 := c.getNodesOfEndpoint(cidrOrName)
302302
if err1 != nil {
303303
return nil, errType1, err1
304304
}
305305
if endpoint != nil {
306306
return endpoint, noErr, nil
307307
}
308308
// 2. cidrOrName references subnet
309-
subnetEndpoints, err2 := getNodesOfSubnet(c, cidrOrName)
309+
subnetEndpoints, err2 := c.getNodesOfSubnet(cidrOrName)
310310
if err2 != nil {
311311
return nil, noConnectedEndpoints, err2
312312
}
@@ -332,7 +332,7 @@ func getNodesFromInputString(c *VPCConfig, cidrOrName string) (nodes []Node,
332332
// note: in case there are two subnets of the same name, or a subnet and a vsi, we take the first one
333333
// using the same name is a bad practice but its not npGuard's responsibility to guard.
334334
// in this case the user may refer to the exact cidr instead of the name
335-
func getNodesOfSubnet(c *VPCConfig, name string) ([]Node, error) {
335+
func (c *VPCConfig) getNodesOfSubnet(name string) ([]Node, error) {
336336
inputSubnet, inputVpc := getResourceAndVpcNames(name)
337337
var foundSubnet Subnet
338338
for _, subnet := range c.Subnets {
@@ -353,7 +353,7 @@ func getNodesOfSubnet(c *VPCConfig, name string) ([]Node, error) {
353353

354354
// getNodesOfEndpoint gets a string name or UID of an endpoint (e.g. VSI), and
355355
// returns the list of all nodes within this endpoint
356-
func getNodesOfEndpoint(c *VPCConfig, name string) ([]Node, int, error) {
356+
func (c *VPCConfig) getNodesOfEndpoint(name string) ([]Node, int, error) {
357357
var nodeSetOfEndpoint NodeSet
358358
uid := name // uid specified - vpc prefix is not relevant and uid may contain the deliminator "/"
359359
// endpoint name may be prefixed by vpc name

pkg/vpcmodel/nodesConnectivity.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ func (c *VPCConfig) GetVPCNetworkConnectivity(lbAbstraction bool, groupingType i
3434
if !node.IsInternal() {
3535
continue
3636
}
37-
allIngressAllowedConns, ingressAllowedConnsPerLayer, err1 := getAllowedConnsPerDirection(c, true, node)
37+
allIngressAllowedConns, ingressAllowedConnsPerLayer, err1 := c.getAllowedConnsPerDirection(true, node)
3838
if err1 != nil {
3939
return nil, err1
4040
}
41-
allEgressAllowedConns, egressAllowedConnsPerLayer, err2 := getAllowedConnsPerDirection(c, false, node)
41+
allEgressAllowedConns, egressAllowedConnsPerLayer, err2 := c.getAllowedConnsPerDirection(false, node)
4242
if err2 != nil {
4343
return nil, err2
4444
}
@@ -70,7 +70,7 @@ func (c *VPCConfig) GetVPCNetworkConnectivity(lbAbstraction bool, groupingType i
7070
return res, err
7171
}
7272

73-
func getLoadBalancerRule(c *VPCConfig, src, dst Node) LoadBalancerRule {
73+
func (c *VPCConfig) getLoadBalancerRule(src, dst Node) LoadBalancerRule {
7474
for _, lb := range c.LoadBalancers {
7575
if rule := lb.GetLoadBalancerRule(src, dst); rule != nil {
7676
return rule
@@ -91,7 +91,7 @@ func getPrivateSubnetRule(src, dst Node) PrivateSubnetRule {
9191

9292
// getNonFilterNonRouterRulesConn() return the connectivity of all rules that are not part of the filters and routers.
9393
func getNonFilterNonRouterRulesConn(c *VPCConfig, src, dst Node, isIngress bool) *netset.TransportSet {
94-
loadBalancerRule := getLoadBalancerRule(c, src, dst)
94+
loadBalancerRule := c.getLoadBalancerRule(src, dst)
9595
if loadBalancerRule != nil && loadBalancerRule.Deny(isIngress) {
9696
return NoConns()
9797
}
@@ -123,7 +123,7 @@ func updatePerLayerRes(res map[string]map[Node]*netset.TransportSet, layer strin
123123

124124
// getAllowedConnsPerDirection returns: (1) map of allowed (ingress or egress) connectivity for capturedNode, considering
125125
// all relevant resources (nacl/sg/fip/pgw) , and (2) similar map per separated layers only (nacl/sg)
126-
func getAllowedConnsPerDirection(c *VPCConfig, isIngress bool, capturedNode Node) (
126+
func (c *VPCConfig) getAllowedConnsPerDirection(isIngress bool, capturedNode Node) (
127127
allLayersRes map[Node]*netset.TransportSet, // result considering all layers
128128
perLayerRes map[string]map[Node]*netset.TransportSet, // result separated per layer
129129
err error,

pkg/vpcmodel/output.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func NewOutputGenerator(cConfigs *MultipleVPCConfigs, groupingType int, uc Outpu
9797
}
9898
case AllSubnets:
9999
for i, vpcConfig := range cConfigs.Configs() {
100-
subnetsConn, err := GetSubnetsConnectivity(vpcConfig, true, groupingType)
100+
subnetsConn, err := vpcConfig.GetSubnetsConnectivity(true, groupingType)
101101
if err != nil {
102102
return nil, err
103103
}

pkg/vpcmodel/semanticDiff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (configs configsForDiff) GetDiff() (*diffBetweenCfgs, error) {
117117
func getAllowedResponsiveConnections(c *VPCConfig,
118118
diffAnalysis diffAnalysisType) (responsiveConnectivityMap GeneralResponsiveConnectivityMap, err error) {
119119
if diffAnalysis == Subnets {
120-
subnetsConn, err := GetSubnetsConnectivity(c, true, NoGroupingNoConsistencyEdges)
120+
subnetsConn, err := c.GetSubnetsConnectivity(true, NoGroupingNoConsistencyEdges)
121121
if err != nil {
122122
return nil, err
123123
}

pkg/vpcmodel/subnetsConnectivity.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (v *VPCsubnetConnectivity) printAllowedConns(c *VPCConfig) {
7171
}
7272
}
7373

74-
func ipblockToNamedResourcesInConfig(c *VPCConfig, ipb *netset.IPBlock, excludeExternalNodes bool) ([]VPCResourceIntf, error) {
74+
func (c *VPCConfig) ipblockToNamedResourcesInConfig(ipb *netset.IPBlock, excludeExternalNodes bool) ([]VPCResourceIntf, error) {
7575
res := []VPCResourceIntf{}
7676

7777
// consider subnets
@@ -116,7 +116,7 @@ func convertIPbasedToSubnetBasedResult(c *VPCConfig, ipconn *IPbasedConnectivity
116116

117117
for ipb, conn := range ipconn.IngressAllowedConns {
118118
// PGW does not allow ingress traffic but the ingress is required for the responsive computation
119-
if namedResources, err := ipblockToNamedResourcesInConfig(c, ipb, excludeExternalNodes); err == nil {
119+
if namedResources, err := c.ipblockToNamedResourcesInConfig(ipb, excludeExternalNodes); err == nil {
120120
for _, n := range namedResources {
121121
res.IngressAllowedConns[n] = conn
122122
}
@@ -127,7 +127,7 @@ func convertIPbasedToSubnetBasedResult(c *VPCConfig, ipconn *IPbasedConnectivity
127127

128128
// egress traffic to external nodes may be enabled by a public gateway
129129
for ipb, conn := range ipconn.EgressAllowedConns {
130-
if namedResources, err := ipblockToNamedResourcesInConfig(c, ipb, excludeExternalNodes); err == nil {
130+
if namedResources, err := c.ipblockToNamedResourcesInConfig(ipb, excludeExternalNodes); err == nil {
131131
for _, n := range namedResources {
132132
res.EgressAllowedConns[n] = conn
133133
}
@@ -172,7 +172,7 @@ func getSubnetsWithPGW(c *VPCConfig) map[string]bool {
172172
}
173173

174174
// the main function to compute connectivity per subnet based on resources that capture subnets, such as nacl, pgw, tgw, routing-tables
175-
func GetSubnetsConnectivity(c *VPCConfig, includePGW bool, groupingType int) (*VPCsubnetConnectivity, error) {
175+
func (c *VPCConfig) GetSubnetsConnectivity(includePGW bool, groupingType int) (*VPCsubnetConnectivity, error) {
176176
var subnetsConnectivityFromACLresources map[string]*IPbasedConnectivityResult
177177
var err error
178178
for _, fl := range c.FilterResources {
@@ -351,7 +351,7 @@ func (v *VPCsubnetConnectivity) computeResponsiveConnections(allowedConnsCombine
351351
// GetConnectivityOutputPerEachSubnetSeparately returns string results of connectivity analysis per
352352
// single subnet with its attached nacl, separately per subnet - useful to get understanding of the
353353
// connectivity implied from nacl configuration applied on a certain subnet in the vpc
354-
func GetConnectivityOutputPerEachSubnetSeparately(c *VPCConfig) string {
354+
func (c *VPCConfig) GetConnectivityOutputPerEachSubnetSeparately() string {
355355
// iterate over all subnets, collect all outputs per subnet connectivity
356356
for _, r := range c.FilterResources {
357357
if r.Kind() == NaclLayer {

pkg/vpcmodel/textOutput.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (t *TextOutputFormatter) WriteOutput(c1, c2 *VPCConfig,
7878
out += subnetsConn.GroupedConnectivity.String(c1)
7979
hasStatelessConns = subnetsConn.GroupedConnectivity.hasStatelessConns()
8080
case SingleSubnet:
81-
out += GetConnectivityOutputPerEachSubnetSeparately(c1)
81+
out += c1.GetConnectivityOutputPerEachSubnetSeparately()
8282
case SubnetsDiff, EndpointsDiff:
8383
diffOut := cfgsDiff.String()
8484
if diffOut != "" {

0 commit comments

Comments
 (0)