From 0d0fc680f6404da95ce80c31470fa6f361eda1da Mon Sep 17 00:00:00 2001 From: Damian Jarzebowski Date: Wed, 23 Aug 2023 14:03:33 +0200 Subject: [PATCH] Add 4 new variables for NSGRuleSummary --- modules/azure/common.go | 8 ++++++++ modules/azure/nsg.go | 28 ++++++++++++++++++---------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/modules/azure/common.go b/modules/azure/common.go index ff3a52a66..2436a1770 100644 --- a/modules/azure/common.go +++ b/modules/azure/common.go @@ -64,3 +64,11 @@ func safePtrToInt32(raw *int32) int32 { } return *raw } + +// safePtrToList converts a []string pointer to a non-pointer []string value, or to initialization of an empty slice if the pointer is nil. +func safePtrToList(raw *[]string) []string { + if raw == nil { + return []string{} + } + return *raw +} diff --git a/modules/azure/nsg.go b/modules/azure/nsg.go index 865142587..077412ba5 100644 --- a/modules/azure/nsg.go +++ b/modules/azure/nsg.go @@ -20,16 +20,20 @@ type NsgRuleSummaryList struct { // NsgRuleSummary is a string-based (non-pointer) summary of an NSG rule with several helper methods attached // to help with verification of rule configuratoin. type NsgRuleSummary struct { - Name string - Description string - Protocol string - SourcePortRange string - DestinationPortRange string - SourceAddressPrefix string - DestinationAddressPrefix string - Access string - Priority int32 - Direction string + Name string + Description string + Protocol string + SourcePortRange string + SourcePortRanges []string + DestinationPortRange string + DestinationPortRanges []string + SourceAddressPrefix string + SourceAdresssPrefixes []string + DestinationAddressPrefix string + DestinationAddressPrefixes []string + Access string + Priority int32 + Direction string } // GetDefaultNsgRulesClient returns a rules client which can be used to read the list of *default* security rules @@ -169,9 +173,13 @@ func convertToNsgRuleSummary(name *string, rule *network.SecurityRulePropertiesF summary.Name = safePtrToString(name) summary.Protocol = string(rule.Protocol) summary.SourcePortRange = safePtrToString(rule.SourcePortRange) + summary.SourcePortRanges = safePtrToList(rule.SourcePortRanges) summary.DestinationPortRange = safePtrToString(rule.DestinationPortRange) + summary.DestinationPortRanges = safePtrToList(rule.DestinationPortRanges) summary.SourceAddressPrefix = safePtrToString(rule.SourceAddressPrefix) + summary.SourceAdresssPrefixes = safePtrToList(rule.SourceAddressPrefixes) summary.DestinationAddressPrefix = safePtrToString(rule.DestinationAddressPrefix) + summary.DestinationAddressPrefixes = safePtrToList(rule.DestinationAddressPrefixes) summary.Access = string(rule.Access) summary.Priority = safePtrToInt32(rule.Priority) summary.Direction = string(rule.Direction)