Skip to content

Commit dab7a80

Browse files
matyang22matyang222
andauthored
Gateway Load Balancer Cross tenant issue fix (#15195)
* fix * name fix * put await next to create update Co-authored-by: matyang222 <[email protected]>
1 parent f5899ca commit dab7a80

File tree

4 files changed

+91
-5
lines changed

4 files changed

+91
-5
lines changed

src/Network/Network/Generated/LoadBalancer/NewAzureRMLoadBalancerCommand.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,37 @@ public override void Execute()
247247
}
248248
}
249249

250+
List<string> resourceIdsRequiringAuthToken = new List<string>();
251+
Dictionary<string, List<string>> auxAuthHeader = null;
252+
253+
// Get aux token for each gateway lb references
254+
foreach (FrontendIPConfiguration frontend in vLoadBalancerModel.FrontendIPConfigurations)
255+
{
256+
if (frontend.GatewayLoadBalancer != null)
257+
{
258+
//Get the aux header for the remote vnet
259+
resourceIdsRequiringAuthToken.Add(frontend.GatewayLoadBalancer.Id);
260+
}
261+
}
262+
263+
if (resourceIdsRequiringAuthToken.Count > 0)
264+
{
265+
var auxHeaderDictionary = GetAuxilaryAuthHeaderFromResourceIds(resourceIdsRequiringAuthToken);
266+
if (auxHeaderDictionary != null && auxHeaderDictionary.Count > 0)
267+
{
268+
auxAuthHeader = new Dictionary<string, List<string>>(auxHeaderDictionary);
269+
}
270+
}
271+
272+
250273
ConfirmAction(
251274
Force.IsPresent,
252275
string.Format(Properties.Resources.OverwritingResource, Name),
253276
Properties.Resources.CreatingResourceMessage,
254277
Name,
255278
() =>
256279
{
257-
this.NetworkClient.NetworkManagementClient.LoadBalancers.CreateOrUpdate(this.ResourceGroupName, this.Name, vLoadBalancerModel);
280+
this.NetworkClient.NetworkManagementClient.LoadBalancers.CreateOrUpdateWithHttpMessagesAsync(this.ResourceGroupName, this.Name, vLoadBalancerModel, auxAuthHeader).GetAwaiter().GetResult();
258281
var getLoadBalancer = this.NetworkClient.NetworkManagementClient.LoadBalancers.Get(this.ResourceGroupName, this.Name);
259282
var psLoadBalancer = NetworkResourceManagerProfile.Mapper.Map<PSLoadBalancer>(getLoadBalancer);
260283
psLoadBalancer.ResourceGroupName = this.ResourceGroupName;

src/Network/Network/Generated/LoadBalancer/SetAzureRMLoadBalancerCommand.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,30 @@ public override void Execute()
128128
var vLoadBalancerModel = NetworkResourceManagerProfile.Mapper.Map<MNM.LoadBalancer>(this.LoadBalancer);
129129
vLoadBalancerModel.Tags = TagsConversionHelper.CreateTagDictionary(this.LoadBalancer.Tag, validate: true);
130130

131+
List<string> resourceIds = new List<string>();
132+
Dictionary<string, List<string>> auxAuthHeader = null;
133+
134+
// Get aux token for each gateway lb references
135+
foreach (FrontendIPConfiguration frontend in vLoadBalancerModel.FrontendIPConfigurations)
136+
{
137+
if (frontend.GatewayLoadBalancer != null)
138+
{
139+
//Get the aux header for the remote vnet
140+
resourceIds.Add(frontend.GatewayLoadBalancer.Id);
141+
}
142+
}
143+
144+
if (resourceIds.Count > 0)
145+
{
146+
var auxHeaderDictionary = GetAuxilaryAuthHeaderFromResourceIds(resourceIds);
147+
if (auxHeaderDictionary != null && auxHeaderDictionary.Count > 0)
148+
{
149+
auxAuthHeader = new Dictionary<string, List<string>>(auxHeaderDictionary);
150+
}
151+
}
152+
131153
// Execute the PUT LoadBalancer call
132-
this.NetworkClient.NetworkManagementClient.LoadBalancers.CreateOrUpdate(this.LoadBalancer.ResourceGroupName, this.LoadBalancer.Name, vLoadBalancerModel);
154+
this.NetworkClient.NetworkManagementClient.LoadBalancers.CreateOrUpdateWithHttpMessagesAsync(this.LoadBalancer.ResourceGroupName, this.LoadBalancer.Name, vLoadBalancerModel, auxAuthHeader).GetAwaiter().GetResult();
133155

134156
var getLoadBalancer = this.NetworkClient.NetworkManagementClient.LoadBalancers.Get(this.LoadBalancer.ResourceGroupName, this.LoadBalancer.Name);
135157
var psLoadBalancer = NetworkResourceManagerProfile.Mapper.Map<PSLoadBalancer>(getLoadBalancer);

src/Network/Network/NetworkInterface/NewAzureNetworkInterfaceCommand.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,13 +437,35 @@ private PSNetworkInterface CreateNetworkInterface()
437437
networkInterface.NetworkSecurityGroup.Id = this.NetworkSecurityGroupId;
438438
}
439439

440+
List<string> resourceIdsRequiringAuthToken = new List<string>();
441+
Dictionary<string, List<string>> auxAuthHeader = null;
442+
443+
// Get aux token for each gateway lb references
444+
foreach (var ipConfiguration in networkInterface.IpConfigurations)
445+
{
446+
if (ipConfiguration.GatewayLoadBalancer != null)
447+
{
448+
//Get the aux header for the remote vnet
449+
resourceIdsRequiringAuthToken.Add(ipConfiguration.GatewayLoadBalancer.Id);
450+
}
451+
}
452+
453+
if (resourceIdsRequiringAuthToken.Count > 0)
454+
{
455+
var auxHeaderDictionary = GetAuxilaryAuthHeaderFromResourceIds(resourceIdsRequiringAuthToken);
456+
if (auxHeaderDictionary != null && auxHeaderDictionary.Count > 0)
457+
{
458+
auxAuthHeader = new Dictionary<string, List<string>>(auxHeaderDictionary);
459+
}
460+
}
461+
440462
var networkInterfaceModel = NetworkResourceManagerProfile.Mapper.Map<MNM.NetworkInterface>(networkInterface);
441463

442464
this.NullifyApplicationSecurityGroupIfAbsent(networkInterfaceModel);
443465

444466
networkInterfaceModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);
445467

446-
this.NetworkInterfaceClient.CreateOrUpdate(this.ResourceGroupName, this.Name, networkInterfaceModel);
468+
this.NetworkInterfaceClient.CreateOrUpdateWithHttpMessagesAsync(this.ResourceGroupName, this.Name, networkInterfaceModel, auxAuthHeader).GetAwaiter().GetResult();
447469

448470
var getNetworkInterface = this.GetNetworkInterface(this.ResourceGroupName, this.Name);
449471

src/Network/Network/NetworkInterface/SetAzureNetworkInterfaceCommand.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
1818
using Microsoft.Azure.Management.Network;
1919
using System;
20+
using System.Collections.Generic;
2021
using System.Management.Automation;
2122
using MNM = Microsoft.Azure.Management.Network.Models;
2223

@@ -43,14 +44,32 @@ public override void Execute()
4344
throw new ArgumentException(Microsoft.Azure.Commands.Network.Properties.Resources.ResourceNotFound);
4445
}
4546

46-
// Verify if PublicIpAddress is empty
47+
List<string> resourceIdsRequiringAuthToken = new List<string>();
48+
Dictionary<string, List<string>> auxAuthHeader = null;
49+
4750
foreach (var ipconfig in NetworkInterface.IpConfigurations)
4851
{
52+
// Verify if PublicIpAddress is empty
4953
if (ipconfig.PublicIpAddress != null &&
5054
string.IsNullOrEmpty(ipconfig.PublicIpAddress.Id))
5155
{
5256
ipconfig.PublicIpAddress = null;
5357
}
58+
59+
if (ipconfig.GatewayLoadBalancer != null)
60+
{
61+
//Get the aux header for the remote vnet
62+
resourceIdsRequiringAuthToken.Add(ipconfig.GatewayLoadBalancer.Id);
63+
}
64+
}
65+
66+
if (resourceIdsRequiringAuthToken.Count > 0)
67+
{
68+
var auxHeaderDictionary = GetAuxilaryAuthHeaderFromResourceIds(resourceIdsRequiringAuthToken);
69+
if (auxHeaderDictionary != null && auxHeaderDictionary.Count > 0)
70+
{
71+
auxAuthHeader = new Dictionary<string, List<string>>(auxHeaderDictionary);
72+
}
5473
}
5574

5675
// Map to the sdk object
@@ -60,7 +79,7 @@ public override void Execute()
6079

6180
networkInterfaceModel.Tags = TagsConversionHelper.CreateTagDictionary(this.NetworkInterface.Tag, validate: true);
6281

63-
this.NetworkInterfaceClient.CreateOrUpdate(this.NetworkInterface.ResourceGroupName, this.NetworkInterface.Name, networkInterfaceModel);
82+
this.NetworkInterfaceClient.CreateOrUpdateWithHttpMessagesAsync(this.NetworkInterface.ResourceGroupName, this.NetworkInterface.Name, networkInterfaceModel, auxAuthHeader).GetAwaiter().GetResult();
6483

6584
var getNetworkInterface = this.GetNetworkInterface(this.NetworkInterface.ResourceGroupName, this.NetworkInterface.Name);
6685
WriteObject(getNetworkInterface);

0 commit comments

Comments
 (0)