Skip to content

Commit 224effc

Browse files
Fixing Set-AzNetworkRuleSet and adding TrustedServiceAccess (Azure#18018)
* Fixing Set-AzNetworkRuleSet and adding TrustedServiceAccess * Fixing tests * pushing recording * Fixing pipelines * Fix ChangeLog * Fixing pipelines
1 parent 7195e34 commit 224effc

File tree

10 files changed

+1047
-802
lines changed

10 files changed

+1047
-802
lines changed

src/ServiceBus/ServiceBus.Test/ScenarioTests/NetworkRuleSetTests.ps1

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Tests New Parameter for ServiceBus Namespace Create List Remove operations.
2020
function NetworkRuleSetTests {
2121
# Setup
2222

23+
#Customer can use this cmdlet to
24+
#Set default action, trustedservice, publicnetworkaccess
25+
2326
$location = Get-Location
2427
$resourceGroupName = getAssetName "RSG"
2528
$namespaceName = getAssetName "ServiceBus-Namespace-"
@@ -92,11 +95,19 @@ function NetworkRuleSetTests {
9295
Assert-AreEqual $setResult.IpRules.Count 3 "Set - IPRules count did not matched"
9396

9497
# Set-AzServiceBusNetworkRuleSet with parameters
95-
$setResult = Set-AzServiceBusNetworkRuleSet -ResourceGroup $resourceGroupName -Name $namespaceName2 -IPRule $setResult.IpRules -VirtualNetworkRule $setResult.VirtualNetworkRules -DefaultAction "Allow" -PublicNetworkAccess "Disabled"
98+
$setResult = Set-AzServiceBusNetworkRuleSet -ResourceGroup $resourceGroupName -Name $namespaceName2 -DefaultAction "Allow" -PublicNetworkAccess "Disabled" -TrustedServiceAccessEnabled
99+
Assert-AreEqual $setResult.VirtualNetworkRules.Count 3 "Set -VirtualNetworkRules count did not matched"
100+
Assert-AreEqual $setResult.IpRules.Count 3 "Set - IPRules count did not matched"
101+
Assert-AreEqual $setResult.PublicNetworkAccess "Disabled"
102+
Assert-AreEqual $setResult.DefaultAction "Allow"
103+
Assert-True {$setResult.TrustedServiceAccessEnabled}
104+
105+
$setResult = Set-AzServiceBusNetworkRuleSet -ResourceGroup $resourceGroupName -Name $namespaceName2 -IPRule $setResult.IpRules -VirtualNetworkRule $setResult.VirtualNetworkRules
96106
Assert-AreEqual $setResult.VirtualNetworkRules.Count 3 "Set -VirtualNetworkRules count did not matched"
97107
Assert-AreEqual $setResult.IpRules.Count 3 "Set - IPRules count did not matched"
98108
Assert-AreEqual $setResult.PublicNetworkAccess "Disabled"
99109
Assert-AreEqual $setResult.DefaultAction "Allow"
110+
Assert-True {$setResult.TrustedServiceAccessEnabled}
100111

101112
# Set-AzServiceBusNetworkRuleSet with Resource ID
102113
$setResult1 = Set-AzServiceBusNetworkRuleSet -ResourceGroup $resourceGroupName -Name $namespaceName2 -ResourceId $getResult.Id

src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusServiceTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ public void ServiceBusNameSpaceAuth_CURD_Tests()
4141
TestRunner.RunTestScript("ServiceBusNameSpaceAuthTests");
4242
}
4343

44-
[Fact(Skip = "Skip as current test framework does not support recording generated cmdlets.")]
44+
[Fact]
4545
[Trait(Category.AcceptanceType, Category.LiveOnly)]
4646
public void ServiceBusNameSpaceEncryption_CRUD()
4747
{
4848
TestRunner.RunTestScript("EncryptionTest");
4949
}
5050

51-
[Fact(Skip = "Skip as current test framework does not support recording generated cmdlets.")]
51+
[Fact]
5252
[Trait(Category.AcceptanceType, Category.LiveOnly)]
5353
public void ServiceBusNameSpaceMSI()
5454
{

src/ServiceBus/ServiceBus.Test/ScenarioTests/ServiceBusServiceTests.ps1

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ function MSITest{
249249
$namespace2 = getAssetName "Namespace2-"
250250
try{
251251

252-
$uad1 = Get-AzUserAssignedIdentity -ResourceGroupName $resourceGroupName -Name $msi1
253-
$uad2 = Get-AzUserAssignedIdentity -ResourceGroupName $resourceGroupName -Name $msi2
254-
$uad3 = Get-AzUserAssignedIdentity -ResourceGroupName $resourceGroupName -Name $msi3
252+
$uad1 = "/subscriptions/326100e2-f69d-4268-8503-075374f62b6e/resourceGroups/PS-Testing/providers/Microsoft.ManagedIdentity/userAssignedIdentities/PS-Testing-MSI1"
253+
$uad2 = "/subscriptions/326100e2-f69d-4268-8503-075374f62b6e/resourceGroups/PS-Testing/providers/Microsoft.ManagedIdentity/userAssignedIdentities/PS-Testing-MSI2"
254+
$uad3 = "/subscriptions/326100e2-f69d-4268-8503-075374f62b6e/resourceGroups/PS-Testing/providers/Microsoft.ManagedIdentity/userAssignedIdentities/PS-Testing-MSI3"
255255

256256
$namespace = New-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace1 -SkuName Standard -Location northeurope
257257
Assert-AreEqual $namespace.Name $namespace1
@@ -262,13 +262,13 @@ function MSITest{
262262
Assert-AreEqual $namespace.Sku.Name "Standard"
263263
Assert-AreEqual $namespace.IdentityType "SystemAssigned"
264264

265-
$namespace = Set-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace1 -IdentityType "UserAssigned" -IdentityId $uad1.Id,$uad2.Id
265+
$namespace = Set-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace1 -IdentityType "UserAssigned" -IdentityId $uad1,$uad2
266266
Assert-AreEqual $namespace.Name $namespace1
267267
Assert-AreEqual $namespace.Sku.Name "Standard"
268268
Assert-AreEqual $namespace.IdentityType "UserAssigned"
269269
Assert-True { $namespace.IdentityId.Count -eq 2 }
270270

271-
$namespace = Set-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace1 -IdentityType "SystemAssigned, UserAssigned" -IdentityId $uad1.Id,$uad2.Id
271+
$namespace = Set-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace1 -IdentityType "SystemAssigned, UserAssigned"
272272
Assert-AreEqual $namespace.Name $namespace1
273273
Assert-AreEqual $namespace.Sku.Name "Standard"
274274
Assert-AreEqual $namespace.IdentityType "SystemAssignedUserAssigned"
@@ -290,16 +290,16 @@ function EncryptionTest{
290290
$msi1 = "PS-Testing-MSI1"
291291
$msi2 = "PS-Testing-MSI2"
292292
$msi3 = "PS-Testing-MSI3"
293-
$kv1 = "PS-Testing-kv1"
294-
$kv2 = "PS-Testing-kv2"
295-
$kv1uri = "https://ps-testing-kv1.vault.azure.net/"
296-
$kv2uri = "https://ps-testing-kv2.vault.azure.net"
293+
$kv1 = "PS-Test-kv1"
294+
$kv2 = "PS-Test-kv2"
295+
$kv1uri = "https://ps-test-kv1.vault.azure.net/"
296+
$kv2uri = "https://ps-test-kv2.vault.azure.net"
297297
$namespace1 = getAssetName "Namespace1-"
298298
$namespace2 = getAssetName "Namespace2-"
299299

300-
$uad1 = Get-AzUserAssignedIdentity -ResourceGroupName $resourceGroupName -Name $msi1
301-
$uad2 = Get-AzUserAssignedIdentity -ResourceGroupName $resourceGroupName -Name $msi2
302-
$uad3 = Get-AzUserAssignedIdentity -ResourceGroupName $resourceGroupName -Name $msi3
300+
$uad1 = "/subscriptions/326100e2-f69d-4268-8503-075374f62b6e/resourceGroups/PS-Testing/providers/Microsoft.ManagedIdentity/userAssignedIdentities/PS-Testing-MSI1"
301+
$uad2 = "/subscriptions/326100e2-f69d-4268-8503-075374f62b6e/resourceGroups/PS-Testing/providers/Microsoft.ManagedIdentity/userAssignedIdentities/PS-Testing-MSI2"
302+
$uad3 = "/subscriptions/326100e2-f69d-4268-8503-075374f62b6e/resourceGroups/PS-Testing/providers/Microsoft.ManagedIdentity/userAssignedIdentities/PS-Testing-MSI3"
303303

304304
$namespace = New-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace2 -SkuName Premium -Location northeurope -IdentityType SystemAssigned
305305
Assert-AreEqual $namespace.Name $namespace2
@@ -318,17 +318,17 @@ function EncryptionTest{
318318
Assert-True { $namespace.EncryptionConfig.Count -eq 2 }
319319

320320

321-
$ec1 = New-AzServiceBusEncryptionConfig -KeyName key1 -KeyVaultUri $kv1uri -UserAssignedIdentity $uad1.Id
322-
$ec2 = New-AzServiceBusEncryptionConfig -KeyName key2 -KeyVaultUri $kv1uri -UserAssignedIdentity $uad1.Id
321+
$ec1 = New-AzServiceBusEncryptionConfig -KeyName key1 -KeyVaultUri $kv1uri -UserAssignedIdentity $uad1
322+
$ec2 = New-AzServiceBusEncryptionConfig -KeyName key2 -KeyVaultUri $kv1uri -UserAssignedIdentity $uad1
323323

324-
$namespace = New-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace1 -SkuName Premium -Location northeurope -IdentityType UserAssigned -IdentityId $uad1.Id,$uad2.Id -EncryptionConfig $ec1,$ec2
324+
$namespace = New-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace1 -SkuName Premium -Location northeurope -IdentityType UserAssigned -IdentityId $uad1,$uad2 -EncryptionConfig $ec1,$ec2
325325
Assert-AreEqual $namespace.Name $namespace1
326326
Assert-AreEqual $namespace.Sku.Name "Premium"
327327
Assert-AreEqual $namespace.IdentityType "UserAssigned"
328328
Assert-True { $namespace.IdentityId.Count -eq 2 }
329329
Assert-True { $namespace.EncryptionConfig.Count -eq 2 }
330330

331-
$ec3 = New-AzServiceBusEncryptionConfig -KeyName key1 -KeyVaultUri $kv2uri -UserAssignedIdentity $uad1.id
331+
$ec3 = New-AzServiceBusEncryptionConfig -KeyName key1 -KeyVaultUri $kv2uri -UserAssignedIdentity $uad1
332332
$namespace.EncryptionConfig += $ec3
333333

334334
$namespace = Set-AzServiceBusNamespace -ResourceGroupName $resourceGroupName -Name $namespace1 -EncryptionConfig $namespace.EncryptionConfig -Location northeurope

src/ServiceBus/ServiceBus.Test/SessionRecords/Microsoft.Azure.Commands.ServiceBus.Test.ScenarioTests.NetworkRuleSetTests/NetworkRuleSetCRUD.json

Lines changed: 909 additions & 754 deletions
Large diffs are not rendered by default.

src/ServiceBus/ServiceBus/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
-->
2121
## Upcoming Release
2222
* Fixed miscellaneous network rule set typos across module.
23+
* Add `TrustedServiceAccessEnabled` to `Set-AzServiceBusNetworkRuleSet`
2324

2425
## Version 1.8.1
2526
* Fixed that `New-AzServiceBusAuthorizationRuleSASToken` returns invalid token. [#12975]

src/ServiceBus/ServiceBus/Cmdlets/NetworkRuleSet/SetAzureServiceBusNetworkrule.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ public class SetAzureServiceBusNetworkrule : AzureServiceBusCmdletBase
4949
[PSDefaultValue(Value = "Enabled")]
5050
public string PublicNetworkAccess { get; set; }
5151

52-
[Parameter(Mandatory = true, ParameterSetName = NetworkRuleSetPropertiesParameterSet, Position = 2, HelpMessage = "List of IPRuleSet")]
53-
[ValidateNotNullOrEmpty]
52+
[Parameter(Mandatory = false, ParameterSetName = NetworkRuleSetPropertiesParameterSet, HelpMessage = "Trusted Service Access for NetworkRuleSet")]
53+
public SwitchParameter TrustedServiceAccessEnabled { get; set; }
54+
55+
[Parameter(Mandatory = false, ParameterSetName = NetworkRuleSetPropertiesParameterSet, Position = 2, HelpMessage = "List of IPRuleSet")]
5456
public PSNWRuleSetIpRulesAttributes[] IPRule { get; set; }
5557

56-
[Parameter(Mandatory = true, ParameterSetName = NetworkRuleSetPropertiesParameterSet, Position = 3, HelpMessage = "List of VirtualNetworkRules")]
57-
[ValidateNotNullOrEmpty]
58+
[Parameter(Mandatory = false, ParameterSetName = NetworkRuleSetPropertiesParameterSet, Position = 3, HelpMessage = "List of VirtualNetworkRules")]
5859
[Alias(AliasVirtualNetworkRule)]
5960
public PSNWRuleSetVirtualNetworkRulesAttributes[] VirtualNetworkRule { get; set; }
6061

@@ -78,15 +79,13 @@ public override void ExecuteCmdlet()
7879

7980
if (ParameterSetName.Equals(NetworkRuleSetPropertiesParameterSet))
8081
{
81-
PSNetworkRuleSetAttributes networkRuleSetAttributes = new PSNetworkRuleSetAttributes()
82-
{
83-
DefaultAction = DefaultAction,
84-
IpRules = IPRule.OfType<PSNWRuleSetIpRulesAttributes>().ToList(),
85-
VirtualNetworkRules = VirtualNetworkRule.OfType<PSNWRuleSetVirtualNetworkRulesAttributes>().ToList(),
86-
PublicNetworkAccess = PublicNetworkAccess
87-
};
88-
89-
WriteObject(Client.CreateOrUpdateNetworkRuleSet(ResourceGroupName, Name, networkRuleSetAttributes));
82+
WriteObject(Client.UpdateNetworkRuleSet(resourceGroupName: ResourceGroupName,
83+
namespaceName: Name,
84+
publicNetworkAccess: PublicNetworkAccess,
85+
trustedServiceAccessEnabled: TrustedServiceAccessEnabled,
86+
defaultAction: DefaultAction,
87+
iPRule: IPRule,
88+
virtualNetworkRule: VirtualNetworkRule));
9089
}
9190

9291
if (ParameterSetName.Equals(NetworkRuleSetInputObjectParameterSet))

src/ServiceBus/ServiceBus/Models/PSNetworkRuleSetAttributes.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public PSNetworkRuleSetAttributes(NetworkRuleSet networkRuleSet)
5151
Name = networkRuleSet.Name;
5252
Type = networkRuleSet.Type;
5353
PublicNetworkAccess = networkRuleSet.PublicNetworkAccess;
54+
TrustedServiceAccessEnabled = networkRuleSet.TrustedServiceAccessEnabled;
5455
}
5556

5657
/// <summary>
@@ -80,6 +81,11 @@ public PSNetworkRuleSetAttributes(NetworkRuleSet networkRuleSet)
8081
/// </summary>
8182
public string PublicNetworkAccess { get; set; }
8283

84+
/// <summary>
85+
/// Value that indicates whether Trusted Service Access is Enabled or not.
86+
/// </summary>
87+
public bool? TrustedServiceAccessEnabled { get; set; }
88+
8389
/// <summary>
8490
/// Gets or sets list VirtualNetwork Rules
8591
/// </summary>

src/ServiceBus/ServiceBus/ServiceBus.format.ps1xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@
198198
<Label>PublicNetworkAccess</Label>
199199
<PropertyName>PublicNetworkAccess</PropertyName>
200200
</ListItem>
201+
<ListItem>
202+
<Label>TrustedServiceAccessEnabled</Label>
203+
<PropertyName>TrustedServiceAccessEnabled</PropertyName>
204+
</ListItem>
201205
<ListItem>
202206
<Label>Id</Label>
203207
<PropertyName>Id</PropertyName>

src/ServiceBus/ServiceBus/Utilities/ServiceBusClient.cs

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@ public PSNamespaceAttributes UpdateNamespace(string resourceGroupName, string na
216216

217217
parameter.Identity.Type = FindIdentity(identityType);
218218

219-
if (parameter.Identity.Type == ManagedServiceIdentityType.None || parameter.Identity.Type == ManagedServiceIdentityType.SystemAssigned)
219+
/*if (parameter.Identity.Type == ManagedServiceIdentityType.None || parameter.Identity.Type == ManagedServiceIdentityType.SystemAssigned)
220220
{
221221
parameter.Identity.UserAssignedIdentities = null;
222-
}
222+
}*/
223223
}
224224

225225
if (identityIds != null)
@@ -236,9 +236,13 @@ public PSNamespaceAttributes UpdateNamespace(string resourceGroupName, string na
236236
{
237237
parameter.Identity.UserAssignedIdentities = UserAssignedIdentities;
238238
}
239-
if (parameter.Identity.Type == ManagedServiceIdentityType.None || parameter.Identity.Type == ManagedServiceIdentityType.SystemAssigned)
239+
if (identityIds.Length == 0)
240240
{
241-
throw new Exception("Please change -IdentityType to 'UserAssigned' or 'SystemAssigned, UserAssigned' if you want to add User Assigned Identities");
241+
parameter.Identity.UserAssignedIdentities = null;
242+
}
243+
else if (parameter.Identity.Type == ManagedServiceIdentityType.None || parameter.Identity.Type == ManagedServiceIdentityType.SystemAssigned)
244+
{
245+
throw new Exception("Please change -IdentityType to UserAssigned or 'SystemAssigned, UserAssigned' if you want to add User Assigned Identities");
242246
}
243247
}
244248

@@ -336,6 +340,11 @@ public PSNetworkRuleSetAttributes CreateOrUpdateNetworkRuleSet(string resourceGr
336340

337341
networkRuleSet.PublicNetworkAccess = psNetworkRuleSetAttributes.PublicNetworkAccess;
338342

343+
if(psNetworkRuleSetAttributes.TrustedServiceAccessEnabled != null)
344+
{
345+
networkRuleSet.TrustedServiceAccessEnabled = psNetworkRuleSetAttributes.TrustedServiceAccessEnabled;
346+
}
347+
339348
foreach (PSNWRuleSetIpRulesAttributes psiprules in psNetworkRuleSetAttributes.IpRules)
340349
{
341350
networkRuleSet.IpRules.Add(new NWRuleSetIpRules { Action = psiprules.Action, IpMask = psiprules.IpMask });
@@ -350,6 +359,55 @@ public PSNetworkRuleSetAttributes CreateOrUpdateNetworkRuleSet(string resourceGr
350359
return new PSNetworkRuleSetAttributes(response);
351360
}
352361

362+
public PSNetworkRuleSetAttributes UpdateNetworkRuleSet(string resourceGroupName, string namespaceName, string publicNetworkAccess, bool trustedServiceAccessEnabled, string defaultAction, PSNWRuleSetIpRulesAttributes[] iPRule, PSNWRuleSetVirtualNetworkRulesAttributes[] virtualNetworkRule)
363+
{
364+
NetworkRuleSet networkRuleSet = Client.Namespaces.GetNetworkRuleSet(resourceGroupName, namespaceName);
365+
366+
if(networkRuleSet == null)
367+
{
368+
networkRuleSet = new NetworkRuleSet();
369+
}
370+
371+
if(defaultAction != null)
372+
{
373+
networkRuleSet.DefaultAction = defaultAction;
374+
}
375+
376+
if (publicNetworkAccess != null)
377+
{
378+
networkRuleSet.PublicNetworkAccess = publicNetworkAccess;
379+
}
380+
381+
if (trustedServiceAccessEnabled == true)
382+
{
383+
networkRuleSet.TrustedServiceAccessEnabled = trustedServiceAccessEnabled;
384+
}
385+
386+
if (iPRule != null)
387+
{
388+
networkRuleSet.IpRules = new List<NWRuleSetIpRules>();
389+
390+
foreach (PSNWRuleSetIpRulesAttributes psiprules in iPRule)
391+
{
392+
networkRuleSet.IpRules.Add(new NWRuleSetIpRules { Action = psiprules.Action, IpMask = psiprules.IpMask });
393+
}
394+
}
395+
396+
if(virtualNetworkRule != null)
397+
{
398+
networkRuleSet.VirtualNetworkRules = new List<NWRuleSetVirtualNetworkRules>();
399+
400+
foreach (PSNWRuleSetVirtualNetworkRulesAttributes psvisrtualnetworkrules in virtualNetworkRule)
401+
{
402+
networkRuleSet.VirtualNetworkRules.Add(new NWRuleSetVirtualNetworkRules { Subnet = new Subnet { Id = psvisrtualnetworkrules.Subnet.Id }, IgnoreMissingVnetServiceEndpoint = psvisrtualnetworkrules.IgnoreMissingVnetServiceEndpoint });
403+
}
404+
}
405+
406+
var response = Client.Namespaces.CreateOrUpdateNetworkRuleSet(resourceGroupName, namespaceName, networkRuleSet);
407+
return new PSNetworkRuleSetAttributes(response);
408+
409+
}
410+
353411
#endregion
354412

355413
#region NameSpace AuthorizationRules

0 commit comments

Comments
 (0)