Skip to content

Commit 72bcfc8

Browse files
authored
Merge pull request #7403 from demyanenko/resourcegraph-cloud-shell-subscriptions
[ResourceGraph] Fetch subscriptions from ARM if AzureContext is not populated
2 parents 145f20c + a500713 commit 72bcfc8

File tree

12 files changed

+351
-16
lines changed

12 files changed

+351
-16
lines changed

src/ResourceManager/ResourceGraph/Commands.ResourceGraph.Test/ScenarioTests/TestController.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure.Commands.Common.Authentication;
16+
using Microsoft.Azure.Internal.Subscriptions;
1617
using Microsoft.Azure.Management.ResourceGraph;
1718
using Microsoft.Azure.Test.HttpRecorder;
1819
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
@@ -33,6 +34,8 @@ public class TestController : RMTestBase
3334

3435
public ResourceGraphClient ResourceGraphClient { get; private set; }
3536

37+
public SubscriptionClient SubscriptionClient { get; private set; }
38+
3639
public static TestController NewInstance => new TestController();
3740

3841
protected TestController()
@@ -78,12 +81,18 @@ public void RunPowerShellTest(ServiceManagemenet.Common.Models.XunitTracingInter
7881
protected void SetupManagementClients(MockContext context)
7982
{
8083
ResourceGraphClient = GetResourceGraphClient(context);
81-
_helper.SetupManagementClients(ResourceGraphClient);
84+
SubscriptionClient = GetSubscriptionClient(context);
85+
_helper.SetupManagementClients(ResourceGraphClient, SubscriptionClient);
8286
}
8387

8488
private static ResourceGraphClient GetResourceGraphClient(MockContext context)
8589
{
8690
return context.GetServiceClient<ResourceGraphClient>(TestEnvironmentFactory.GetTestEnvironment());
8791
}
92+
93+
private static SubscriptionClient GetSubscriptionClient(MockContext context)
94+
{
95+
return context.GetServiceClient<SubscriptionClient>(TestEnvironmentFactory.GetTestEnvironment());
96+
}
8897
}
8998
}

src/ResourceManager/ResourceGraph/Commands.ResourceGraph.Test/SessionRecords/Microsoft.Azure.Commands.ResourceGraph.Test.ScenarioTests.ResourceGraphQueryTests/PagedQuery.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,65 @@
11
{
22
"Entries": [
3+
{
4+
"RequestUri": "/subscriptions?api-version=2016-06-01",
5+
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnM/YXBpLXZlcnNpb249MjAxNi0wNi0wMQ==",
6+
"RequestMethod": "GET",
7+
"RequestBody": "",
8+
"RequestHeaders": {
9+
"x-ms-client-request-id": [
10+
"31537677-7032-4654-becb-372f2eeebf21"
11+
],
12+
"accept-language": [
13+
"en-US"
14+
],
15+
"User-Agent": [
16+
"FxVersion/4.7.3163.0",
17+
"OSName/Windows10Enterprise",
18+
"OSVersion/6.3.17134",
19+
"Microsoft.Azure.Internal.Subscriptions.SubscriptionClient/4.1.0"
20+
]
21+
},
22+
"ResponseBody": "{\"value\": [{\"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000\", \"subscriptionId\": \"00000000-0000-0000-0000-000000000000\", \"displayName\": \"Test Subscription\", \"state\": \"Enabled\", \"authorizationSource\": \"RoleBased\"}]}",
23+
"ResponseHeaders": {
24+
"Content-Length": [
25+
"987"
26+
],
27+
"Content-Type": [
28+
"application/json; charset=utf-8"
29+
],
30+
"Expires": [
31+
"-1"
32+
],
33+
"Pragma": [
34+
"no-cache"
35+
],
36+
"x-ms-ratelimit-remaining-tenant-reads": [
37+
"11999"
38+
],
39+
"x-ms-request-id": [
40+
"dc5b4ea5-4059-44fa-9d49-5c48f46224f4"
41+
],
42+
"x-ms-correlation-request-id": [
43+
"dc5b4ea5-4059-44fa-9d49-5c48f46224f4"
44+
],
45+
"x-ms-routing-request-id": [
46+
"WESTUS2:20180926T232942Z:dc5b4ea5-4059-44fa-9d49-5c48f46224f4"
47+
],
48+
"Strict-Transport-Security": [
49+
"max-age=31536000; includeSubDomains"
50+
],
51+
"X-Content-Type-Options": [
52+
"nosniff"
53+
],
54+
"Cache-Control": [
55+
"no-cache"
56+
],
57+
"Date": [
58+
"Wed, 26 Sep 2018 23:29:41 GMT"
59+
]
60+
},
61+
"StatusCode": 200
62+
},
363
{
464
"RequestUri": "/providers/Microsoft.ResourceGraph/resources?api-version=2018-09-01-preview",
565
"EncodedRequestUri": "L3Byb3ZpZGVycy9NaWNyb3NvZnQuUmVzb3VyY2VHcmFwaC9yZXNvdXJjZXM/YXBpLXZlcnNpb249MjAxOC0wOS0wMS1wcmV2aWV3",

src/ResourceManager/ResourceGraph/Commands.ResourceGraph.Test/SessionRecords/Microsoft.Azure.Commands.ResourceGraph.Test.ScenarioTests.ResourceGraphQueryTests/Query.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,65 @@
11
{
22
"Entries": [
3+
{
4+
"RequestUri": "/subscriptions?api-version=2016-06-01",
5+
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnM/YXBpLXZlcnNpb249MjAxNi0wNi0wMQ==",
6+
"RequestMethod": "GET",
7+
"RequestBody": "",
8+
"RequestHeaders": {
9+
"x-ms-client-request-id": [
10+
"31537677-7032-4654-becb-372f2eeebf21"
11+
],
12+
"accept-language": [
13+
"en-US"
14+
],
15+
"User-Agent": [
16+
"FxVersion/4.7.3163.0",
17+
"OSName/Windows10Enterprise",
18+
"OSVersion/6.3.17134",
19+
"Microsoft.Azure.Internal.Subscriptions.SubscriptionClient/4.1.0"
20+
]
21+
},
22+
"ResponseBody": "{\"value\": [{\"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000\", \"subscriptionId\": \"00000000-0000-0000-0000-000000000000\", \"displayName\": \"Test Subscription\", \"state\": \"Enabled\", \"authorizationSource\": \"RoleBased\"}]}",
23+
"ResponseHeaders": {
24+
"Content-Length": [
25+
"987"
26+
],
27+
"Content-Type": [
28+
"application/json; charset=utf-8"
29+
],
30+
"Expires": [
31+
"-1"
32+
],
33+
"Pragma": [
34+
"no-cache"
35+
],
36+
"x-ms-ratelimit-remaining-tenant-reads": [
37+
"11999"
38+
],
39+
"x-ms-request-id": [
40+
"dc5b4ea5-4059-44fa-9d49-5c48f46224f4"
41+
],
42+
"x-ms-correlation-request-id": [
43+
"dc5b4ea5-4059-44fa-9d49-5c48f46224f4"
44+
],
45+
"x-ms-routing-request-id": [
46+
"WESTUS2:20180926T232942Z:dc5b4ea5-4059-44fa-9d49-5c48f46224f4"
47+
],
48+
"Strict-Transport-Security": [
49+
"max-age=31536000; includeSubDomains"
50+
],
51+
"X-Content-Type-Options": [
52+
"nosniff"
53+
],
54+
"Cache-Control": [
55+
"no-cache"
56+
],
57+
"Date": [
58+
"Wed, 26 Sep 2018 23:29:41 GMT"
59+
]
60+
},
61+
"StatusCode": 200
62+
},
363
{
464
"RequestUri": "/providers/Microsoft.ResourceGraph/resources?api-version=2018-09-01-preview",
565
"EncodedRequestUri": "L3Byb3ZpZGVycy9NaWNyb3NvZnQuUmVzb3VyY2VHcmFwaC9yZXNvdXJjZXM/YXBpLXZlcnNpb249MjAxOC0wOS0wMS1wcmV2aWV3",

src/ResourceManager/ResourceGraph/Commands.ResourceGraph.Test/SessionRecords/Microsoft.Azure.Commands.ResourceGraph.Test.ScenarioTests.ResourceGraphQueryTests/QueryError.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,65 @@
11
{
22
"Entries": [
3+
{
4+
"RequestUri": "/subscriptions?api-version=2016-06-01",
5+
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnM/YXBpLXZlcnNpb249MjAxNi0wNi0wMQ==",
6+
"RequestMethod": "GET",
7+
"RequestBody": "",
8+
"RequestHeaders": {
9+
"x-ms-client-request-id": [
10+
"31537677-7032-4654-becb-372f2eeebf21"
11+
],
12+
"accept-language": [
13+
"en-US"
14+
],
15+
"User-Agent": [
16+
"FxVersion/4.7.3163.0",
17+
"OSName/Windows10Enterprise",
18+
"OSVersion/6.3.17134",
19+
"Microsoft.Azure.Internal.Subscriptions.SubscriptionClient/4.1.0"
20+
]
21+
},
22+
"ResponseBody": "{\"value\": [{\"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000\", \"subscriptionId\": \"00000000-0000-0000-0000-000000000000\", \"displayName\": \"Test Subscription\", \"state\": \"Enabled\", \"authorizationSource\": \"RoleBased\"}]}",
23+
"ResponseHeaders": {
24+
"Content-Length": [
25+
"987"
26+
],
27+
"Content-Type": [
28+
"application/json; charset=utf-8"
29+
],
30+
"Expires": [
31+
"-1"
32+
],
33+
"Pragma": [
34+
"no-cache"
35+
],
36+
"x-ms-ratelimit-remaining-tenant-reads": [
37+
"11999"
38+
],
39+
"x-ms-request-id": [
40+
"dc5b4ea5-4059-44fa-9d49-5c48f46224f4"
41+
],
42+
"x-ms-correlation-request-id": [
43+
"dc5b4ea5-4059-44fa-9d49-5c48f46224f4"
44+
],
45+
"x-ms-routing-request-id": [
46+
"WESTUS2:20180926T232942Z:dc5b4ea5-4059-44fa-9d49-5c48f46224f4"
47+
],
48+
"Strict-Transport-Security": [
49+
"max-age=31536000; includeSubDomains"
50+
],
51+
"X-Content-Type-Options": [
52+
"nosniff"
53+
],
54+
"Cache-Control": [
55+
"no-cache"
56+
],
57+
"Date": [
58+
"Wed, 26 Sep 2018 23:29:41 GMT"
59+
]
60+
},
61+
"StatusCode": 200
62+
},
363
{
464
"RequestUri": "/providers/Microsoft.ResourceGraph/resources?api-version=2018-09-01-preview",
565
"EncodedRequestUri": "L3Byb3ZpZGVycy9NaWNyb3NvZnQuUmVzb3VyY2VHcmFwaC9yZXNvdXJjZXM/YXBpLXZlcnNpb249MjAxOC0wOS0wMS1wcmV2aWV3",

src/ResourceManager/ResourceGraph/Commands.ResourceGraph.Test/SessionRecords/Microsoft.Azure.Commands.ResourceGraph.Test.ScenarioTests.ResourceGraphQueryTests/Subscriptions.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,65 @@
11
{
22
"Entries": [
3+
{
4+
"RequestUri": "/subscriptions?api-version=2016-06-01",
5+
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnM/YXBpLXZlcnNpb249MjAxNi0wNi0wMQ==",
6+
"RequestMethod": "GET",
7+
"RequestBody": "",
8+
"RequestHeaders": {
9+
"x-ms-client-request-id": [
10+
"31537677-7032-4654-becb-372f2eeebf21"
11+
],
12+
"accept-language": [
13+
"en-US"
14+
],
15+
"User-Agent": [
16+
"FxVersion/4.7.3163.0",
17+
"OSName/Windows10Enterprise",
18+
"OSVersion/6.3.17134",
19+
"Microsoft.Azure.Internal.Subscriptions.SubscriptionClient/4.1.0"
20+
]
21+
},
22+
"ResponseBody": "{\"value\": [{\"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000\", \"subscriptionId\": \"00000000-0000-0000-0000-000000000000\", \"displayName\": \"Test Subscription\", \"state\": \"Enabled\", \"authorizationSource\": \"RoleBased\"}]}",
23+
"ResponseHeaders": {
24+
"Content-Length": [
25+
"987"
26+
],
27+
"Content-Type": [
28+
"application/json; charset=utf-8"
29+
],
30+
"Expires": [
31+
"-1"
32+
],
33+
"Pragma": [
34+
"no-cache"
35+
],
36+
"x-ms-ratelimit-remaining-tenant-reads": [
37+
"11999"
38+
],
39+
"x-ms-request-id": [
40+
"dc5b4ea5-4059-44fa-9d49-5c48f46224f4"
41+
],
42+
"x-ms-correlation-request-id": [
43+
"dc5b4ea5-4059-44fa-9d49-5c48f46224f4"
44+
],
45+
"x-ms-routing-request-id": [
46+
"WESTUS2:20180926T232942Z:dc5b4ea5-4059-44fa-9d49-5c48f46224f4"
47+
],
48+
"Strict-Transport-Security": [
49+
"max-age=31536000; includeSubDomains"
50+
],
51+
"X-Content-Type-Options": [
52+
"nosniff"
53+
],
54+
"Cache-Control": [
55+
"no-cache"
56+
],
57+
"Date": [
58+
"Wed, 26 Sep 2018 23:29:41 GMT"
59+
]
60+
},
61+
"StatusCode": 200
62+
},
363
{
464
"RequestUri": "/providers/Microsoft.ResourceGraph/resources?api-version=2018-09-01-preview",
565
"EncodedRequestUri": "L3Byb3ZpZGVycy9NaWNyb3NvZnQuUmVzb3VyY2VHcmFwaC9yZXNvdXJjZXM/YXBpLXZlcnNpb249MjAxOC0wOS0wMS1wcmV2aWV3",

src/ResourceManager/ResourceGraph/Commands.ResourceGraph/Az.ResourceGraph.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# RootModule = ''
1313

1414
# Version number of this module.
15-
ModuleVersion = '0.2.0'
15+
ModuleVersion = '0.2.1'
1616

1717
# Supported PSEditions
1818
CompatiblePSEditions = 'Core', 'Desktop'

src/ResourceManager/ResourceGraph/Commands.ResourceGraph/AzureRM.ResourceGraph.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# RootModule = ''
1313

1414
# Version number of this module.
15-
ModuleVersion = '0.1.0'
15+
ModuleVersion = '0.1.1'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()

src/ResourceManager/ResourceGraph/Commands.ResourceGraph/ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
-->
2020
## Current Release
2121

22+
## Version 0.1.1-preview
23+
* Fixed an issue with subscriptions not getting populated in Cloud Shell
24+
2225
## Version 0.1.0-preview
2326
* Public preview release of Resource Graph cmdlets

0 commit comments

Comments
 (0)