Skip to content

Commit 2d24fe6

Browse files
author
Hovsep
committed
Merge pull request Azure#1970 from vivsriaus/HardcodeApiVersion
Use hard-coded api version for Policy cmdlets
2 parents 2fc3a68 + e65115b commit 2d24fe6

File tree

9 files changed

+24
-35
lines changed

9 files changed

+24
-35
lines changed

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

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

57+
/// <summary>
58+
/// The default policy API version.
59+
/// </summary>
60+
public static readonly string PolicyApiVersion = "2015-10-01-preview";
61+
5762
/// <summary>
5863
/// The move action.
5964
/// </summary>

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/Policy/GetAzurePolicyAssignment.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,13 @@ private async Task<ResponseWithContinuation<JObject[]>> GetResources()
100100
{
101101
string resourceId = this.Id ?? this.GetResourceId();
102102

103-
var apiVersion = await this
104-
.DetermineApiVersion(resourceId: resourceId)
105-
.ConfigureAwait(continueOnCapturedContext: false);
106-
107103
if (IsResourceGet(resourceId))
108104
{
109105
var resource = await this
110106
.GetResourcesClient()
111107
.GetResource<JObject>(
112108
resourceId: resourceId,
113-
apiVersion: apiVersion,
109+
apiVersion: Constants.PolicyApiVersion,
114110
cancellationToken: this.CancellationToken.Value,
115111
odataQuery: null)
116112
.ConfigureAwait(continueOnCapturedContext: false);
@@ -126,7 +122,7 @@ private async Task<ResponseWithContinuation<JObject[]>> GetResources()
126122
.GetResourcesClient()
127123
.ListObjectColleciton<JObject>(
128124
resourceCollectionId: resourceId,
129-
apiVersion: apiVersion,
125+
apiVersion: Constants.PolicyApiVersion,
130126
cancellationToken: this.CancellationToken.Value,
131127
odataQuery: filter)
132128
.ConfigureAwait(continueOnCapturedContext: false);
@@ -141,7 +137,7 @@ private async Task<ResponseWithContinuation<JObject[]>> GetResources()
141137
.GetResourcesClient()
142138
.ListObjectColleciton<JObject>(
143139
resourceCollectionId: resourceId,
144-
apiVersion: apiVersion,
140+
apiVersion: Constants.PolicyApiVersion,
145141
cancellationToken: this.CancellationToken.Value,
146142
odataQuery: filter)
147143
.ConfigureAwait(continueOnCapturedContext: false);

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/Policy/GetAzurePolicyDefinition.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,13 @@ private async Task<ResponseWithContinuation<JObject[]>> GetResources()
8585
{
8686
string resourceId = this.Id ?? this.GetResourceId();
8787

88-
var apiVersion = await this
89-
.DetermineApiVersion(resourceId: resourceId)
90-
.ConfigureAwait(continueOnCapturedContext: false);
91-
9288
if (!string.IsNullOrEmpty(ResourceIdUtility.GetResourceName(resourceId)))
9389
{
9490
var resource = await this
9591
.GetResourcesClient()
9692
.GetResource<JObject>(
9793
resourceId: resourceId,
98-
apiVersion: apiVersion,
94+
apiVersion: Constants.PolicyApiVersion,
9995
cancellationToken: this.CancellationToken.Value)
10096
.ConfigureAwait(continueOnCapturedContext: false);
10197
ResponseWithContinuation<JObject[]> retVal;
@@ -109,7 +105,7 @@ private async Task<ResponseWithContinuation<JObject[]>> GetResources()
109105
.GetResourcesClient()
110106
.ListObjectColleciton<JObject>(
111107
resourceCollectionId: resourceId,
112-
apiVersion: apiVersion,
108+
apiVersion: Constants.PolicyApiVersion,
113109
cancellationToken: this.CancellationToken.Value)
114110
.ConfigureAwait(continueOnCapturedContext: false);
115111
}

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/Policy/NewAzurePolicyAssignment.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,11 @@ protected override void OnProcessRecord()
6868
throw new PSInvalidOperationException("The supplied PolicyDefinition object is invalid.");
6969
}
7070
string resourceId = GetResourceId();
71-
var apiVersion = this.DetermineApiVersion(resourceId: resourceId).Result;
7271

7372
var operationResult = this.GetResourcesClient()
7473
.PutResource(
7574
resourceId: resourceId,
76-
apiVersion: apiVersion,
75+
apiVersion: Constants.PolicyApiVersion,
7776
resource: this.GetResource(),
7877
cancellationToken: this.CancellationToken.Value,
7978
odataQuery: null)
@@ -82,7 +81,7 @@ protected override void OnProcessRecord()
8281
var managementUri = this.GetResourcesClient()
8382
.GetResourceManagementRequestUri(
8483
resourceId: resourceId,
85-
apiVersion: apiVersion,
84+
apiVersion: Constants.PolicyApiVersion,
8685
odataQuery: null);
8786

8887
var activity = string.Format("PUT {0}", managementUri.PathAndQuery);

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/Policy/NewAzurePolicyDefinition.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,11 @@ protected override void OnProcessRecord()
6666
{
6767
base.OnProcessRecord();
6868
string resourceId = GetResourceId();
69-
var apiVersion = this.DetermineApiVersion(resourceId: resourceId).Result;
7069

7170
var operationResult = this.GetResourcesClient()
7271
.PutResource(
7372
resourceId: resourceId,
74-
apiVersion: apiVersion,
73+
apiVersion: Constants.PolicyApiVersion,
7574
resource: this.GetResource(),
7675
cancellationToken: this.CancellationToken.Value,
7776
odataQuery: null)
@@ -80,7 +79,7 @@ protected override void OnProcessRecord()
8079
var managementUri = this.GetResourcesClient()
8180
.GetResourceManagementRequestUri(
8281
resourceId: resourceId,
83-
apiVersion: apiVersion,
82+
apiVersion: Constants.PolicyApiVersion,
8483
odataQuery: null);
8584

8685
var activity = string.Format("PUT {0}", managementUri.PathAndQuery);

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/Policy/RemoveAzurePolicyAssignment.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,18 @@ private void RunCmdlet()
8585
resourceId,
8686
() =>
8787
{
88-
var apiVersion = this.DetermineApiVersion(resourceId: resourceId).Result;
89-
9088
var operationResult = this.GetResourcesClient()
9189
.DeleteResource(
9290
resourceId: resourceId,
93-
apiVersion: apiVersion,
91+
apiVersion: Constants.PolicyApiVersion,
9492
cancellationToken: this.CancellationToken.Value,
9593
odataQuery: null)
9694
.Result;
9795

9896
var managementUri = this.GetResourcesClient()
9997
.GetResourceManagementRequestUri(
10098
resourceId: resourceId,
101-
apiVersion: apiVersion,
99+
apiVersion: Constants.PolicyApiVersion,
102100
odataQuery: null);
103101

104102
var activity = string.Format("DELETE {0}", managementUri.PathAndQuery);

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/Policy/RemoveAzurePolicyDefinition.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,18 @@ private void RunCmdlet()
7878
resourceId,
7979
() =>
8080
{
81-
var apiVersion = this.DetermineApiVersion(resourceId: resourceId).Result;
82-
8381
var operationResult = this.GetResourcesClient()
8482
.DeleteResource(
8583
resourceId: resourceId,
86-
apiVersion: apiVersion,
84+
apiVersion: Constants.PolicyApiVersion,
8785
cancellationToken: this.CancellationToken.Value,
8886
odataQuery: null)
8987
.Result;
9088

9189
var managementUri = this.GetResourcesClient()
9290
.GetResourceManagementRequestUri(
9391
resourceId: resourceId,
94-
apiVersion: apiVersion,
92+
apiVersion: Constants.PolicyApiVersion,
9593
odataQuery: null);
9694

9795
var activity = string.Format("DELETE {0}", managementUri.PathAndQuery);

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/Policy/SetAzurePolicyAssignment.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,20 @@ protected override void OnProcessRecord()
7676
{
7777
base.OnProcessRecord();
7878
string resourceId = this.Id ?? this.GetResourceId();
79-
var apiVersion = this.DetermineApiVersion(resourceId: resourceId).Result;
8079

8180
var operationResult = this.GetResourcesClient()
8281
.PutResource(
8382
resourceId: resourceId,
84-
apiVersion: apiVersion,
85-
resource: this.GetResource(resourceId, apiVersion),
83+
apiVersion: Constants.PolicyApiVersion,
84+
resource: this.GetResource(resourceId, Constants.PolicyApiVersion),
8685
cancellationToken: this.CancellationToken.Value,
8786
odataQuery: null)
8887
.Result;
8988

9089
var managementUri = this.GetResourcesClient()
9190
.GetResourceManagementRequestUri(
9291
resourceId: resourceId,
93-
apiVersion: apiVersion,
92+
apiVersion: Constants.PolicyApiVersion,
9493
odataQuery: null);
9594

9695
var activity = string.Format("PUT {0}", managementUri.PathAndQuery);

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/Policy/SetAzurePolicyDefinition.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,20 @@ protected override void OnProcessRecord()
8484
{
8585
base.OnProcessRecord();
8686
string resourceId = this.Id ?? this.GetResourceId();
87-
var apiVersion = this.DetermineApiVersion(resourceId: resourceId).Result;
8887

8988
var operationResult = this.GetResourcesClient()
9089
.PutResource(
9190
resourceId: resourceId,
92-
apiVersion: apiVersion,
93-
resource: this.GetResource(resourceId, apiVersion),
91+
apiVersion: Constants.PolicyApiVersion,
92+
resource: this.GetResource(resourceId, Constants.PolicyApiVersion),
9493
cancellationToken: this.CancellationToken.Value,
9594
odataQuery: null)
9695
.Result;
9796

9897
var managementUri = this.GetResourcesClient()
9998
.GetResourceManagementRequestUri(
10099
resourceId: resourceId,
101-
apiVersion: apiVersion,
100+
apiVersion: Constants.PolicyApiVersion,
102101
odataQuery: null);
103102

104103
var activity = string.Format("PUT {0}", managementUri.PathAndQuery);

0 commit comments

Comments
 (0)