Skip to content

Commit 9b0504f

Browse files
authored
Merge pull request #2951 from vivsriaus/FixResourcesPs1
Update api-version to use default constant resources api-version for ARM cmdlets
2 parents f3976b9 + 7581c7e commit 9b0504f

File tree

6 files changed

+260
-597
lines changed

6 files changed

+260
-597
lines changed

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Components/Constants.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public static class Constants
5454
/// </summary>
5555
public static readonly string DefaultApiVersion = "2015-01-01";
5656

57+
58+
/// <summary>
59+
/// The default resources API version.
60+
/// </summary>
61+
public static readonly string ResourcesApiVersion = "2016-09-01";
62+
5763
/// <summary>
5864
/// The default policy API version.
5965
/// </summary>

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/Resource/FindAzureResourceCmdlet.cs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ public sealed class FindAzureResourceCmdlet : ResourceManagerCmdletBase
143143
/// </summary>
144144
public Guid? SubscriptionId { get; set; }
145145

146+
/// <summary>
147+
/// Gets or sets the default api-version to use.
148+
/// </summary>
149+
public string DefaultApiVersion { get; set; }
150+
146151
/// <summary>
147152
/// Collects subscription ids from the pipeline.
148153
/// </summary>
@@ -166,6 +171,8 @@ protected override void OnEndProcessing()
166171
/// </summary>
167172
private void RunCmdlet()
168173
{
174+
this.DefaultApiVersion = string.IsNullOrWhiteSpace(this.ApiVersion) ? Constants.ResourcesApiVersion : this.ApiVersion;
175+
169176
if (!this.TenantLevel)
170177
{
171178
this.SubscriptionId = DefaultContext.Subscription.Id;
@@ -246,10 +253,6 @@ private async Task<ResponseWithContinuation<JObject[]>> ListResourcesTypeCollect
246253
extensionResourceType: this.ExtensionResourceType,
247254
extensionResourceName: null);
248255

249-
var apiVersion = await this
250-
.DetermineApiVersion(resourceId: resourceCollectionId)
251-
.ConfigureAwait(continueOnCapturedContext: false);
252-
253256
var odataQuery = QueryFilterBuilder.CreateFilter(
254257
resourceType: null,
255258
resourceName: null,
@@ -263,7 +266,7 @@ private async Task<ResponseWithContinuation<JObject[]>> ListResourcesTypeCollect
263266
.GetResourcesClient()
264267
.ListObjectColleciton<JObject>(
265268
resourceCollectionId: resourceCollectionId,
266-
apiVersion: apiVersion,
269+
apiVersion: this.DefaultApiVersion,
267270
cancellationToken: this.CancellationToken.Value,
268271
odataQuery: odataQuery)
269272
.ConfigureAwait(continueOnCapturedContext: false);
@@ -286,14 +289,10 @@ private async Task<ResponseWithContinuation<JObject[]>> ListResourcesInTenant()
286289
resourceGroupNameContains: this.ResourceGroupNameContains,
287290
nameContains: this.ResourceNameContains);
288291

289-
var apiVersion = await this
290-
.DetermineApiVersion(providerNamespace: Constants.MicrosoftResourceNamesapce, resourceType: Constants.ResourceGroups)
291-
.ConfigureAwait(continueOnCapturedContext: false);
292-
293292
return await this
294293
.GetResourcesClient()
295294
.ListResources<JObject>(
296-
apiVersion: apiVersion,
295+
apiVersion: this.DefaultApiVersion,
297296
top: this.Top,
298297
filter: filterQuery,
299298
cancellationToken: this.CancellationToken.Value)
@@ -315,16 +314,12 @@ private async Task<ResponseWithContinuation<JObject[]>> ListResourcesInResourceG
315314
resourceGroupNameContains: this.ResourceGroupNameContains,
316315
nameContains: this.ResourceNameContains);
317316

318-
var apiVersion = await this
319-
.DetermineApiVersion(providerNamespace: Constants.MicrosoftResourceNamesapce, resourceType: Constants.ResourceGroups)
320-
.ConfigureAwait(continueOnCapturedContext: false);
321-
322317
return await this
323318
.GetResourcesClient()
324319
.ListResources<JObject>(
325320
subscriptionId: this.SubscriptionId.Value,
326321
resourceGroupName: null,
327-
apiVersion: apiVersion,
322+
apiVersion: this.DefaultApiVersion,
328323
top: this.Top,
329324
filter: filterQuery,
330325
cancellationToken: this.CancellationToken.Value)
@@ -345,15 +340,11 @@ private async Task<ResponseWithContinuation<JObject[]>> ListResourcesInSubscript
345340
filter: this.ODataQuery,
346341
nameContains: this.ResourceNameContains);
347342

348-
var apiVersion = await this
349-
.DetermineApiVersion(providerNamespace: Constants.MicrosoftResourceNamesapce, resourceType: Constants.ResourceGroups)
350-
.ConfigureAwait(continueOnCapturedContext: false);
351-
352343
return await this
353344
.GetResourcesClient()
354345
.ListResources<JObject>(
355346
subscriptionId: this.SubscriptionId.Value,
356-
apiVersion: apiVersion,
347+
apiVersion: this.DefaultApiVersion,
357348
top: this.Top,
358349
filter: filterQuery,
359350
cancellationToken: this.CancellationToken.Value)

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/Resource/GetAzureResourceCmdlet.cs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ public sealed class GetAzureResourceCmdlet : ResourceManagerCmdletBase
187187
/// </summary>
188188
public Guid? SubscriptionId { get; set; }
189189

190+
/// <summary>
191+
/// Gets or sets the default api-version to use.
192+
/// </summary>
193+
public string DefaultApiVersion { get; set; }
194+
190195
/// <summary>
191196
/// Collects subscription ids from the pipeline.
192197
/// </summary>
@@ -210,6 +215,8 @@ protected override void OnEndProcessing()
210215
/// </summary>
211216
private void RunCmdlet()
212217
{
218+
this.DefaultApiVersion = string.IsNullOrWhiteSpace(this.ApiVersion) ? Constants.ResourcesApiVersion : this.ApiVersion;
219+
213220
if (string.IsNullOrEmpty(this.ResourceId) && !this.TenantLevel)
214221
{
215222
this.SubscriptionId = DefaultContext.Subscription.Id;
@@ -331,10 +338,6 @@ private async Task<ResponseWithContinuation<JObject[]>> ListResourcesTypeCollect
331338
extensionResourceType: this.ExtensionResourceType,
332339
extensionResourceName: this.ExtensionResourceName);
333340

334-
var apiVersion = await this
335-
.DetermineApiVersion(resourceId: resourceCollectionId)
336-
.ConfigureAwait(continueOnCapturedContext: false);
337-
338341
var odataQuery = QueryFilterBuilder.CreateFilter(
339342
resourceType: null,
340343
resourceName: null,
@@ -346,7 +349,7 @@ private async Task<ResponseWithContinuation<JObject[]>> ListResourcesTypeCollect
346349
.GetResourcesClient()
347350
.ListObjectColleciton<JObject>(
348351
resourceCollectionId: resourceCollectionId,
349-
apiVersion: apiVersion,
352+
apiVersion: this.DefaultApiVersion,
350353
cancellationToken: this.CancellationToken.Value,
351354
odataQuery: odataQuery)
352355
.ConfigureAwait(continueOnCapturedContext: false);
@@ -367,14 +370,10 @@ private async Task<ResponseWithContinuation<JObject[]>> ListResourcesInTenant()
367370
tagValue: null,
368371
filter: this.ODataQuery);
369372

370-
var apiVersion = await this
371-
.DetermineApiVersion(providerNamespace: Constants.MicrosoftResourceNamesapce, resourceType: Constants.ResourceGroups)
372-
.ConfigureAwait(continueOnCapturedContext: false);
373-
374373
return await this
375374
.GetResourcesClient()
376375
.ListResources<JObject>(
377-
apiVersion: apiVersion,
376+
apiVersion: this.DefaultApiVersion,
378377
top: this.Top,
379378
filter: filterQuery,
380379
cancellationToken: this.CancellationToken.Value)
@@ -394,16 +393,12 @@ private async Task<ResponseWithContinuation<JObject[]>> ListResourcesInResourceG
394393
tagValue: null,
395394
filter: this.ODataQuery);
396395

397-
var apiVersion = await this
398-
.DetermineApiVersion(providerNamespace: Constants.MicrosoftResourceNamesapce, resourceType: Constants.ResourceGroups)
399-
.ConfigureAwait(continueOnCapturedContext: false);
400-
401396
return await this
402397
.GetResourcesClient()
403398
.ListResources<JObject>(
404399
subscriptionId: this.SubscriptionId.Value,
405400
resourceGroupName: this.ResourceGroupName,
406-
apiVersion: apiVersion,
401+
apiVersion: this.DefaultApiVersion,
407402
top: this.Top,
408403
filter: filterQuery,
409404
cancellationToken: this.CancellationToken.Value)
@@ -423,15 +418,11 @@ private async Task<ResponseWithContinuation<JObject[]>> ListResourcesInSubscript
423418
tagValue: null,
424419
filter: this.ODataQuery);
425420

426-
var apiVersion = await this
427-
.DetermineApiVersion(providerNamespace: Constants.MicrosoftResourceNamesapce, resourceType: Constants.ResourceGroups)
428-
.ConfigureAwait(continueOnCapturedContext: false);
429-
430421
return await this
431422
.GetResourcesClient()
432423
.ListResources<JObject>(
433424
subscriptionId: this.SubscriptionId.Value,
434-
apiVersion: apiVersion,
425+
apiVersion: this.DefaultApiVersion,
435426
top: this.Top,
436427
filter: filterQuery,
437428
cancellationToken: this.CancellationToken.Value)

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/ResourceGroups/FindAzureResourceGroupCmdlet.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
1616
{
17+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
1718
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions;
1819
using Microsoft.Azure.Commands.ResourceManager.Common;
1920
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
@@ -62,9 +63,7 @@ private async Task<ResponseWithContinuation<JObject[]>> GetResourceGroups()
6263
{
6364
var resourceGroupsId = string.Format("/subscriptions/{0}/resourceGroups", Uri.EscapeDataString(this.DefaultContext.Subscription.Id.ToString()));
6465

65-
var apiVersion = await this
66-
.DetermineApiVersion(resourceId: resourceGroupsId)
67-
.ConfigureAwait(continueOnCapturedContext: false);
66+
var apiVersion = string.IsNullOrWhiteSpace(this.ApiVersion) ? Constants.ResourcesApiVersion : this.ApiVersion;
6867

6968
string queryString = null;
7069

src/ResourceManager/Resources/Commands.Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceGroupTests/TestFindResourceGroup.json

Lines changed: 169 additions & 439 deletions
Large diffs are not rendered by default.

src/ResourceManager/Resources/Commands.Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceTests/TestFindAResourceTest.json

Lines changed: 61 additions & 115 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)