Skip to content

Commit

Permalink
Merge pull request #1332 from DamianJarzebowski/expand-nsg-rule-summa…
Browse files Browse the repository at this point in the history
…ry-struct

Add 4 new variables for NSGRuleSummary
  • Loading branch information
denis256 authored Aug 27, 2023
2 parents 9e475c5 + 0d0fc68 commit 5428fbc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
8 changes: 8 additions & 0 deletions modules/azure/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
28 changes: 18 additions & 10 deletions modules/azure/nsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5428fbc

Please sign in to comment.