-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for output type and null subscriptions collection in ResourceGraph #15135
Changes from all commits
cc484e5
98014e0
20b60e4
715c66f
2ed371a
6c8892b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<?xml version="1.0"?> | ||
<Configuration> | ||
<ViewDefinitions> | ||
<View> | ||
<Name>Microsoft.Azure.Commands.ResourceGraph.Models.PSResourceGraphResponse</Name> | ||
<Name>Microsoft.Azure.Commands.ResourceGraph.Models.PSResourceGraphResponse`1[[System.Management.Automation.PSObject]]</Name> | ||
<ViewSelectedBy> | ||
<TypeName>Microsoft.Azure.Commands.ResourceGraph.Models.PSResourceGraphResponse</TypeName> | ||
<TypeName>Microsoft.Azure.Commands.ResourceGraph.Models.PSResourceGraphResponse`1[[System.Management.Automation.PSObject]]</TypeName> | ||
</ViewSelectedBy> | ||
<ListControl> | ||
<ListEntries> | ||
<ListEntry> | ||
<ListItems> | ||
<ListItem> | ||
<PropertyName>SkipToken</PropertyName> | ||
<ItemSelectionCondition> | ||
<ScriptBlock> | ||
$_.SkipToken -ne $null | ||
</ScriptBlock> | ||
</ItemSelectionCondition> | ||
</ListItem> | ||
<ListItem> | ||
<PropertyName>Data</PropertyName> | ||
</ListItem> | ||
</ListItem> | ||
</ListItems> | ||
</ListEntry> | ||
</ListEntries> | ||
</ListControl> | ||
</View> | ||
</ViewDefinitions> | ||
</Configuration> | ||
</Configuration> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,17 +14,53 @@ | |
|
||
namespace Microsoft.Azure.Commands.ResourceGraph.Models | ||
{ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Management.Automation; | ||
using Microsoft.WindowsAzure.Commands.Common.Attributes; | ||
|
||
public class PSResourceGraphResponse | ||
public class PSResourceGraphResponse<PSObject> : IList<PSObject> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @VeryEarly thank you very much for all the help here addressing our cmdlets compatibility issues and formatter concers. You Rock !!!:thumbsup: :rocket: |
||
{ | ||
[Ps1Xml(Target = ViewControl.List)] | ||
fenwickt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public string SkipToken { get; set; } | ||
|
||
[Ps1Xml(Target = ViewControl.List)] | ||
public IList<PSObject> Data { get; set; } | ||
public PSObject this[int index] | ||
{ | ||
get => Data[index]; | ||
set => Data[index] = value; | ||
} | ||
|
||
public IEnumerator<PSObject> GetEnumerator() | ||
{ | ||
return Data.GetEnumerator(); | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() | ||
{ | ||
return GetEnumerator(); | ||
} | ||
|
||
public bool IsReadOnly => Data.IsReadOnly; | ||
|
||
public int Count => Data.Count; | ||
|
||
public void Add(PSObject value) => Data.Add(value); | ||
|
||
public void Clear() => Data.Clear(); | ||
|
||
public bool Contains(PSObject value) => Data.Contains(value); | ||
|
||
public void CopyTo(PSObject[] array, int index) => Data.CopyTo(array, index); | ||
|
||
public int IndexOf(PSObject value) => Data.IndexOf(value); | ||
|
||
public void Insert(int index, PSObject value) => Data.Insert(index, value); | ||
|
||
public void Remove(PSObject value) => Data.Remove(value); | ||
|
||
public void RemoveAt(int index) => Data.RemoveAt(index); | ||
|
||
bool ICollection<PSObject>.Remove(PSObject item) => Data.Remove(item); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,12 +39,14 @@ name : nt | |
type : microsoft.compute/virtualmachinescalesets | ||
location : eastus | ||
tags : @{resourceType=Service Fabric; clusterName=gov-art-int-nt-a} | ||
ResourceId : /subscriptions/1ef51df4-f8a9-4b69-9919-1ef51df4eff6/resourceGroups/Service-INT-a/providers/Microsoft.Compute/virtualMachineScaleSets/nt | ||
|
||
id : /subscriptions/1ef51df4-f8a9-4b69-9919-1ef51df4eff6/resourceGroups/Service-INT-a/providers/Microsoft.EventGrid/topics/egtopic-1 | ||
name : egtopic-1 | ||
type : microsoft.eventgrid/topics | ||
location : westus2 | ||
tags : | ||
ResourceId : /subscriptions/1ef51df4-f8a9-4b69-9919-1ef51df4eff6/resourceGroups/Service-INT-a/providers/Microsoft.EventGrid/topics/egtopic-1 | ||
``` | ||
|
||
Simple resources query requesting a subset of resource fields. | ||
|
@@ -64,34 +66,43 @@ A complex query on resources featuring field selection, filtering and summarizin | |
|
||
### Example 3 | ||
```powershell | ||
PS C:\> Search-AzGraph -Query 'project id, name' -SkipToken 'skiptokenvaluefromthepreviousquery==' | ||
PS C:\> $response = Search-AzGraph -Query "project id, name, type, location" -First 2 | ||
PS C:\> Search-AzGraph -Query "project id, name, type, location" -SkipToken $response.SkipToken | ||
|
||
|
||
id : /subscriptions/1ef51df4-f8a9-4b69-9919-1ef51df4eff6/resourceGroups/Service-INT-b/providers/Microsoft.Compute/virtualMachineScaleSets/nt2 | ||
name : nt2 | ||
id : /subscriptions/1ef51df4-f8a9-4b69-9919-1ef51df4eff6/resourceGroups/test/providers/Microsoft.Network/networkInterfaces/17ni | ||
name : 17ni | ||
type : microsoft.network/networkinterfaces | ||
location : westeurope | ||
ResourceId : /subscriptions/1ef51df4-f8a9-4b69-9919-1ef51df4eff6/resourceGroups/test/providers/Microsoft.Network/networkInterfaces/17ni | ||
|
||
id : /subscriptions/1ef51df4-f8a9-4b69-9919-1ef51df4eff6/resourceGroups/Service-INT-b/providers/Microsoft.EventGrid/topics/egtopic-2 | ||
name : egtopic-2 | ||
id : /subscriptions/1ef51df4-f8a9-4b69-9919-1ef51df4eff6/resourceGroups/test/providers/Microsoft.Network/networkSecurityGroups/17nsg | ||
name : 17nsg | ||
type : microsoft.network/networksecuritygroups | ||
location : westeurope | ||
ResourceId : /subscriptions/1ef51df4-f8a9-4b69-9919-1ef51df4eff6/resourceGroups/test/providers/Microsoft.Network/networkSecurityGroups/17nsg | ||
``` | ||
|
||
A query with the skip token passed from the previous query results | ||
A query with the skip token passed from the previous query results. Please note that keeping id in the results is mandatory to get back a skip token. | ||
|
||
### Example 4 | ||
```powershell | ||
PS C:\> Search-AzGraph -Query 'project id, name, type, location, tags' -First 2 -ManagementGroup 'MyManagementGroupId' -AllowPartialScope | ||
PS C:\> Search-AzGraph -Query "project id, name, type, location, tags" -First 2 -ManagementGroup MyManagementGroupId -AllowPartialScope | ||
|
||
|
||
id : /subscriptions/1ef51df4-f8a9-4b69-9919-1ef51df4eff6/resourceGroups/Service-INT-a/providers/Microsoft.Compute/virtualMachineScaleSets/nt | ||
name : nt | ||
type : microsoft.compute/virtualmachinescalesets | ||
location : eastus | ||
tags : @{resourceType=Service Fabric; clusterName=gov-art-int-nt-a} | ||
ResourceId : /subscriptions/1ef51df4-f8a9-4b69-9919-1ef51df4eff6/resourceGroups/Service-INT-a/providers/Microsoft.Compute/virtualMachineScaleSets/nt | ||
|
||
id : /subscriptions/1ef51df4-f8a9-4b69-9919-1ef51df4eff6/resourceGroups/Service-INT-a/providers/Microsoft.EventGrid/topics/egtopic-1 | ||
name : egtopic-1 | ||
type : microsoft.eventgrid/topics | ||
location : westus2 | ||
tags : | ||
ResourceId : /subscriptions/1ef51df4-f8a9-4b69-9919-1ef51df4eff6/resourceGroups/Service-INT-a/providers/Microsoft.EventGrid/topics/egtopic-1 | ||
``` | ||
|
||
A query scoped to the management group that allows the query to succeed with partial scope result if MyManagementGroupId has more than N subscriptions underneath. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this statement feels keeping it open question to end customers thinking about what is the N means for my tenant. N => 1000 or 5000. Should we add information on - if the given management group exceeds the limit of number of allowed subscriptions while querying for resources. Also provide information that while querying for container resources we don't have any limits. |
||
|
@@ -229,7 +240,7 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable | |
|
||
## OUTPUTS | ||
|
||
### Microsoft.Azure.Commands.ResourceGraph.Models.PSResourceGraphResponse | ||
### Microsoft.Azure.Commands.ResourceGraph.Models.PSResourceGraphResponse`1[[System.Management.Automation.PSObject]] | ||
|
||
## NOTES | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"AssemblyFileName","ClassName","Target","Severity","ProblemId","Description","Remediation" | ||
"Az.ResourceGraph","Microsoft.Azure.Commands.ResourceGraph.Cmdlets.SearchAzureRmGraph","Search-AzGraph","0","1020","The cmdlet 'Search-AzGraph' no longer has output type 'Microsoft.Azure.Commands.ResourceGraph.Models.PSResourceGraphResponse'.","Make cmdlet 'Search-AzGraph' return type 'Microsoft.Azure.Commands.ResourceGraph.Models.PSResourceGraphResponse'." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please let me know if I should revert this change. I wasn't able to run tests locally without it.