Skip to content

Commit 99339ca

Browse files
authored
Merge branch 'feat/aws-acm-mock-tests' into fix/aws-rds-bounds-acm-pagination
2 parents e8f358c + e09e9f9 commit 99339ca

13 files changed

Lines changed: 173 additions & 54 deletions

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ require (
9696
github.com/gonvenience/ytbx v1.4.4
9797
github.com/hashicorp/go-getter/v2 v2.2.3
9898
github.com/homeport/dyff v1.6.0
99-
github.com/jackc/pgx/v5 v5.7.1
99+
github.com/jackc/pgx/v5 v5.9.0
100100
github.com/lib/pq v1.10.9
101101
github.com/slack-go/slack v0.15.0
102102
gopkg.in/yaml.v3 v3.0.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI
373373
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
374374
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
375375
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
376-
github.com/jackc/pgx/v5 v5.7.1 h1:x7SYsPBYDkHDksogeSmZZ5xzThcTgRz++I5E+ePFUcs=
377-
github.com/jackc/pgx/v5 v5.7.1/go.mod h1:e7O26IywZZ+naJtWWos6i6fvWK+29etgITqrqHLfoZA=
376+
github.com/jackc/pgx/v5 v5.9.0 h1:T/dI+2TvmI2H8s/KH1/lXIbz1CUFk3gn5oTjr0/mBsE=
377+
github.com/jackc/pgx/v5 v5.9.0/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4=
378378
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
379379
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
380380
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a h1:zPPuIq2jAWWPTrGt70eK/BSch+gFAGrNzecsoENgu2o=

modules/azure/availabilityset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func GetAvailabilitySetFaultDomainCountContextE(t testing.TestingT, ctx context.
228228

229229
// ExtractAvailabilitySetFaultDomainCount gets the Fault Domain Count from the provided AvailabilitySet.
230230
func ExtractAvailabilitySetFaultDomainCount(avs *armcompute.AvailabilitySet) (int32, error) {
231-
if avs.Properties == nil || avs.Properties.PlatformFaultDomainCount == nil {
231+
if avs == nil || avs.Properties == nil || avs.Properties.PlatformFaultDomainCount == nil {
232232
return -1, errors.New("availability set has no fault domain count")
233233
}
234234

modules/azure/compute.go

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func GetVirtualMachineNicsContextE(ctx context.Context, vmName string, resGroupN
136136

137137
// extractVMNics extracts the Network Interface names from a Virtual Machine object.
138138
func extractVMNics(vm *armcompute.VirtualMachine) ([]string, error) {
139-
if vm.Properties == nil || vm.Properties.NetworkProfile == nil {
139+
if vm == nil || vm.Properties == nil || vm.Properties.NetworkProfile == nil {
140140
return nil, nil
141141
}
142142

@@ -145,6 +145,10 @@ func extractVMNics(vm *armcompute.VirtualMachine) ([]string, error) {
145145
var nics []string
146146

147147
for _, nic := range vmNICs {
148+
if nic == nil || nic.ID == nil {
149+
continue
150+
}
151+
148152
nicName, err := GetNameFromResourceIDE(*nic.ID)
149153
if err != nil {
150154
return nil, fmt.Errorf("failed to parse NIC resource ID %q: %w", *nic.ID, err)
@@ -198,11 +202,20 @@ func GetVirtualMachineManagedDisksContextE(ctx context.Context, vmName string, r
198202

199203
// extractVMManagedDisks extracts the Managed Disk names from a Virtual Machine object.
200204
func extractVMManagedDisks(vm *armcompute.VirtualMachine) []string {
205+
if vm == nil || vm.Properties == nil || vm.Properties.StorageProfile == nil {
206+
return nil
207+
}
208+
201209
vmDisks := vm.Properties.StorageProfile.DataDisks
202210

203-
diskNames := make([]string, len(vmDisks))
204-
for i, v := range vmDisks {
205-
diskNames[i] = *v.Name
211+
diskNames := make([]string, 0, len(vmDisks))
212+
213+
for _, v := range vmDisks {
214+
if v == nil || v.Name == nil {
215+
continue
216+
}
217+
218+
diskNames = append(diskNames, *v.Name)
206219
}
207220

208221
return diskNames
@@ -250,6 +263,11 @@ func GetVirtualMachineOSDiskNameContextE(ctx context.Context, vmName string, res
250263

251264
// extractVMOSDiskName extracts the OS Disk name from a Virtual Machine object.
252265
func extractVMOSDiskName(vm *armcompute.VirtualMachine) string {
266+
if vm == nil || vm.Properties == nil || vm.Properties.StorageProfile == nil ||
267+
vm.Properties.StorageProfile.OSDisk == nil || vm.Properties.StorageProfile.OSDisk.Name == nil {
268+
return ""
269+
}
270+
253271
return *vm.Properties.StorageProfile.OSDisk.Name
254272
}
255273

@@ -295,7 +313,8 @@ func GetVirtualMachineAvailabilitySetIDContextE(ctx context.Context, vmName stri
295313

296314
// extractVMAvailabilitySetID extracts the Availability Set ID from a Virtual Machine object.
297315
func extractVMAvailabilitySetID(vm *armcompute.VirtualMachine) (string, error) {
298-
if vm.Properties.AvailabilitySet == nil {
316+
if vm == nil || vm.Properties == nil || vm.Properties.AvailabilitySet == nil ||
317+
vm.Properties.AvailabilitySet.ID == nil {
299318
return "", nil
300319
}
301320

@@ -358,10 +377,15 @@ func GetVirtualMachineImageContextE(ctx context.Context, vmName string, resGroup
358377
// extractVMImage extracts the Image reference from a Virtual Machine object.
359378
// For custom images where Publisher/Offer/SKU/Version may be nil, empty strings are returned.
360379
func extractVMImage(vm *armcompute.VirtualMachine) *VMImage {
361-
ref := vm.Properties.StorageProfile.ImageReference
362-
363380
img := &VMImage{}
364381

382+
if vm == nil || vm.Properties == nil || vm.Properties.StorageProfile == nil ||
383+
vm.Properties.StorageProfile.ImageReference == nil {
384+
return img
385+
}
386+
387+
ref := vm.Properties.StorageProfile.ImageReference
388+
365389
if ref.Publisher != nil {
366390
img.Publisher = *ref.Publisher
367391
}
@@ -423,6 +447,11 @@ func GetSizeOfVirtualMachineContextE(ctx context.Context, vmName string, resGrou
423447

424448
// extractVMSize extracts the VM size from a Virtual Machine object.
425449
func extractVMSize(vm *armcompute.VirtualMachine) armcompute.VirtualMachineSizeTypes {
450+
if vm == nil || vm.Properties == nil || vm.Properties.HardwareProfile == nil ||
451+
vm.Properties.HardwareProfile.VMSize == nil {
452+
return ""
453+
}
454+
426455
return *vm.Properties.HardwareProfile.VMSize
427456
}
428457

@@ -470,11 +499,15 @@ func GetVirtualMachineTagsContextE(ctx context.Context, vmName string, resGroupN
470499
func extractVMTags(vm *armcompute.VirtualMachine) map[string]string {
471500
tags := make(map[string]string)
472501

473-
if vm.Tags == nil {
502+
if vm == nil || vm.Tags == nil {
474503
return tags
475504
}
476505

477506
for k, v := range vm.Tags {
507+
if v == nil {
508+
continue
509+
}
510+
478511
tags[k] = *v
479512
}
480513

@@ -544,6 +577,10 @@ func listVirtualMachineNames(ctx context.Context, client *armcompute.VirtualMach
544577
}
545578

546579
for _, v := range page.Value {
580+
if v == nil || v.Name == nil {
581+
continue
582+
}
583+
547584
vmDetails = append(vmDetails, *v.Name)
548585
}
549586
}
@@ -615,6 +652,10 @@ func listVirtualMachineProperties(ctx context.Context, client *armcompute.Virtua
615652
}
616653

617654
for _, v := range page.Value {
655+
if v == nil || v.Name == nil || v.Properties == nil {
656+
continue
657+
}
658+
618659
vmDetails[*v.Name] = *v.Properties
619660
}
620661
}
@@ -633,6 +674,11 @@ type Instance struct {
633674

634675
// GetVirtualMachineInstanceSize gets the size of the Virtual Machine.
635676
func (vm *Instance) GetVirtualMachineInstanceSize() armcompute.VirtualMachineSizeTypes {
677+
if vm == nil || vm.VirtualMachine == nil || vm.Properties == nil ||
678+
vm.Properties.HardwareProfile == nil || vm.Properties.HardwareProfile.VMSize == nil {
679+
return ""
680+
}
681+
636682
return *vm.Properties.HardwareProfile.VMSize
637683
}
638684

modules/azure/loadbalancer.go

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ func GetLoadBalancerWithClient(ctx context.Context, client *armnetwork.LoadBalan
271271
// ExtractLoadBalancerFrontendIPConfigNames gets a list of the Frontend IP Configuration Names
272272
// from a Load Balancer.
273273
func ExtractLoadBalancerFrontendIPConfigNames(lb *armnetwork.LoadBalancer) []string {
274-
if lb.Properties == nil {
274+
if lb == nil || lb.Properties == nil {
275275
return nil
276276
}
277277

@@ -284,9 +284,11 @@ func ExtractLoadBalancerFrontendIPConfigNames(lb *armnetwork.LoadBalancer) []str
284284
configNames := make([]string, 0, len(feConfigs))
285285

286286
for _, config := range feConfigs {
287-
if config.Name != nil {
288-
configNames = append(configNames, *config.Name)
287+
if config == nil || config.Name == nil {
288+
continue
289289
}
290+
291+
configNames = append(configNames, *config.Name)
290292
}
291293

292294
return configNames
@@ -296,33 +298,34 @@ func ExtractLoadBalancerFrontendIPConfigNames(lb *armnetwork.LoadBalancer) []str
296298
// specified Frontend IP Configuration. For public IPs it requires a PublicIPAddressesClient
297299
// to resolve the public IP address.
298300
func GetIPOfLoadBalancerFrontendIPConfigWithClient(ctx context.Context, feConfig *armnetwork.FrontendIPConfiguration, pipClient *armnetwork.PublicIPAddressesClient, resourceGroupName string) (string, LoadBalancerIPType, error) {
299-
if feConfig.Properties == nil {
301+
if feConfig == nil || feConfig.Properties == nil {
300302
return "", NoIP, errors.New("frontend IP configuration has nil properties")
301303
}
302304

303305
feProps := feConfig.Properties
304306

305-
if feProps.PublicIPAddress != nil && feProps.PublicIPAddress.ID != nil {
306-
pipName := GetNameFromResourceID(*feProps.PublicIPAddress.ID)
307-
308-
ipValue, err := GetPublicIPAddressWithClient(ctx, pipClient, resourceGroupName, pipName)
309-
if err != nil {
310-
return "", NoIP, err
307+
pip := feProps.PublicIPAddress
308+
if pip == nil || pip.ID == nil {
309+
if feProps.PrivateIPAddress == nil {
310+
return "", NoIP, errors.New("frontend IP configuration has no private or public IP address assigned")
311311
}
312312

313-
ip, err := ExtractIPOfPublicIPAddress(ipValue)
314-
if err != nil {
315-
return "", NoIP, err
316-
}
313+
return *feProps.PrivateIPAddress, PrivateIP, nil
314+
}
315+
316+
pipName := GetNameFromResourceID(*pip.ID)
317317

318-
return ip, PublicIP, nil
318+
ipValue, err := GetPublicIPAddressWithClient(ctx, pipClient, resourceGroupName, pipName)
319+
if err != nil {
320+
return "", NoIP, err
319321
}
320322

321-
if feProps.PrivateIPAddress == nil {
322-
return "", NoIP, errors.New("frontend IP configuration has no private or public IP address assigned")
323+
ip, err := ExtractIPOfPublicIPAddress(ipValue)
324+
if err != nil {
325+
return "", NoIP, err
323326
}
324327

325-
return *feProps.PrivateIPAddress, PrivateIP, nil
328+
return ip, PublicIP, nil
326329
}
327330

328331
// GetLoadBalancerClientContextE gets a new Load Balancer client in the specified Azure Subscription.

modules/azure/networkinterface.go

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,36 @@ func GetNetworkInterfacePublicIPsContextE(ctx context.Context, nicName string, r
133133
return publicIPs, err
134134
}
135135

136-
// Get the Public IPs from each configuration available
136+
if nic == nil || nic.Properties == nil {
137+
return publicIPs, nil
138+
}
139+
140+
// Get the Public IPs from each configuration available.
141+
// Not failing on individual errors as this is an optimistic accumulator —
142+
// it collects what it can and skips configurations that fail.
137143
for _, IPConfiguration := range nic.Properties.IPConfigurations {
138-
// Iterate each config, for successful configurations check for a Public Address reference.
139-
// Not failing on errors as this is an optimistic accumulator.
144+
if IPConfiguration == nil || IPConfiguration.Name == nil {
145+
continue
146+
}
147+
140148
nicConfig, err := GetNetworkInterfaceConfigurationContextE(ctx, nicName, *IPConfiguration.Name, resGroupName, subscriptionID)
141-
if err == nil {
142-
if nicConfig.Properties.PublicIPAddress != nil {
143-
publicAddressID := GetNameFromResourceID(*nicConfig.Properties.PublicIPAddress.ID)
144-
145-
publicIP, err := GetIPOfPublicIPAddressByNameContextE(ctx, publicAddressID, resGroupName, subscriptionID)
146-
if err == nil {
147-
publicIPs = append(publicIPs, publicIP)
148-
}
149-
}
149+
if err != nil {
150+
continue
151+
}
152+
153+
if nicConfig == nil || nicConfig.Properties == nil || nicConfig.Properties.PublicIPAddress == nil ||
154+
nicConfig.Properties.PublicIPAddress.ID == nil {
155+
continue
150156
}
157+
158+
publicAddressID := GetNameFromResourceID(*nicConfig.Properties.PublicIPAddress.ID)
159+
160+
publicIP, err := GetIPOfPublicIPAddressByNameContextE(ctx, publicAddressID, resGroupName, subscriptionID)
161+
if err != nil {
162+
continue
163+
}
164+
165+
publicIPs = append(publicIPs, publicIP)
151166
}
152167

153168
return publicIPs, nil
@@ -234,16 +249,18 @@ func GetNetworkInterfaceWithClient(ctx context.Context, client *armnetwork.Inter
234249

235250
// ExtractNetworkInterfacePrivateIPs gets a list of the Private IPs from a Network Interface.
236251
func ExtractNetworkInterfacePrivateIPs(nic *armnetwork.Interface) []string {
237-
if nic.Properties == nil {
252+
if nic == nil || nic.Properties == nil {
238253
return nil
239254
}
240255

241256
privateIPs := make([]string, 0, len(nic.Properties.IPConfigurations))
242257

243258
for _, ipConfig := range nic.Properties.IPConfigurations {
244-
if ipConfig.Properties != nil && ipConfig.Properties.PrivateIPAddress != nil {
245-
privateIPs = append(privateIPs, *ipConfig.Properties.PrivateIPAddress)
259+
if ipConfig == nil || ipConfig.Properties == nil || ipConfig.Properties.PrivateIPAddress == nil {
260+
continue
246261
}
262+
263+
privateIPs = append(privateIPs, *ipConfig.Properties.PrivateIPAddress)
247264
}
248265

249266
return privateIPs

modules/azure/nsg.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ func collectDefaultSecurityRules(ctx context.Context, client *armnetwork.Default
214214
}
215215

216216
for _, rule := range page.Value {
217+
if rule == nil {
218+
continue
219+
}
220+
217221
rules = append(rules, convertToNsgRuleSummary(rule.Name, rule.Properties))
218222
}
219223
}
@@ -234,6 +238,10 @@ func collectCustomSecurityRules(ctx context.Context, client *armnetwork.Security
234238
}
235239

236240
for _, rule := range page.Value {
241+
if rule == nil {
242+
continue
243+
}
244+
237245
rules = append(rules, convertToNsgRuleSummary(rule.Name, rule.Properties))
238246
}
239247
}

modules/azure/publicaddress.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ func CheckPublicDNSNameAvailabilityContextE(ctx context.Context, location string
137137
return false, err
138138
}
139139

140+
if res.Available == nil {
141+
return false, nil
142+
}
143+
140144
return *res.Available, nil
141145
}
142146

@@ -175,6 +179,10 @@ func GetPublicIPAddressWithClient(ctx context.Context, client *armnetwork.Public
175179

176180
// ExtractIPOfPublicIPAddress gets the IP string from a PublicIPAddress.
177181
func ExtractIPOfPublicIPAddress(pip *armnetwork.PublicIPAddress) (string, error) {
182+
if pip == nil {
183+
return "", fmt.Errorf("public IP address is nil")
184+
}
185+
178186
if pip.Properties == nil || pip.Properties.IPAddress == nil {
179187
name := "<unknown>"
180188
if pip.Name != nil {

modules/azure/recoveryservices.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func GetBackupPolicyListWithClient(ctx context.Context, client *armrecoveryservi
234234
}
235235

236236
for _, v := range page.Value {
237-
if v.Name == nil {
237+
if v == nil || v.Name == nil {
238238
continue
239239
}
240240

@@ -262,9 +262,16 @@ func GetBackupProtectedVMListWithClient(ctx context.Context, client *armrecovery
262262
}
263263

264264
for _, item := range page.Value {
265-
if vmItem, ok := item.Properties.(*armrecoveryservicesbackup.AzureIaaSComputeVMProtectedItem); ok {
266-
vmList[*vmItem.FriendlyName] = *vmItem
265+
if item == nil || item.Properties == nil {
266+
continue
267267
}
268+
269+
vmItem, ok := item.Properties.(*armrecoveryservicesbackup.AzureIaaSComputeVMProtectedItem)
270+
if !ok || vmItem == nil || vmItem.FriendlyName == nil {
271+
continue
272+
}
273+
274+
vmList[*vmItem.FriendlyName] = *vmItem
268275
}
269276
}
270277

0 commit comments

Comments
 (0)