Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Az.Accounts] Fixed returning duplicate subscription ids. #19447

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/Accounts/Accounts.Test/AzureRMProfileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ public void SingleTenantSubscriptionListSucceed()

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void GetSubscriptionListByNameCorrect()
public void GetSubscriptionListByNameSameIdCorrect()
{
var tenants = new List<string> { DefaultTenant.ToString() };
var firstList = new List<string> { DefaultSubscription.ToString() };
Expand All @@ -514,6 +514,29 @@ public void GetSubscriptionListByNameCorrect()
client.TryGetSubscriptionListByName(DefaultTenant.ToString(),
MockSubscriptionClientFactory.GetSubscriptionNameFromId(DefaultSubscription.ToString()),
out subValueList);
Assert.Single(subValueList);
}


[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void GetSubscriptionListByNameCorrect()
{
var subId1 = "a11a11aa-aaaa-aaaa-aaaa-aaaa1111aaaa";
var subId2 = "aaaa11aa-aaaa-aaaa-aaaa-aaaa1111aaaa";

var tenants = new List<string> { DefaultTenant.ToString() };
var firstList = new List<string> { subId1 };
var secondList = new List<string> { subId2 };
var thirdList = firstList;
var fourthList = firstList;
Comment on lines +528 to +532
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be better if use more meaningful variable name here.

var client = SetupTestEnvironment(tenants, firstList, secondList, thirdList, fourthList);
var tenantResults = client.ListTenants();
Assert.Single(tenantResults);
IEnumerable<IAzureSubscription> subValueList;
client.TryGetSubscriptionListByName(DefaultTenant.ToString(),
"SameNameForGetSubscriptionByName",
out subValueList);
Assert.Equal(2, subValueList.Count());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public MockSubscriptionClientFactory()

public static string GetSubscriptionNameFromId(string id)
{
if(id == "a11a11aa-aaaa-aaaa-aaaa-aaaa1111aaaa" || id == "aaaa11aa-aaaa-aaaa-aaaa-aaaa1111aaaa")
{
return "SameNameForGetSubscriptionByName";
}
return "Sub-" + id;
}

Expand Down
8 changes: 3 additions & 5 deletions src/Accounts/Accounts/Az.Accounts.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Microsoft Corporation
#
# Generated on: 2022/9/2
# Generated on: 9/9/2022
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to update this file manually.

#

@{
Expand All @@ -12,7 +12,7 @@
# RootModule = ''

# Version number of this module.
ModuleVersion = '2.10.0'
ModuleVersion = '2.10.1'

# Supported PSEditions
CompatiblePSEditions = 'Core', 'Desktop'
Expand Down Expand Up @@ -146,9 +146,7 @@ PrivateData = @{
# IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = '* Supported returning all subscriptions with specified name while using ''Get-AzSubscription'' with parameter ''SubscriptionName''. [#19295]
* Fixed null reference exception when cmdlet uses AzureRestOperation [#18104]
* Updated survey message and settings'
ReleaseNotes = '* Fixed returning duplicate Ids for one subscription while using ''Get-AzSubscription'' with parameter ''SubscriptionName''. [#19427]'

# Prerelease string of this module
# Prerelease = ''
Expand Down
3 changes: 3 additions & 0 deletions src/Accounts/Accounts/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

## Upcoming Release

## Version 2.10.1
* Fixed returning duplicate Ids for one subscription while using `Get-AzSubscription` with parameter `SubscriptionName`. [#19427]
Comment on lines +23 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to update the version manually. Just add changelog content under Upcoming Release section is fine.


## Version 2.10.0
* Supported returning all subscriptions with specified name while using `Get-AzSubscription` with parameter `SubscriptionName`. [#19295]
* Fixed null reference exception when cmdlet uses AzureRestOperation [#18104]
Expand Down
27 changes: 23 additions & 4 deletions src/Accounts/Accounts/Models/RMProfileClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,30 @@ public bool TryGetSubscriptionByName(string tenantId, string subscriptionName, o
return subscription != null;
}

public bool TryGetSubscriptionListByName(string tenantId, string subscriptionName, out IEnumerable<IAzureSubscription> subscriptionList)
public bool TryGetSubscriptionListByName(string tenantId, string subscriptionName, out IEnumerable<IAzureSubscription> subscriptions)
{
subscriptionList = ListSubscriptions(tenantId);
subscriptionList = subscriptionList.Where(s => s.Name.Equals(subscriptionName, StringComparison.OrdinalIgnoreCase));
return subscriptionList.Any();
subscriptions = ListSubscriptions(tenantId).Where(s => s.Name.Equals(subscriptionName, StringComparison.OrdinalIgnoreCase));
List<IAzureSubscription> subscriptionList = new List<IAzureSubscription>();
HashSet<Guid> subscriptionIds = new HashSet<Guid>();
foreach(IAzureSubscription subscription in subscriptions)
{

if(subscription is PSAzureSubscription && subscription.GetTenant() != null
&& subscription.GetHomeTenant().Equals(subscription.GetTenant()) && subscriptionIds.Add(subscription.GetId()))
Copy link
Contributor

@wyunchi-ms wyunchi-ms Sep 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean !subscriptionIds.Contains(subscription.GetId()) here?

{
subscriptionList.Add(subscription);
}

}
foreach (IAzureSubscription subscription in subscriptions)
{
if (subscriptionIds.Add(subscription.GetId()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean Contains here?

{
subscriptionList.Add(subscription);
}
}
subscriptions = subscriptionList;
return subscriptions.Any();
}

private IAzureSubscription GetFirstSubscription(string tenantId)
Expand Down
4 changes: 2 additions & 2 deletions src/Accounts/Accounts/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:

[assembly: AssemblyVersion("2.10.0")]
[assembly: AssemblyFileVersion("2.10.0")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to update this file manually.

[assembly: AssemblyVersion("2.10.1")]
[assembly: AssemblyFileVersion("2.10.1")]
#if !SIGN
[assembly: InternalsVisibleTo("Microsoft.Azure.PowerShell.Cmdlets.Accounts.Test")]
#endif
Expand Down
80 changes: 63 additions & 17 deletions src/Accounts/Accounts/Utilities/CommandMappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,14 @@
"Remove-AzAttestationPolicySigner": {}
},
"Az.Automation": {
"Move-AzAutomationHybridRunbookWorker": {},
"Remove-AzAutomationHybridRunbookWorker": {},
"New-AzAutomationHybridRunbookWorker": {},
"Get-AzAutomationHybridRunbookWorker": {},
"Remove-AzAutomationHybridRunbookWorkerGroup": {},
"Set-AzAutomationHybridRunbookWorkerGroup": {},
"New-AzAutomationHybridRunbookWorkerGroup": {},
"Get-AzAutomationHybridRunbookWorkerGroup": {},
"Get-AzAutomationHybridWorkerGroup": {},
"Remove-AzAutomationHybridWorkerGroup": {},
"Get-AzAutomationJobOutputRecord": {},
Expand Down Expand Up @@ -5104,30 +5112,68 @@
"Set-AzSecurityAutomation": {}
},
"Az.SecurityInsights": {
"Get-AzSentinelAlertRuleAction": {},
"New-AzSentinelAlertRuleAction": {},
"Remove-AzSentinelAlertRuleAction": {},
"Update-AzSentinelAlertRuleAction": {},
"Get-AzSentinelAlertRule": {},
"New-AzSentinelAlertRule": {},
"Remove-AzSentinelAlertRule": {},
"Update-AzSentinelAlertRule": {},
"Get-AzSentinelAlertRuleAction": {},
"Get-AzSentinelAlertRuleTemplate": {},
"Get-AzSentinelAutomationRule": {},
"Get-AzSentinelBookmark": {},
"New-AzSentinelBookmark": {},
"Remove-AzSentinelBookmark": {},
"Update-AzSentinelBookmark": {},
"Get-AzSentinelBookmarkRelation": {},
"Get-AzSentinelDataConnector": {},
"New-AzSentinelDataConnector": {},
"Remove-AzSentinelDataConnector": {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to update this file manually.

"Update-AzSentinelDataConnector": {},
"Get-AzSentinelIncidentComment": {},
"New-AzSentinelIncidentComment": {},
"Get-AzSentinelEnrichment": {},
"Get-AzSentinelEntity": {},
"Get-AzSentinelEntityActivity": {},
"Get-AzSentinelEntityInsight": {},
"Get-AzSentinelEntityQuery": {},
"Get-AzSentinelEntityQueryTemplate": {},
"Get-AzSentinelEntityRelation": {},
"Get-AzSentinelEntityTimeline": {},
"Get-AzSentinelIncident": {},
"Get-AzSentinelIncidentAlert": {},
"Get-AzSentinelIncidentBookmark": {},
"Get-AzSentinelIncidentComment": {},
"Get-AzSentinelIncidentEntity": {},
"Get-AzSentinelIncidentRelation": {},
"Get-AzSentinelMetadata": {},
"Get-AzSentinelOnboardingState": {},
"Get-AzSentinelSetting": {},
"Get-AzSentinelThreatIntelligenceIndicator": {},
"Get-AzSentinelThreatIntelligenceIndicatorMetric": {},
"Invoke-AzSentinelThreatIntelligenceIndicatorQuery": {},
"New-AzSentinelAlertRule": {},
"New-AzSentinelAlertRuleAction": {},
"New-AzSentinelAutomationRule": {},
"New-AzSentinelBookmark": {},
"New-AzSentinelBookmarkRelation": {},
"New-AzSentinelDataConnector": {},
"New-AzSentinelEntityQuery": {},
"New-AzSentinelIncident": {},
"New-AzSentinelIncidentOwner": {},
"New-AzSentinelIncidentComment": {},
"New-AzSentinelIncidentRelation": {},
"New-AzSentinelIncidentTeam": {},
"New-AzSentinelOnboardingState": {},
"Remove-AzSentinelAlertRule": {},
"Remove-AzSentinelAlertRuleAction": {},
"Remove-AzSentinelAutomationRule": {},
"Remove-AzSentinelBookmark": {},
"Remove-AzSentinelBookmarkRelation": {},
"Remove-AzSentinelDataConnector": {},
"Remove-AzSentinelEntityQuery": {},
"Remove-AzSentinelIncident": {},
"Update-AzSentinelIncident": {}
"Remove-AzSentinelIncidentComment": {},
"Remove-AzSentinelIncidentRelation": {},
"Remove-AzSentinelOnboardingState": {},
"Test-AzSentinelDataConnectorCheckRequirement": {},
"Update-AzSentinelAlertRule": {},
"Update-AzSentinelAlertRuleAction": {},
"Update-AzSentinelAutomationRule": {},
"Update-AzSentinelBookmark": {},
"Update-AzSentinelBookmarkRelation": {},
"Update-AzSentinelDataConnector": {},
"Update-AzSentinelEntityQuery": {},
"Update-AzSentinelIncident": {},
"Update-AzSentinelIncidentComment": {},
"Update-AzSentinelIncidentRelation": {},
"Update-AzSentinelSetting": {}
},
"Az.ServiceBus": {
"New-AzServiceBusNamespace": {},
Expand Down
4 changes: 2 additions & 2 deletions src/Accounts/Authentication/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.10.0")]
[assembly: AssemblyFileVersion("2.10.0")]
[assembly: AssemblyVersion("2.10.1")]
[assembly: AssemblyFileVersion("2.10.1")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to update this file manually.

#if !SIGN
[assembly: InternalsVisibleTo("Microsoft.Azure.PowerShell.Authentication.Test")]
#endif
4 changes: 2 additions & 2 deletions src/Accounts/Authenticators/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.10.0")]
[assembly: AssemblyFileVersion("2.10.0")]
[assembly: AssemblyVersion("2.10.1")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to update this file manually.

[assembly: AssemblyFileVersion("2.10.1")]
2 changes: 1 addition & 1 deletion tools/Az/Az.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ DotNetFrameworkVersion = '4.7.2'
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @(@{ModuleName = 'Az.Accounts'; ModuleVersion = '2.10.0'; },
RequiredModules = @(@{ModuleName = 'Az.Accounts'; ModuleVersion = '2.10.1'; },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to update this file manually.

@{ModuleName = 'Az.Advisor'; RequiredVersion = '1.1.2'; },
@{ModuleName = 'Az.Aks'; RequiredVersion = '4.3.0'; },
@{ModuleName = 'Az.AnalysisServices'; RequiredVersion = '1.1.4'; },
Expand Down
4 changes: 2 additions & 2 deletions tools/AzPreview/AzPreview.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ DotNetFrameworkVersion = '4.7.2'
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @(@{ModuleName = 'Az.Accounts'; ModuleVersion = '2.10.0'; },
RequiredModules = @(@{ModuleName = 'Az.Accounts'; ModuleVersion = '2.10.1'; },
@{ModuleName = 'Az.ADDomainServices'; RequiredVersion = '0.2.0'; },
@{ModuleName = 'Az.Advisor'; RequiredVersion = '1.1.2'; },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to update this file manually.

@{ModuleName = 'Az.Aks'; RequiredVersion = '4.3.0'; },
Expand Down Expand Up @@ -172,7 +172,7 @@ RequiredModules = @(@{ModuleName = 'Az.Accounts'; ModuleVersion = '2.10.0'; },
@{ModuleName = 'Az.Resources'; RequiredVersion = '6.2.0'; },
@{ModuleName = 'Az.Search'; RequiredVersion = '0.8.0'; },
@{ModuleName = 'Az.Security'; RequiredVersion = '1.3.0'; },
@{ModuleName = 'Az.SecurityInsights'; RequiredVersion = '1.1.0'; },
@{ModuleName = 'Az.SecurityInsights'; RequiredVersion = '2.0.0'; },
@{ModuleName = 'Az.ServiceBus'; RequiredVersion = '1.11.0'; },
@{ModuleName = 'Az.ServiceFabric'; RequiredVersion = '3.1.0'; },
@{ModuleName = 'Az.ServiceLinker'; RequiredVersion = '0.1.0'; },
Expand Down
4 changes: 2 additions & 2 deletions tools/Docs/az-ps-latest.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pac0,[ps=true;customSource=https://www.powershellgallery.com/api/v2/]Az.Accounts,2.10.0
pac0,[ps=true;customSource=https://www.powershellgallery.com/api/v2/]Az.Accounts,2.10.1
pac1,[ps=true;customSource=https://www.powershellgallery.com/api/v2/]Az.ADDomainServices,0.2.0
pac2,[ps=true;customSource=https://www.powershellgallery.com/api/v2/]Az.Advisor,1.1.2
pac3,[ps=true;customSource=https://www.powershellgallery.com/api/v2/]Az.Aks,4.3.0
Expand Down Expand Up @@ -118,7 +118,7 @@ pac116,[ps=true;customSource=https://www.powershellgallery.com/api/v2/]Az.Resour
pac117,[ps=true;customSource=https://www.powershellgallery.com/api/v2/]Az.Resources,6.2.0
pac118,[ps=true;customSource=https://www.powershellgallery.com/api/v2/]Az.Search,0.8.0
pac119,[ps=true;customSource=https://www.powershellgallery.com/api/v2/]Az.Security,1.3.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to update this file manually.

pac120,[ps=true;customSource=https://www.powershellgallery.com/api/v2/]Az.SecurityInsights,1.1.0
pac120,[ps=true;customSource=https://www.powershellgallery.com/api/v2/]Az.SecurityInsights,2.0.0
pac121,[ps=true;customSource=https://www.powershellgallery.com/api/v2/]Az.ServiceBus,1.11.0
pac122,[ps=true;customSource=https://www.powershellgallery.com/api/v2/]Az.ServiceFabric,3.1.0
pac123,[ps=true;customSource=https://www.powershellgallery.com/api/v2/]Az.ServiceLinker,0.1.0
Expand Down
Loading