Skip to content

Commit 8af39a4

Browse files
work
1 parent bbc3da2 commit 8af39a4

File tree

3 files changed

+64
-54
lines changed

3 files changed

+64
-54
lines changed

src/vscode-bicep/package-lock.json

+34-41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/vscode-bicep/src/azure/AzureUiManager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class AzureUiManager implements IAzureUiManager {
9898
await this.azurePickers.EnsureSignedIn();
9999

100100
const subscriptionId = this.getSubscriptionId(scope);
101-
const subscriptions = await this.azurePickers.getAllSubscriptions(); //asdfg cache
101+
const subscriptions = await this.azurePickers.getAllSubscriptions();
102102
const subscription = subscriptions.find((s) => s.subscriptionId === subscriptionId);
103103
if (!subscription) {
104104
throw new Error(`Subscription with ID "${subscriptionId}" not found.`);

src/vscode-bicep/src/utils/AzurePickers.ts

+29-12
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ export class AzurePickers extends Disposable {
3636
super();
3737
}
3838

39-
public async getFilteredSubscriptions(): Promise<AzureSubscription[]> {
40-
return await this.vsCodeAzureSubscriptionProvider.getSubscriptions(true);
41-
}
42-
4339
public async getAllSubscriptions(): Promise<AzureSubscription[]> {
4440
return await this.vsCodeAzureSubscriptionProvider.getSubscriptions(false);
4541
}
@@ -144,11 +140,26 @@ export class AzurePickers extends Disposable {
144140
public async pickSubscription(context: IActionContext): Promise<AzureSubscription> {
145141
await this.EnsureSignedIn();
146142

147-
const subscriptions = await this.vsCodeAzureSubscriptionProvider.getSubscriptions();
143+
const subscriptions = await this.getAllSubscriptions();
148144
if (subscriptions.length === 0) {
149-
throw new Error("No subscriptions found");
145+
let message = "No subscriptions found.";
146+
try {
147+
const tenants = await this.vsCodeAzureSubscriptionProvider.getTenants();
148+
const signInStatusPromises = tenants.map(async (tenant) => {
149+
const isSignedIn = await this.vsCodeAzureSubscriptionProvider.isSignedIn(tenant.tenantId);
150+
return `${tenant.tenantId} (${isSignedIn ? 'signed in' : 'signed out'})`;
151+
});
152+
const signInStatus = await Promise.all(signInStatusPromises);
153+
message += ` Available tenants: ${signInStatus.join(", ")}`;
154+
} catch (err) {
155+
this.outputChannelManager.appendToOutputChannel(parseError(err).message);
156+
}
157+
158+
throw new Error(message);
150159
}
151160

161+
subscriptions.sort((a, b) => a.name.localeCompare(b.name));
162+
152163
const picks = subscriptions.map(s => {
153164
return <IAzureQuickPickItem<AzureSubscription>>{
154165
label: s.name,
@@ -167,6 +178,8 @@ export class AzurePickers extends Disposable {
167178
const client: ResourceManagementClient = await createResourceManagementClient([context, subscriptionContext]);
168179
const rgs: ResourceGroup[] = await uiUtils.listAllIterator(client.resourceGroups.list());
169180

181+
rgs.sort((a, b) => nonNullProp(a, "name").localeCompare(nonNullProp(b, "name")));
182+
170183
const createNewRGItem: IAzureQuickPickItem<ResourceGroup | undefined> = {
171184
label: '$(plus) Create new resource group',
172185
data: undefined,
@@ -190,7 +203,7 @@ export class AzurePickers extends Disposable {
190203

191204
const selected = await context.ui.showQuickPick(picks, { placeHolder: "Select resource group" });
192205
if (selected === createNewRGItem) {
193-
return await this.promptAndCreateResourceGroup(context, subscription);
206+
return await this.promptCreateResourceGroup(context, subscription);
194207
} else {
195208
return selected.data!;
196209
}
@@ -200,7 +213,9 @@ export class AzurePickers extends Disposable {
200213
await this.EnsureSignedIn();
201214

202215
const client = await createSubscriptionClient([context, createSubscriptionContext(subscription)]);
203-
const locations = (await uiUtils.listAllIterator(client.subscriptions.listLocations(subscription.subscriptionId))).map(l => l.name);
216+
const locations = (await uiUtils.listAllIterator(client.subscriptions.listLocations(subscription.subscriptionId))).map(l => nonNullProp(l, "name"));
217+
locations.sort();
218+
204219
const picks = locations.map((l) => <IAzureQuickPickItem<string>>{
205220
label: l,
206221
data: l
@@ -213,23 +228,25 @@ export class AzurePickers extends Disposable {
213228
await this.EnsureSignedIn();
214229

215230
const managementGroupsAPI = new ManagementGroupsAPI(new DefaultAzureCredential());
216-
let managementGroupInfos: ManagementGroupInfo[];
231+
let managementGroups: ManagementGroupInfo[];
217232
try {
218-
managementGroupInfos = await uiUtils.listAllIterator(managementGroupsAPI.managementGroups.list());
233+
managementGroups = await uiUtils.listAllIterator(managementGroupsAPI.managementGroups.list());
219234
} catch (err) {
220235
throw new Error(`You might not have access to any management groups. Please create one in the Azure portal and try to deploy again. Error: ${parseError(err).message}`,
221236
);
222237
}
223238

224-
const picks = managementGroupInfos.map((mg) => <IAzureQuickPickItem<ManagementGroupInfo>>{
239+
managementGroups.sort((a, b) => nonNullProp(a, "name").localeCompare(nonNullProp(b, "name")));
240+
241+
const picks = managementGroups.map((mg) => <IAzureQuickPickItem<ManagementGroupInfo>>{
225242
label: mg.name,
226243
data: mg,
227244
});
228245

229246
return (await context.ui.showQuickPick(picks, { placeHolder: "Select management group" })).data;
230247
}
231248

232-
private async promptAndCreateResourceGroup(context: IActionContext, subscription: AzureSubscription): Promise<ResourceGroup> {
249+
private async promptCreateResourceGroup(context: IActionContext, subscription: AzureSubscription): Promise<ResourceGroup> {
233250
const subscriptionContext = createSubscriptionContext(subscription);
234251
const wizardContext: IResourceGroupWizardContext = {
235252
...context,

0 commit comments

Comments
 (0)