Skip to content

Commit 80e9e91

Browse files
author
Hovsep
committed
Merge pull request Azure#1075 from vivsriaus/RemoveLegacyObject
Remove legacy object format from resource cmdlets
2 parents 1c7b941 + f0d05ba commit 80e9e91

16 files changed

+31
-175
lines changed

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Commands.Resources.Rest.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
<Compile Include="Entities\Providers\ResourceTypeDefinition.cs" />
121121
<Compile Include="Entities\ResourceGroup\ResourceBatchMoveParameters.cs" />
122122
<Compile Include="Entities\Resources\Resource.cs" />
123-
<Compile Include="Entities\Resources\ResourceObjectFormat.cs" />
124123
<Compile Include="Entities\Resources\ResourcePlan.cs" />
125124
<Compile Include="Entities\Resources\ResourceSku.cs" />
126125
<Compile Include="Entities\Resources\TerminalProvisioningStates.cs" />

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Entities/Resources/ResourceObjectFormat.cs

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Extensions/JTokenExtensions.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ internal static class JTokenExtensions
4949
/// Converts a <see cref="JObject"/> to a <see cref="PSObject"/>
5050
/// </summary>
5151
/// <param name="jtoken">The <see cref="JObject"/></param>
52-
/// <param name="objectFormat">The <see cref="ResourceObjectFormat"/></param>
5352
/// <param name="objectType">The type of the object.</param>
54-
internal static PSObject ToPsObject(this JToken jtoken, ResourceObjectFormat objectFormat, string objectType = null)
53+
internal static PSObject ToPsObject(this JToken jtoken, string objectType = null)
5554
{
5655
if (jtoken == null)
5756
{
@@ -60,7 +59,7 @@ internal static PSObject ToPsObject(this JToken jtoken, ResourceObjectFormat obj
6059

6160
if (jtoken.Type != JTokenType.Object)
6261
{
63-
return new PSObject(JTokenExtensions.ConvertPropertyValueForPsObject(propertyValue: jtoken, objectFormat: objectFormat));
62+
return new PSObject(JTokenExtensions.ConvertPropertyValueForPsObject(propertyValue: jtoken));
6463
}
6564

6665
var jobject = (JObject)jtoken;
@@ -75,7 +74,7 @@ internal static PSObject ToPsObject(this JToken jtoken, ResourceObjectFormat obj
7574
{
7675
psObject.Properties.Add(new PSNoteProperty(
7776
name: JTokenExtensions.ConvertToPascalCase(propertyName: property.Name),
78-
value: JTokenExtensions.ConvertPropertyValueForPsObject(propertyValue: property.Value, objectFormat: objectFormat)));
77+
value: JTokenExtensions.ConvertPropertyValueForPsObject(propertyValue: property.Value)));
7978
}
8079

8180
return psObject;
@@ -86,12 +85,11 @@ internal static PSObject ToPsObject(this JToken jtoken, ResourceObjectFormat obj
8685
/// used as the value of a <see cref="PSNoteProperty"/>.
8786
/// </summary>
8887
/// <param name="propertyValue">The <see cref="JToken"/> value.</param>
89-
/// <param name="objectFormat">The <see cref="ResourceObjectFormat"/></param>
90-
internal static object ConvertPropertyValueForPsObject(JToken propertyValue, ResourceObjectFormat objectFormat)
88+
internal static object ConvertPropertyValueForPsObject(JToken propertyValue)
9189
{
9290
if (propertyValue.Type == JTokenType.Object)
9391
{
94-
return propertyValue.ToPsObject(objectFormat);
92+
return propertyValue.ToPsObject();
9593
}
9694

9795
if (propertyValue.Type == JTokenType.Array)
@@ -102,7 +100,7 @@ internal static object ConvertPropertyValueForPsObject(JToken propertyValue, Res
102100

103101
for (int i = 0; i < array.Length; ++i)
104102
{
105-
array[i] = JTokenExtensions.ConvertPropertyValueForPsObject(jArray[i], objectFormat);
103+
array[i] = JTokenExtensions.ConvertPropertyValueForPsObject(jArray[i]);
106104
}
107105

108106
return array;

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Extensions/ResourceExtensions.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ internal static class ResourceExtensions
3232
/// Converts a <see cref="Resource{JToken}"/> object into a <see cref="PSObject"/> object.
3333
/// </summary>
3434
/// <param name="resource">The <see cref="Resource{JToken}"/> object.</param>
35-
/// <param name="objectFormat">The <see cref="ResourceObjectFormat"/></param>
36-
internal static PSObject ToPsObject(this Resource<JToken> resource, ResourceObjectFormat objectFormat)
35+
internal static PSObject ToPsObject(this Resource<JToken> resource)
3736
{
3837
var resourceType = string.IsNullOrEmpty(resource.Id)
3938
? null
@@ -56,12 +55,12 @@ internal static PSObject ToPsObject(this Resource<JToken> resource, ResourceObje
5655
{ "Location", resource.Location },
5756
{ "SubscriptionId", string.IsNullOrEmpty(resource.Id) ? null : ResourceIdUtility.GetSubscriptionId(resource.Id) },
5857
{ "Tags", TagsHelper.GetTagsHashtables(resource.Tags) },
59-
{ "Plan", resource.Plan.ToJToken().ToPsObject(objectFormat) },
60-
{ "Properties", ResourceExtensions.GetProperties(resource, objectFormat) },
58+
{ "Plan", resource.Plan.ToJToken().ToPsObject() },
59+
{ "Properties", ResourceExtensions.GetProperties(resource) },
6160
{ "CreatedTime", resource.CreatedTime },
6261
{ "ChangedTime", resource.ChangedTime },
6362
{ "ETag", resource.ETag },
64-
{ "Sku", resource.Sku.ToJToken().ToPsObject(objectFormat) },
63+
{ "Sku", resource.Sku.ToJToken().ToPsObject() },
6564
};
6665

6766
var resourceTypeName = resourceType == null && extensionResourceType == null
@@ -81,17 +80,14 @@ internal static PSObject ToPsObject(this Resource<JToken> resource, ResourceObje
8180
/// Gets the properties object
8281
/// </summary>
8382
/// <param name="resource">The <see cref="Resource{JToken}"/> object.</param>
84-
/// <param name="objectFormat">The <see cref="ResourceObjectFormat"/></param>
85-
private static object GetProperties(Resource<JToken> resource, ResourceObjectFormat objectFormat)
83+
private static object GetProperties(Resource<JToken> resource)
8684
{
8785
if (resource.Properties == null)
8886
{
8987
return null;
9088
}
9189

92-
return objectFormat == ResourceObjectFormat.Legacy
93-
? JsonUtilities.DeserializeJson(resource.Properties.ToString())
94-
: (object)resource.Properties.ToPsObject(objectFormat);
90+
return (object)resource.Properties.ToPsObject();
9591
}
9692

9793
/// <summary>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private void RunCmdlet()
5252
getFirstPage: () => this.GetResourceGroups(),
5353
getNextPage: nextLink => this.GetNextLink<JObject>(nextLink),
5454
cancellationToken: this.CancellationToken,
55-
action: resourceGroups => this.WriteObject(sendToPipeline: resourceGroups.CoalesceEnumerable().SelectArray(resourceGroup => resourceGroup.ToPsObject(ResourceObjectFormat.New)), enumerateCollection: true));
55+
action: resourceGroups => this.WriteObject(sendToPipeline: resourceGroups.CoalesceEnumerable().SelectArray(resourceGroup => resourceGroup.ToPsObject()), enumerateCollection: true));
5656
}
5757

5858
/// <summary>

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/GetAzureResourceGroupDeploymentOperationCmdlet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private void RunCmdlet()
7979
getFirstPage: () => this.GetResources(),
8080
getNextPage: nextLink => this.GetNextLink<JObject>(nextLink),
8181
cancellationToken: this.CancellationToken,
82-
action: resources => this.WriteObject(sendToPipeline: resources.CoalesceEnumerable().SelectArray(resource => resource.ToPsObject(ResourceObjectFormat.New)), enumerateCollection: true));
82+
action: resources => this.WriteObject(sendToPipeline: resources.CoalesceEnumerable().SelectArray(resource => resource.ToPsObject()), enumerateCollection: true));
8383
}
8484

8585
/// <summary>

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/InvokeAzureResourceActionCmdlet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected override void OnProcessRecord()
8383
var resultString = this.GetLongRunningOperationTracker(activityName: activity, isResourceCreateOrUpdate: false)
8484
.WaitOnOperation(operationResult: operationResult);
8585

86-
this.TryConvertAndWriteObject(resultString, ResourceObjectFormat.New);
86+
this.TryConvertAndWriteObject(resultString);
8787
});
8888
}
8989

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Implementation/Lock/ResourceLockManagementCmdletBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ protected PSObject[] GetOutputObjects(params JToken[] resources)
155155
.Where(resource => resource != null)
156156
.SelectArray(resource =>
157157
{
158-
var psobject = resource.ToResource().ToPsObject(ResourceObjectFormat.New);
158+
var psobject = resource.ToResource().ToPsObject();
159159
psobject.Properties.Add(new PSNoteProperty("LockId", psobject.Properties["ResourceId"].Value));
160160
return psobject;
161161
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected PSObject[] GetOutputObjects(params JToken[] resources)
4949
.Where(resource => resource != null)
5050
.SelectArray(resource =>
5151
{
52-
var psobject = resource.ToResource().ToPsObject(ResourceObjectFormat.New);
52+
var psobject = resource.ToResource().ToPsObject();
5353
psobject.Properties.Add(new PSNoteProperty("PolicyAssignmentId", psobject.Properties["ResourceId"].Value));
5454
return psobject;
5555
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected PSObject[] GetOutputObjects(params JToken[] resources)
4949
.Where(resource => resource != null)
5050
.SelectArray(resource =>
5151
{
52-
var psobject = resource.ToResource().ToPsObject(ResourceObjectFormat.New);
52+
var psobject = resource.ToResource().ToPsObject();
5353
psobject.Properties.Add(new PSNoteProperty("PolicyDefinitionId", psobject.Properties["ResourceId"].Value));
5454
return psobject;
5555
});

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

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -122,25 +122,11 @@ public sealed class FindAzureResourceCmdlet : ResourceManagerCmdletBase
122122
[Parameter(ParameterSetName = FindAzureResourceCmdlet.ListTenantResourcesParameterSet, Mandatory = true, HelpMessage = "Indicates that this is a tenant level operation.")]
123123
public SwitchParameter TenantLevel { get; set; }
124124

125-
/// <summary>
126-
/// Gets or sets the resource property object format.
127-
/// </summary>
128-
[Parameter(Mandatory = false, HelpMessage = "The output format of the resource properties.")]
129-
public ResourceObjectFormat OutputObjectFormat { get; set; }
130-
131125
/// <summary>
132126
/// Gets or sets the subscription id.
133127
/// </summary>
134128
public Guid? SubscriptionId { get; set; }
135129

136-
/// <summary>
137-
/// Initializes a new instance of the <see cref="FindAzureResourceCmdlet" /> class.
138-
/// </summary>
139-
public FindAzureResourceCmdlet()
140-
{
141-
this.OutputObjectFormat = ResourceObjectFormat.Legacy;
142-
}
143-
144130
/// <summary>
145131
/// Collects subscription ids from the pipeline.
146132
/// </summary>
@@ -164,11 +150,6 @@ protected override void OnEndProcessing()
164150
/// </summary>
165151
private void RunCmdlet()
166152
{
167-
if(this.OutputObjectFormat == ResourceObjectFormat.Legacy)
168-
{
169-
this.WriteWarning("This cmdlet is using the legacy properties object format. This format is being deprecated. Please use '-OutputObjectFormat New' and update your scripts.");
170-
}
171-
172153
if (!this.TenantLevel)
173154
{
174155
this.SubscriptionId = DefaultContext.Subscription.Id;
@@ -193,14 +174,14 @@ private void RunCmdlet()
193174
items = this.GetPopulatedResource(batch).Result;
194175
}
195176

196-
var powerShellObjects = items.SelectArray(genericResource => genericResource.ToPsObject(this.OutputObjectFormat));
177+
var powerShellObjects = items.SelectArray(genericResource => genericResource.ToPsObject());
197178

198179
this.WriteObject(sendToPipeline: powerShellObjects, enumerateCollection: true);
199180
}
200181
}
201182
else
202183
{
203-
this.WriteObject(sendToPipeline: resources.CoalesceEnumerable().SelectArray(res => res.ToPsObject(this.OutputObjectFormat)), enumerateCollection: true);
184+
this.WriteObject(sendToPipeline: resources.CoalesceEnumerable().SelectArray(res => res.ToPsObject()), enumerateCollection: true);
204185
}
205186
});
206187

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

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -173,25 +173,11 @@ public sealed class GetAzureResourceCmdlet : ResourceManagerCmdletBase
173173
[Parameter(ParameterSetName = GetAzureResourceCmdlet.ListTenantResourcesParameterSet, Mandatory = true, HelpMessage = "Indicates that this is a tenant level operation.")]
174174
public SwitchParameter TenantLevel { get; set; }
175175

176-
/// <summary>
177-
/// Gets or sets the resource property object format.
178-
/// </summary>
179-
[Parameter(Mandatory = false, HelpMessage = "The output format of the resource properties.")]
180-
public ResourceObjectFormat OutputObjectFormat { get; set; }
181-
182176
/// <summary>
183177
/// Gets or sets the subscription id.
184178
/// </summary>
185179
public Guid? SubscriptionId { get; set; }
186180

187-
/// <summary>
188-
/// Initializes a new instance of the <see cref="GetAzureResourceCmdlet" /> class.
189-
/// </summary>
190-
public GetAzureResourceCmdlet()
191-
{
192-
this.OutputObjectFormat = ResourceObjectFormat.Legacy;
193-
}
194-
195181
/// <summary>
196182
/// Collects subscription ids from the pipeline.
197183
/// </summary>
@@ -215,11 +201,6 @@ protected override void OnEndProcessing()
215201
/// </summary>
216202
private void RunCmdlet()
217203
{
218-
if(this.OutputObjectFormat == ResourceObjectFormat.Legacy)
219-
{
220-
this.WriteWarning("This cmdlet is using the legacy properties object format. This format is being deprecated. Please use '-OutputObjectFormat New' and update your scripts.");
221-
}
222-
223204
if (string.IsNullOrEmpty(this.ResourceId) && !this.TenantLevel)
224205
{
225206
this.SubscriptionId = DefaultContext.Subscription.Id;
@@ -244,14 +225,14 @@ private void RunCmdlet()
244225
items = this.GetPopulatedResource(batch).Result;
245226
}
246227

247-
var powerShellObjects = items.SelectArray(genericResource => genericResource.ToPsObject(this.OutputObjectFormat));
228+
var powerShellObjects = items.SelectArray(genericResource => genericResource.ToPsObject());
248229

249230
this.WriteObject(sendToPipeline: powerShellObjects, enumerateCollection: true);
250231
}
251232
}
252233
else
253234
{
254-
this.WriteObject(sendToPipeline: resources.CoalesceEnumerable().SelectArray(res => res.ToPsObject(this.OutputObjectFormat)), enumerateCollection: true);
235+
this.WriteObject(sendToPipeline: resources.CoalesceEnumerable().SelectArray(res => res.ToPsObject()), enumerateCollection: true);
255236
}
256237
});
257238

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private void RunCmdlet()
165165
isResourceCreateOrUpdate: false)
166166
.WaitOnOperation(operationResult: operationResult);
167167

168-
this.TryConvertAndWriteObject(result, ResourceObjectFormat.New);
168+
this.TryConvertAndWriteObject(result);
169169
});
170170
}
171171
}

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

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -81,36 +81,16 @@ public sealed class NewAzureResourceCmdlet : ResourceManipulationCmdletBase
8181
[Parameter(Mandatory = false, HelpMessage = "When set indicates that the full object is passed in to the -PropertyObject parameter.")]
8282
public SwitchParameter IsFullObject { get; set; }
8383

84-
/// <summary>
85-
/// Gets or sets the resource property object format.
86-
/// </summary>
87-
[Parameter(Mandatory = false, HelpMessage = "The output format of the resource properties.")]
88-
[ValidateNotNull]
89-
public ResourceObjectFormat? OutputObjectFormat { get; set; }
90-
91-
/// <summary>
92-
/// Initializes a new instance of the <see cref="NewAzureResourceCmdlet" /> class.
93-
/// </summary>
94-
public NewAzureResourceCmdlet()
95-
{
96-
this.OutputObjectFormat = ResourceObjectFormat.Legacy;
97-
}
98-
9984
/// <summary>
10085
/// Executes the cmdlet.
10186
/// </summary>
10287
protected override void OnProcessRecord()
10388
{
10489
base.OnProcessRecord();
105-
this.DetermineOutputObjectFormat();
10690
if(this.IsFullObject.IsPresent)
10791
{
10892
this.WriteWarning("The IsFullObject parameter is obsolete and will be removed in future releases.");
10993
}
110-
if (this.OutputObjectFormat == ResourceObjectFormat.Legacy)
111-
{
112-
this.WriteWarning("This cmdlet is using the legacy properties object format. This format is being deprecated. Please use '-OutputObjectFormat New' and update your scripts.");
113-
}
11494

11595
var resourceId = this.GetResourceId();
11696
this.ConfirmAction(
@@ -142,26 +122,10 @@ protected override void OnProcessRecord()
142122
var result = this.GetLongRunningOperationTracker(activityName: activity, isResourceCreateOrUpdate: true)
143123
.WaitOnOperation(operationResult: operationResult);
144124

145-
this.TryConvertToResourceAndWriteObject(result, this.OutputObjectFormat.Value);
125+
this.TryConvertToResourceAndWriteObject(result);
146126
});
147127
}
148128

149-
/// <summary>
150-
/// Determines the output object format.
151-
/// </summary>
152-
private void DetermineOutputObjectFormat()
153-
{
154-
if (this.Properties != null && this.OutputObjectFormat == null && this.Properties.TypeNames.Any(typeName => typeName.EqualsInsensitively(Constants.MicrosoftAzureResource)))
155-
{
156-
this.OutputObjectFormat = ResourceObjectFormat.New;
157-
}
158-
159-
if (this.OutputObjectFormat == null)
160-
{
161-
this.OutputObjectFormat = ResourceObjectFormat.Legacy;
162-
}
163-
}
164-
165129
/// <summary>
166130
/// Gets the resource body from the parameters.
167131
/// </summary>

0 commit comments

Comments
 (0)