Skip to content

Commit 92febbd

Browse files
a0x1abvidai-msft
andauthored
[Resources] Added ExpandProperties functionality to GetAzureResourceGroup (Azure#28161)
Co-authored-by: Vincent Dai <[email protected]>
1 parent 1397315 commit 92febbd

File tree

18 files changed

+1061
-58
lines changed

18 files changed

+1061
-58
lines changed

src/Resources/ResourceManager/Implementation/ResourceGroups/GetAzureResourceGroupCmdlet.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,19 @@ public class GetAzureResourceGroupCmdlet : ResourceManagerCmdletBaseWithApiVersi
6363
[ValidateNotNullOrEmpty]
6464
public Hashtable Tag { get; set; }
6565

66+
/// <summary>
67+
/// Gets or sets the expand properties parameter.
68+
/// </summary>
69+
[Parameter(Mandatory = false, HelpMessage = "When specified, output includes CreatedTime and ChangedTime of a resource.")]
70+
public SwitchParameter ExpandProperties { get; set; }
71+
6672
protected override void OnProcessRecord()
6773
{
68-
String subscriptionId = null;
6974
if (ResourceGroupIdParameterSet.Equals(ParameterSetName)){
7075
ResourceIdentifier resourceIdentifier = ResourceIdentifier.FromResourceGroupIdentifier(this.Id);
7176
Name = resourceIdentifier.ResourceGroupName;
72-
subscriptionId = resourceIdentifier.Subscription;
7377
}
74-
this.WriteObject(ResourceManagerSdkClient.FilterResourceGroups(name: this.Name, tag: this.Tag, detailed: false, location: this.Location, subscriptionId), true);
78+
this.WriteObject(this.NewResourceManagerSdkClient.FilterResourceGroups(this.Name, this.Tag, false, this.Location, this.ExpandProperties), true);
7579
}
7680

7781
}

src/Resources/ResourceManager/SdkClient/NewResourceManagerSdkClient.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -875,14 +875,14 @@ public virtual PSResourceGroup UpdatePSResourceGroup(PSUpdateResourceGroupParame
875875
/// <param name="tag">The resource group tag.</param>
876876
/// <param name="detailed">Whether the return is detailed or not.</param>
877877
/// <param name="location">The resource group location.</param>
878+
/// <param name="expand">The expand parameter for optional response properties.</param>
878879
/// <returns>The filtered resource groups</returns>
879-
public virtual List<PSResourceGroup> FilterResourceGroups(string name, Hashtable tag, bool detailed, string location = null)
880+
public virtual List<PSResourceGroup> FilterResourceGroups(string name, Hashtable tag, bool detailed, string location = null, bool expand = false)
880881
{
881882
List<PSResourceGroup> result = new List<PSResourceGroup>();
883+
var resourceGroupFilter = new ODataQuery<ResourceGroupFilterWithExpand>();
882884

883-
ODataQuery<ResourceGroupFilter> resourceGroupFilter = null;
884-
885-
if (tag != null && tag.Count >= 1)
885+
if (tag?.Count >= 1)
886886
{
887887
PSTagValuePair tagValuePair = TagsConversionHelper.Create(tag);
888888
if (tagValuePair == null || tag.Count > 1)
@@ -891,8 +891,12 @@ public virtual List<PSResourceGroup> FilterResourceGroups(string name, Hashtable
891891
}
892892

893893
resourceGroupFilter = string.IsNullOrEmpty(tagValuePair.Value)
894-
? new ODataQuery<ResourceGroupFilter>(rgFilter => rgFilter.TagName == tagValuePair.Name)
895-
: new ODataQuery<ResourceGroupFilter>(rgFilter => rgFilter.TagName == tagValuePair.Name && rgFilter.TagValue == tagValuePair.Value);
894+
? new ODataQuery<ResourceGroupFilterWithExpand>(rgFilter => rgFilter.TagName == tagValuePair.Name)
895+
: new ODataQuery<ResourceGroupFilterWithExpand>(rgFilter => rgFilter.TagName == tagValuePair.Name && rgFilter.TagValue == tagValuePair.Value);
896+
}
897+
898+
if (expand) {
899+
resourceGroupFilter.Expand = "createdTime,changedTime";
896900
}
897901

898902
if (string.IsNullOrEmpty(name) || WildcardPattern.ContainsWildcardCharacters(name))
@@ -924,7 +928,10 @@ public virtual List<PSResourceGroup> FilterResourceGroups(string name, Hashtable
924928
{
925929
try
926930
{
927-
PSResourceGroup resourceGroup = ResourceManagementClient.ResourceGroups.Get(name).ToPSResourceGroup();
931+
PSResourceGroup resourceGroup = expand
932+
? ResourceManagementClient.ResourceGroups.Get(name, expand: "createdTime,changedTime").ToPSResourceGroup()
933+
: ResourceManagementClient.ResourceGroups.Get(name).ToPSResourceGroup();
934+
928935
if (string.IsNullOrEmpty(location) || resourceGroup.Location.EqualsAsLocation(location))
929936
{
930937
result.Add(resourceGroup);

src/Resources/ResourceManager/SdkExtensions/NewResourcesExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public static PSResourceGroup ToPSResourceGroup(this ResourceGroup resourceGroup
4444
ProvisioningState = resourceGroup.Properties == null ? null : resourceGroup.Properties.ProvisioningState,
4545
Tags = TagsConversionHelper.CreateTagHashtable(resourceGroup.Tags),
4646
ResourceId = resourceGroup.Id,
47-
ManagedBy = resourceGroup.ManagedBy
47+
ManagedBy = resourceGroup.ManagedBy,
48+
CreatedTime = resourceGroup.CreatedTime,
49+
ChangedTime = resourceGroup.ChangedTime
4850
};
4951

5052
return result;

src/Resources/ResourceManager/SdkModels/ResourceGroups/PSResourceGroup.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkExtensions;
16+
using System;
1617
using System.Collections;
1718
using System.Collections.Generic;
1819

@@ -36,5 +37,9 @@ public string TagsTable
3637
public string ResourceId { get; set; }
3738

3839
public string ManagedBy { get; set; }
40+
41+
public DateTime? CreatedTime { get; set; }
42+
43+
public DateTime? ChangedTime { get; set; }
3944
}
4045
}

src/Resources/Resources.Management.Sdk/Generated/IResourceGroupsOperations.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ public partial interface IResourceGroupsOperations
9999
/// <param name='resourceGroupName'>
100100
/// The name of the resource group to get. The name is case insensitive.
101101
/// </param>
102+
/// <param name='expand'>
103+
/// Comma-separated list of additional properties to be included in the
104+
/// response. Valid values include createdTime, changedTime.
105+
/// </param>
102106
/// <param name='customHeaders'>
103107
/// The headers that will be added to request.
104108
/// </param>
@@ -111,7 +115,7 @@ public partial interface IResourceGroupsOperations
111115
/// <exception cref="Microsoft.Rest.SerializationException">
112116
/// Thrown when unable to deserialize the response
113117
/// </exception>
114-
System.Threading.Tasks.Task<Microsoft.Rest.Azure.AzureOperationResponse<ResourceGroup>> GetWithHttpMessagesAsync(string resourceGroupName, System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>> customHeaders = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
118+
System.Threading.Tasks.Task<Microsoft.Rest.Azure.AzureOperationResponse<ResourceGroup>> GetWithHttpMessagesAsync(string resourceGroupName, string expand = default(string), System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>> customHeaders = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
115119

116120
/// <summary>
117121
/// Resource groups can be updated through a simple PATCH operation to a group
@@ -190,7 +194,7 @@ public partial interface IResourceGroupsOperations
190194
/// <exception cref="Microsoft.Rest.SerializationException">
191195
/// Thrown when unable to deserialize the response
192196
/// </exception>
193-
System.Threading.Tasks.Task<Microsoft.Rest.Azure.AzureOperationResponse<Microsoft.Rest.Azure.IPage<ResourceGroup>>> ListWithHttpMessagesAsync(Microsoft.Rest.Azure.OData.ODataQuery<ResourceGroupFilter> odataQuery = default(Microsoft.Rest.Azure.OData.ODataQuery<ResourceGroupFilter>), System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>> customHeaders = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
197+
System.Threading.Tasks.Task<Microsoft.Rest.Azure.AzureOperationResponse<Microsoft.Rest.Azure.IPage<ResourceGroup>>> ListWithHttpMessagesAsync(Microsoft.Rest.Azure.OData.ODataQuery<ResourceGroupFilterWithExpand> odataQuery = default(Microsoft.Rest.Azure.OData.ODataQuery<ResourceGroupFilterWithExpand>), System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>> customHeaders = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
194198

195199
/// <summary>
196200
/// When you delete a resource group, all of its resources are also deleted.

src/Resources/Resources.Management.Sdk/Generated/Models/ResourceGroup.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,15 @@ public ResourceGroup()
4545

4646
/// <param name="tags">The tags attached to the resource group.
4747
/// </param>
48-
public ResourceGroup(string location, string id = default(string), string name = default(string), string type = default(string), ResourceGroupProperties properties = default(ResourceGroupProperties), string managedBy = default(string), System.Collections.Generic.IDictionary<string, string> tags = default(System.Collections.Generic.IDictionary<string, string>))
48+
49+
/// <param name="createdTime">The created time of the resource group. This is only present if requested
50+
/// via the $expand query parameter.
51+
/// </param>
52+
53+
/// <param name="changedTime">The changed time of the resource group. This is only present if requested
54+
/// via the $expand query parameter.
55+
/// </param>
56+
public ResourceGroup(string location, string id = default(string), string name = default(string), string type = default(string), ResourceGroupProperties properties = default(ResourceGroupProperties), string managedBy = default(string), System.Collections.Generic.IDictionary<string, string> tags = default(System.Collections.Generic.IDictionary<string, string>), System.DateTime? createdTime = default(System.DateTime?), System.DateTime? changedTime = default(System.DateTime?))
4957

5058
{
5159
this.Id = id;
@@ -55,6 +63,8 @@ public ResourceGroup()
5563
this.Location = location;
5664
this.ManagedBy = managedBy;
5765
this.Tags = tags;
66+
this.CreatedTime = createdTime;
67+
this.ChangedTime = changedTime;
5868
CustomInit();
5969
}
6070

@@ -107,6 +117,20 @@ public ResourceGroup()
107117
/// </summary>
108118
[Newtonsoft.Json.JsonProperty(PropertyName = "tags")]
109119
public System.Collections.Generic.IDictionary<string, string> Tags {get; set; }
120+
121+
/// <summary>
122+
/// Gets the created time of the resource group. This is only present if
123+
/// requested via the $expand query parameter.
124+
/// </summary>
125+
[Newtonsoft.Json.JsonProperty(PropertyName = "createdTime")]
126+
public System.DateTime? CreatedTime {get; private set; }
127+
128+
/// <summary>
129+
/// Gets the changed time of the resource group. This is only present if
130+
/// requested via the $expand query parameter.
131+
/// </summary>
132+
[Newtonsoft.Json.JsonProperty(PropertyName = "changedTime")]
133+
public System.DateTime? ChangedTime {get; private set; }
110134
/// <summary>
111135
/// Validate the object.
112136
/// </summary>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
// Code generated by Microsoft (R) AutoRest Code Generator.
4+
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
5+
6+
namespace Microsoft.Azure.Management.Resources.Models
7+
{
8+
using System.Linq;
9+
10+
public partial class ResourceGroupFilterWithExpand : ResourceGroupFilter
11+
{
12+
/// <summary>
13+
/// Initializes a new instance of the ResourceGroupFilterWithExpand class.
14+
/// </summary>
15+
public ResourceGroupFilterWithExpand()
16+
{
17+
CustomInit();
18+
}
19+
20+
/// <summary>
21+
/// Initializes a new instance of the ResourceGroupFilterWithExpand class.
22+
/// </summary>
23+
24+
/// <param name="tagName">The tag name.
25+
/// </param>
26+
27+
/// <param name="tagValue">The tag value.
28+
/// </param>
29+
30+
/// <param name="expand">Comma-separated list of additional properties to be included in the
31+
/// response. Valid values include createdTime, changedTime.
32+
/// </param>
33+
public ResourceGroupFilterWithExpand(string tagName = default(string), string tagValue = default(string), string expand = default(string))
34+
35+
: base(tagName, tagValue)
36+
{
37+
this.Expand = expand;
38+
CustomInit();
39+
}
40+
41+
/// <summary>
42+
/// An initialization method that performs custom operations like setting defaults
43+
/// </summary>
44+
partial void CustomInit();
45+
46+
47+
/// <summary>
48+
/// Gets or sets comma-separated list of additional properties to be included
49+
/// in the response. Valid values include createdTime, changedTime.
50+
/// </summary>
51+
[Newtonsoft.Json.JsonProperty(PropertyName = "$expand")]
52+
public string Expand {get; set; }
53+
}
54+
}

src/Resources/Resources.Management.Sdk/Generated/ResourceGroupsOperations.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,10 @@ internal ResourceGroupsOperations (ResourceManagementClient client)
521521
/// <param name='resourceGroupName'>
522522
/// The name of the resource group to get. The name is case insensitive.
523523
/// </param>
524+
/// <param name='expand'>
525+
/// Comma-separated list of additional properties to be included in the
526+
/// response. Valid values include createdTime, changedTime.
527+
/// </param>
524528
/// <param name='customHeaders'>
525529
/// Headers that will be added to request.
526530
/// </param>
@@ -542,7 +546,7 @@ internal ResourceGroupsOperations (ResourceManagementClient client)
542546
/// <return>
543547
/// A response object containing the response body and response headers.
544548
/// </return>
545-
public async System.Threading.Tasks.Task<Microsoft.Rest.Azure.AzureOperationResponse<ResourceGroup>> GetWithHttpMessagesAsync(string resourceGroupName, System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>> customHeaders = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
549+
public async System.Threading.Tasks.Task<Microsoft.Rest.Azure.AzureOperationResponse<ResourceGroup>> GetWithHttpMessagesAsync(string resourceGroupName, string expand = default(string), System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>> customHeaders = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
546550
{
547551

548552

@@ -577,6 +581,7 @@ internal ResourceGroupsOperations (ResourceManagementClient client)
577581
throw new Microsoft.Rest.ValidationException(Microsoft.Rest.ValidationRules.CannotBeNull, "this.Client.SubscriptionId");
578582
}
579583

584+
580585
// Tracing
581586
bool _shouldTrace = Microsoft.Rest.ServiceClientTracing.IsEnabled;
582587
string _invocationId = null;
@@ -585,6 +590,7 @@ internal ResourceGroupsOperations (ResourceManagementClient client)
585590
_invocationId = Microsoft.Rest.ServiceClientTracing.NextInvocationId.ToString();
586591
System.Collections.Generic.Dictionary<string, object> tracingParameters = new System.Collections.Generic.Dictionary<string, object>();
587592
tracingParameters.Add("resourceGroupName", resourceGroupName);
593+
tracingParameters.Add("expand", expand);
588594

589595

590596
tracingParameters.Add("cancellationToken", cancellationToken);
@@ -602,6 +608,10 @@ internal ResourceGroupsOperations (ResourceManagementClient client)
602608
{
603609
_queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(this.Client.ApiVersion)));
604610
}
611+
if (expand != null)
612+
{
613+
_queryParameters.Add(string.Format("$expand={0}", System.Uri.EscapeDataString(expand)));
614+
}
605615
if (_queryParameters.Count > 0)
606616
{
607617
_url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
@@ -1014,7 +1024,7 @@ internal ResourceGroupsOperations (ResourceManagementClient client)
10141024
/// <return>
10151025
/// A response object containing the response body and response headers.
10161026
/// </return>
1017-
public async System.Threading.Tasks.Task<Microsoft.Rest.Azure.AzureOperationResponse<Microsoft.Rest.Azure.IPage<ResourceGroup>>> ListWithHttpMessagesAsync(Microsoft.Rest.Azure.OData.ODataQuery<ResourceGroupFilter> odataQuery = default(Microsoft.Rest.Azure.OData.ODataQuery<ResourceGroupFilter>), System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>> customHeaders = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
1027+
public async System.Threading.Tasks.Task<Microsoft.Rest.Azure.AzureOperationResponse<Microsoft.Rest.Azure.IPage<ResourceGroup>>> ListWithHttpMessagesAsync(Microsoft.Rest.Azure.OData.ODataQuery<ResourceGroupFilterWithExpand> odataQuery = default(Microsoft.Rest.Azure.OData.ODataQuery<ResourceGroupFilterWithExpand>), System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>> customHeaders = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
10181028
{
10191029

10201030

@@ -1053,10 +1063,10 @@ internal ResourceGroupsOperations (ResourceManagementClient client)
10531063
System.Collections.Generic.List<string> _queryParameters = new System.Collections.Generic.List<string>();
10541064
if (odataQuery != null)
10551065
{
1056-
var _resourceGroupFilter = odataQuery.ToString();
1057-
if (!string.IsNullOrEmpty(_resourceGroupFilter))
1066+
var _resourceGroupFilterWithExpand = odataQuery.ToString();
1067+
if (!string.IsNullOrEmpty(_resourceGroupFilterWithExpand))
10581068
{
1059-
_queryParameters.Add(_resourceGroupFilter);
1069+
_queryParameters.Add(_resourceGroupFilterWithExpand);
10601070
}
10611071
}
10621072
if (this.Client.ApiVersion != null)

0 commit comments

Comments
 (0)