diff --git a/src/ApiService/ApiService/Functions/TimerProxy.cs b/src/ApiService/ApiService/Functions/TimerProxy.cs index a230101a6..c90b6d3d1 100644 --- a/src/ApiService/ApiService/Functions/TimerProxy.cs +++ b/src/ApiService/ApiService/Functions/TimerProxy.cs @@ -68,9 +68,9 @@ public class TimerProxy { var subnet = await network.GetSubnet(); var vnet = await network.GetVnet(); if (subnet != null && vnet != null) { - var error = nsgOpertions.AssociateSubnet(region, vnet, subnet); - if (error != null) { - _logger.Error($"Failed to associate NSG and subnet due to {error} in region {region}"); + var result = await nsgOpertions.AssociateSubnet(region, vnet, subnet); + if (!result.OkV) { + _logger.Error($"Failed to associate NSG and subnet due to {result.ErrorV} in region {region}"); } } } diff --git a/src/ApiService/ApiService/onefuzzlib/NsgOperations.cs b/src/ApiService/ApiService/onefuzzlib/NsgOperations.cs index 561c3c0e4..a8d56552f 100644 --- a/src/ApiService/ApiService/onefuzzlib/NsgOperations.cs +++ b/src/ApiService/ApiService/onefuzzlib/NsgOperations.cs @@ -5,7 +5,7 @@ using Azure.ResourceManager.Network; namespace Microsoft.OneFuzz.Service { public interface INsgOperations { Async.Task GetNsg(string name); - public Async.Task AssociateSubnet(string name, VirtualNetworkResource vnet, SubnetResource subnet); + public Async.Task> AssociateSubnet(string name, VirtualNetworkResource vnet, SubnetResource subnet); IAsyncEnumerable ListNsgs(); bool OkToDelete(HashSet active_regions, string nsg_region, string nsg_name); Async.Task StartDeleteNsg(string name); @@ -25,25 +25,29 @@ namespace Microsoft.OneFuzz.Service { _logTracer = logTracer; } - public async Async.Task AssociateSubnet(string name, VirtualNetworkResource vnet, SubnetResource subnet) { + public async Async.Task> AssociateSubnet(string name, VirtualNetworkResource vnet, SubnetResource subnet) { var nsg = await GetNsg(name); if (nsg == null) { - return new Error(ErrorCode.UNABLE_TO_FIND, new[] { $"cannot associate subnet. nsg {name} not found" }); + return OneFuzzResult.Error(new Error(ErrorCode.UNABLE_TO_FIND, + new[] { $"cannot associate subnet. nsg {name} not found" })); } if (nsg.Data.Location != vnet.Data.Location) { - return new Error(ErrorCode.UNABLE_TO_UPDATE, new[] { $"subnet and nsg have to be in the same region. nsg {nsg.Data.Name} {nsg.Data.Location}, subnet: {subnet.Data.Name} {subnet.Data}" }); + return OneFuzzResult.Error(new Error(ErrorCode.UNABLE_TO_UPDATE, + new[] { + $"subnet and nsg have to be in the same region. nsg {nsg.Data.Name} {nsg.Data.Location}, subnet: {subnet.Data.Name} {subnet.Data}" + })); } if (subnet.Data.NetworkSecurityGroup != null && subnet.Data.NetworkSecurityGroup.Id == nsg.Id) { _logTracer.Info($"Subnet {subnet.Data.Name} and NSG {name} already associated, not updating"); - return null; + return OneFuzzResult.Ok(true); } subnet.Data.NetworkSecurityGroup = nsg.Data; var result = await vnet.GetSubnets().CreateOrUpdateAsync(WaitUntil.Started, subnet.Data.Name, subnet.Data); - return null; + return OneFuzzResult.Ok(true); } public async Async.Task DissociateNic(Nsg nsg, NetworkInterfaceResource nic) {