Skip to content

Commit

Permalink
Update subscription client to 2021-01-01
Browse files Browse the repository at this point in the history
  • Loading branch information
msJinLei committed Jun 29, 2021
1 parent 3976e02 commit 4c31073
Show file tree
Hide file tree
Showing 14 changed files with 187 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/Accounts/Accounts.Test/AzureRMProfileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
using Microsoft.Azure.Commands.Profile.Models;
using Microsoft.Azure.Commands.Profile.Test;
using Microsoft.Azure.Commands.ScenarioTest;
using Microsoft.Azure.Management.ResourceManager.Version2019_06_01.Models;
using Microsoft.Azure.Management.ResourceManager.Version2021_01_01.Models;
using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.Rest;
using Microsoft.Rest.Azure;
Expand Down Expand Up @@ -144,7 +144,7 @@ public void SpecifyTenantAndSubscriptionIdSucceed()
null,
false,
null);
Assert.Equal("2019-06-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal("2021-01-01", client.SubscriptionAndTenantClient.ApiVersion);
}

[Fact]
Expand Down Expand Up @@ -179,7 +179,7 @@ public void SubscriptionIdNotExist()
null,
false,
null));
Assert.Equal("2019-06-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal("2021-01-01", client.SubscriptionAndTenantClient.ApiVersion);
}

[Fact]
Expand Down
20 changes: 10 additions & 10 deletions src/Accounts/Accounts.Test/AzureRMProfileTestsForMultitenant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public void LoginByTenant()
false,
null);

Assert.Equal("2019-06-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal("2021-01-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal(tenantA, azureRmProfile.DefaultContext.Tenant.Id.ToString());
Assert.Equal(subscriptionA, azureRmProfile.DefaultContext.Subscription.Id.ToString());
}
Expand Down Expand Up @@ -344,7 +344,7 @@ public void LoginBySubscriptionInMultitenantsHomeFirst()
false,
null);

Assert.Equal("2019-06-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal("2021-01-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal(tenantA, azureRmProfile.DefaultContext.Tenant.Id.ToString());
Assert.Equal(subscriptionA, azureRmProfile.DefaultContext.Subscription.Id.ToString());
}
Expand Down Expand Up @@ -390,7 +390,7 @@ public void LoginBySubscriptionInMultitenantsHomeSecond()
false,
null);

Assert.Equal("2019-06-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal("2021-01-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal(tenantA, azureRmProfile.DefaultContext.Tenant.Id.ToString());
Assert.Equal(subscriptionA, azureRmProfile.DefaultContext.Subscription.Id.ToString());
}
Expand Down Expand Up @@ -434,7 +434,7 @@ public void LoginBySubscriptionInManagedByTenants()
false,
null);

Assert.Equal("2019-06-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal("2021-01-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal(tenantB, azureRmProfile.DefaultContext.Tenant.Id.ToString());
Assert.Equal(subscriptionC, azureRmProfile.DefaultContext.Subscription.Id.ToString());
}
Expand Down Expand Up @@ -477,7 +477,7 @@ public void LoginBySubscriptionTenant()
false,
null);

Assert.Equal("2019-06-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal("2021-01-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal(tenantA, azureRmProfile.DefaultContext.Tenant.Id.ToString());
Assert.Equal(subscriptionB, azureRmProfile.DefaultContext.Subscription.Id.ToString());
}
Expand Down Expand Up @@ -591,7 +591,7 @@ public void SetContextByValidTenant()
var client = GetProfileClient();
var context = client.SetCurrentContext(null, tenantA);

Assert.Equal("2019-06-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal("2021-01-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal(tenantA, context.Tenant.Id.ToString());
Assert.Equal(subscriptionA, context.Subscription.Id.ToString());
}
Expand Down Expand Up @@ -627,7 +627,7 @@ public void SetContextBySubscriptionIdInHomeTenant()
var client = GetProfileClient();
var context = client.SetCurrentContext(subscriptionA, null);

Assert.Equal("2019-06-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal("2021-01-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal(tenantA, context.Tenant.Id.ToString());
Assert.Equal(subscriptionA, context.Subscription.Id.ToString());
}
Expand Down Expand Up @@ -664,7 +664,7 @@ public void SetContextBySubscriptionNameInHomeTenant()
var client = GetProfileClient();
var context = client.SetCurrentContext(subscriptionName.ToString(), null);

Assert.Equal("2019-06-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal("2021-01-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal(tenantA, context.Tenant.Id.ToString());
Assert.Equal(subscriptionA, context.Subscription.Id.ToString());
}
Expand Down Expand Up @@ -699,7 +699,7 @@ public void SetContextBySubscriptionInManagedByTenants()
var client = GetProfileClient();
var context = client.SetCurrentContext(subscriptionC.ToString(), null);

Assert.Equal("2019-06-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal("2021-01-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal(tenantA, context.Tenant.Id.ToString());
Assert.Equal(subscriptionC, context.Subscription.Id.ToString());
}
Expand Down Expand Up @@ -735,7 +735,7 @@ public void SetContextBySubscriptionTenant()
var subscriptionName = (JObject.Parse(subscriptionListA[subscriptionB]))["displayName"];
var context = client.SetCurrentContext(subscriptionName.ToString(), tenantA);

Assert.Equal("2019-06-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal("2021-01-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal(tenantA, context.Tenant.Id.ToString());
Assert.Equal(subscriptionB, context.Subscription.Id.ToString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Management.ResourceManager.Version2019_06_01;
using Microsoft.Azure.Management.ResourceManager.Version2019_06_01.Models;
using Microsoft.Azure.Management.ResourceManager.Version2021_01_01;
using Microsoft.Azure.Management.ResourceManager.Version2021_01_01.Models;
using Microsoft.Rest.Azure;
using Moq;
using System;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Management.ResourceManager.Version2019_06_01;
using Microsoft.Azure.Management.ResourceManager.Version2019_06_01.Models;
using Microsoft.Azure.Management.ResourceManager.Version2021_01_01;
using Microsoft.Azure.Management.ResourceManager.Version2021_01_01.Models;
using Microsoft.Rest.Azure;
using Moq;
using System;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"Entries": [
{
"RequestUri": "/tenants?api-version=2021-01-01",
"EncodedRequestUri": "L3RlbmFudHM/YXBpLXZlcnNpb249MjAyMS0wMS0wMQ==",
"RequestMethod": "GET",
"RequestBody": "",
"RequestHeaders": {
"x-ms-client-request-id": [
"27447c0a-62f3-4ec5-a2ee-46d57196a6c5"
],
"Accept-Language": [
"en-US"
],
"User-Agent": [
"FxVersion/4.6.30015.01",
"OSName/Windows",
"OSVersion/Microsoft.Windows.10.0.19043.",
"Microsoft.Azure.Management.ResourceManager.Version2021.01.01.SubscriptionClient/1.0.0.0"
]
},
"ResponseHeaders": {
"Cache-Control": [
"no-cache"
],
"Pragma": [
"no-cache"
],
"x-ms-ratelimit-remaining-tenant-reads": [
"11999"
],
"x-ms-request-id": [
"aa195b95-77d4-41fe-81ae-041fde762974"
],
"x-ms-correlation-request-id": [
"aa195b95-77d4-41fe-81ae-041fde762974"
],
"x-ms-routing-request-id": [
"SOUTHEASTASIA:20210628T075523Z:aa195b95-77d4-41fe-81ae-041fde762974"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
],
"X-Content-Type-Options": [
"nosniff"
],
"Date": [
"Mon, 28 Jun 2021 07:55:23 GMT"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Expires": [
"-1"
],
"Content-Length": [
"140"
]
},
"ResponseBody": "{\r\n \"value\": [\r\n {\r\n \"id\": \"/tenants/54826b22-38d6-4fb2-bad9-b7b93a3e9c5a\",\r\n \"tenantId\": \"54826b22-38d6-4fb2-bad9-b7b93a3e9c5a\",\r\n \"tenantCategory\": \"Home\"\r\n }\r\n ]\r\n}",
"StatusCode": 200
},
{
"RequestUri": "/subscriptions?api-version=2021-01-01",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnM/YXBpLXZlcnNpb249MjAyMS0wMS0wMQ==",
"RequestMethod": "GET",
"RequestBody": "",
"RequestHeaders": {
"x-ms-client-request-id": [
"27447c0a-62f3-4ec5-a2ee-46d57196a6c5"
],
"Accept-Language": [
"en-US"
],
"User-Agent": [
"FxVersion/4.6.30015.01",
"OSName/Windows",
"OSVersion/Microsoft.Windows.10.0.19043.",
"Microsoft.Azure.Management.ResourceManager.Version2021.01.01.SubscriptionClient/1.0.0.0"
]
},
"ResponseHeaders": {
"Cache-Control": [
"no-cache"
],
"Pragma": [
"no-cache"
],
"x-ms-ratelimit-remaining-tenant-reads": [
"11999"
],
"x-ms-request-id": [
"c8cf462f-f2c0-4ef4-8dc3-aee3d36d3293"
],
"x-ms-correlation-request-id": [
"c8cf462f-f2c0-4ef4-8dc3-aee3d36d3293"
],
"x-ms-routing-request-id": [
"SOUTHEASTASIA:20210628T075524Z:c8cf462f-f2c0-4ef4-8dc3-aee3d36d3293"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
],
"X-Content-Type-Options": [
"nosniff"
],
"Date": [
"Mon, 28 Jun 2021 07:55:23 GMT"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Expires": [
"-1"
],
"Content-Length": [
"522"
]
},
"ResponseBody": "{\r\n \"value\": [\r\n {\r\n \"id\": \"/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590\",\r\n \"authorizationSource\": \"RoleBased\",\r\n \"managedByTenants\": [\r\n {\r\n \"tenantId\": \"2f4a9838-26b7-47ee-be60-ccc1fdec5953\"\r\n }\r\n ],\r\n \"tags\": {\r\n \"testTags\": \"testValue\"\r\n },\r\n \"subscriptionId\": \"0b1f6471-1bf0-4dda-aec3-cb9272f09590\",\r\n \"tenantId\": \"54826b22-38d6-4fb2-bad9-b7b93a3e9c5a\",\r\n \"displayName\": \"AzureSDKTest\",\r\n \"state\": \"Enabled\",\r\n \"subscriptionPolicies\": {\r\n \"locationPlacementId\": \"Internal_2014-09-01\",\r\n \"quotaId\": \"Internal_2014-09-01\",\r\n \"spendingLimit\": \"Off\"\r\n }\r\n }\r\n ],\r\n \"count\": {\r\n \"type\": \"Total\",\r\n \"value\": 1\r\n }\r\n}",
"StatusCode": 200
}
],
"Names": {},
"Variables": {
"SubscriptionId": "0b1f6471-1bf0-4dda-aec3-cb9272f09590"
}
}
2 changes: 1 addition & 1 deletion src/Accounts/Accounts.Test/SubscriptionClientSwitchTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
using Microsoft.Azure.Commands.Common.Authentication.Models;
using Microsoft.Azure.Commands.Profile.Test.Mocks;
using Microsoft.Azure.Commands.ScenarioTest;
using Microsoft.Azure.Management.ResourceManager.Version2019_06_01.Models;
using Microsoft.Azure.Management.ResourceManager.Version2021_01_01.Models;
using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.Rest.Azure;
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
Expand Down
7 changes: 7 additions & 0 deletions src/Accounts/Accounts.Test/SubscriptionCmdletTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,12 @@ public void SetAzureRmContextWithoutSubscription()
{
TestRunner.RunTestScript("Test-SetAzureRmContextWithoutSubscription");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void GetSubscriptionsWithTags()
{
TestRunner.RunTestScript("Test-GetSubscriptionsWithTags");
}
}
}
14 changes: 13 additions & 1 deletion src/Accounts/Accounts.Test/SubscriptionCmdletTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,16 @@ function Test-SetAzureRmContextWithoutSubscription
Assert-True { $context.Tenant -ne $null }
Assert-AreEqual $context.Tenant.Id $firstSubscription.HomeTenantId
Assert-AreEqual $context.Subscription.Id $firstSubscription.Id
}
}

<#
.SYNOPSIS
Check whether tags works with subscripiton
.DESCRIPTION
SmokeTest
#>
function Test-GetSubscriptionsWithTags
{
$allSubscriptions = Get-AzSubscription
Assert-True {($allSubscriptions | Where-Object { $_.Tags -ne $null}).Count -gt 0}
}
1 change: 1 addition & 0 deletions src/Accounts/Accounts/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-->

## Upcoming Release
* Upgraded subscription client to 2021-01-01
* Printed auto generated modules' default logs to verbose stream

## Version 2.4.0
Expand Down
4 changes: 2 additions & 2 deletions src/Accounts/Accounts/Models/SubscriptionClientProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
using System.Collections.Concurrent;
using System.Threading;
using SubscriptionClientVersion2016 = Microsoft.Azure.Commands.ResourceManager.Common.Utilities.SubscriptionClientWrapper;
using SubscriptionClientVersion2019 = Microsoft.Azure.Commands.ResourceManager.Common.Utilities.Version2019_06_01.SubscriptionClientWrapper;
using SubscriptionClientVersion2021 = Microsoft.Azure.Commands.ResourceManager.Common.Utilities.Version2021_01_01.SubscriptionClientWrapper;

namespace Microsoft.Azure.Commands.Profile.Models
{
Expand Down Expand Up @@ -63,7 +63,7 @@ static public SubscritpionClientCandidates Instance

private SubscritpionClientCandidates()
{
Enqueue(new SubscriptionClientVersion2019());
Enqueue(new SubscriptionClientVersion2021());
Enqueue(new SubscriptionClientVersion2016());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using Microsoft.Azure.Commands.Common.Authentication;
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
using Microsoft.Azure.Commands.ResourceManager.Common.Paging;
using Microsoft.Azure.Commands.ResourceManager.Version2019_06_01.Customized;
using Microsoft.Azure.Internal.Subscriptions;
using Microsoft.Azure.Internal.Subscriptions.Models;
using Microsoft.Azure.Internal.Subscriptions.Models.Utilities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@
using Microsoft.Azure.Commands.Common.Authentication;
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
using Microsoft.Azure.Commands.ResourceManager.Common.Paging;
using Microsoft.Azure.Commands.ResourceManager.Version2019_06_01.Customized;
using Microsoft.Azure.Management.ResourceManager.Version2019_06_01;
using Microsoft.Azure.Management.ResourceManager.Version2019_06_01.Models;
using Microsoft.Azure.Management.ResourceManager.Version2019_06_01.Models.Utilities;
using Microsoft.Azure.Commands.ResourceManager.Version2021_01_01.Utilities;
using Microsoft.Azure.Management.ResourceManager.Version2021_01_01;
using Microsoft.Azure.Management.ResourceManager.Version2021_01_01.Models;
using Microsoft.Azure.Management.ResourceManager.Version2021_01_01.Models.Utilities;
using Microsoft.Rest;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System.Collections.Generic;
using System.Linq;

namespace Microsoft.Azure.Commands.ResourceManager.Common.Utilities.Version2019_06_01
namespace Microsoft.Azure.Commands.ResourceManager.Common.Utilities.Version2021_01_01
{
internal class SubscriptionClientWrapper : ISubscriptionClientWrapper
{
public SubscriptionClientWrapper()
{
ApiVersion = "2019-06-01";
ApiVersion = "2021-01-01";
}

public IList<AzureTenant> ListAccountTenants(IAccessToken accessToken, IAzureEnvironment environment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,13 @@ public static string GetAccountName(string connectionString)

return result;
}

public Dictionary<string, string> Tags
{
get
{
return this.GetTags();
}
}
}
}
Loading

0 comments on commit 4c31073

Please sign in to comment.