Skip to content

Commit

Permalink
Improve code by not overriding array
Browse files Browse the repository at this point in the history
  • Loading branch information
romulets committed Dec 14, 2023
1 parent 4d09d85 commit f46f2d9
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions resources/fetching/fetchers/azure/assets_enrincher_vm_nsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ func (e vmNetworkSecurityGroupEnricher) Enrich(_ context.Context, _ cycle.Metada
continue
}

var err error
securityRulesByNetworkInterface, err = e.extractNetworkSecurityGroupRules(asset, securityRulesByNetworkInterface)
if err != nil {
if err := e.extractNetworkSecurityGroupRules(asset, securityRulesByNetworkInterface); err != nil {
errAgg = errors.Join(errAgg, err)
}
}
Expand All @@ -85,15 +83,15 @@ func (e vmNetworkSecurityGroupEnricher) Enrich(_ context.Context, _ cycle.Metada
return errAgg
}

func (e vmNetworkSecurityGroupEnricher) extractNetworkSecurityGroupRules(asset inventory.AzureAsset, securityRulesByNetworkInterface map[string][]extensionNetworkSecurityRules) (map[string][]extensionNetworkSecurityRules, error) {
func (e vmNetworkSecurityGroupEnricher) extractNetworkSecurityGroupRules(asset inventory.AzureAsset, securityRulesByNetworkInterface map[string][]extensionNetworkSecurityRules) error {
var nics []networkInterface
if err := mapstructure.Decode(asset.Properties["networkInterfaces"], &nics); err != nil {
return securityRulesByNetworkInterface, err
return err
}

var rawSecurityRules []networkSecurityRules
if err := mapstructure.Decode(asset.Properties["securityRules"], &rawSecurityRules); err != nil {
return securityRulesByNetworkInterface, err
return err
}

securityRules := make([]extensionNetworkSecurityRules, 0, len(rawSecurityRules))
Expand All @@ -110,7 +108,7 @@ func (e vmNetworkSecurityGroupEnricher) extractNetworkSecurityGroupRules(asset i
securityRulesByNetworkInterface[nic.Id] = append(interfaceRules, securityRules...)
}

return securityRulesByNetworkInterface, nil
return nil
}

func (e vmNetworkSecurityGroupEnricher) addNetworkRulesToAssetExtensions(vm *inventory.AzureAsset, securityRuleByNetworkInterface map[string][]extensionNetworkSecurityRules) error {
Expand Down

0 comments on commit f46f2d9

Please # to comment.