Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenWeatherford committed Oct 30, 2024
1 parent bbc3da2 commit 8af39a4
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 54 deletions.
75 changes: 34 additions & 41 deletions src/vscode-bicep/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/vscode-bicep/src/azure/AzureUiManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class AzureUiManager implements IAzureUiManager {
await this.azurePickers.EnsureSignedIn();

const subscriptionId = this.getSubscriptionId(scope);
const subscriptions = await this.azurePickers.getAllSubscriptions(); //asdfg cache
const subscriptions = await this.azurePickers.getAllSubscriptions();
const subscription = subscriptions.find((s) => s.subscriptionId === subscriptionId);
if (!subscription) {
throw new Error(`Subscription with ID "${subscriptionId}" not found.`);
Expand Down
41 changes: 29 additions & 12 deletions src/vscode-bicep/src/utils/AzurePickers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ export class AzurePickers extends Disposable {
super();
}

public async getFilteredSubscriptions(): Promise<AzureSubscription[]> {
return await this.vsCodeAzureSubscriptionProvider.getSubscriptions(true);
}

public async getAllSubscriptions(): Promise<AzureSubscription[]> {
return await this.vsCodeAzureSubscriptionProvider.getSubscriptions(false);
}
Expand Down Expand Up @@ -144,11 +140,26 @@ export class AzurePickers extends Disposable {
public async pickSubscription(context: IActionContext): Promise<AzureSubscription> {
await this.EnsureSignedIn();

const subscriptions = await this.vsCodeAzureSubscriptionProvider.getSubscriptions();
const subscriptions = await this.getAllSubscriptions();
if (subscriptions.length === 0) {
throw new Error("No subscriptions found");
let message = "No subscriptions found.";
try {
const tenants = await this.vsCodeAzureSubscriptionProvider.getTenants();
const signInStatusPromises = tenants.map(async (tenant) => {
const isSignedIn = await this.vsCodeAzureSubscriptionProvider.isSignedIn(tenant.tenantId);
return `${tenant.tenantId} (${isSignedIn ? 'signed in' : 'signed out'})`;
});
const signInStatus = await Promise.all(signInStatusPromises);
message += ` Available tenants: ${signInStatus.join(", ")}`;
} catch (err) {
this.outputChannelManager.appendToOutputChannel(parseError(err).message);
}

throw new Error(message);
}

subscriptions.sort((a, b) => a.name.localeCompare(b.name));

const picks = subscriptions.map(s => {
return <IAzureQuickPickItem<AzureSubscription>>{
label: s.name,
Expand All @@ -167,6 +178,8 @@ export class AzurePickers extends Disposable {
const client: ResourceManagementClient = await createResourceManagementClient([context, subscriptionContext]);
const rgs: ResourceGroup[] = await uiUtils.listAllIterator(client.resourceGroups.list());

rgs.sort((a, b) => nonNullProp(a, "name").localeCompare(nonNullProp(b, "name")));

const createNewRGItem: IAzureQuickPickItem<ResourceGroup | undefined> = {
label: '$(plus) Create new resource group',
data: undefined,
Expand All @@ -190,7 +203,7 @@ export class AzurePickers extends Disposable {

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

const client = await createSubscriptionClient([context, createSubscriptionContext(subscription)]);
const locations = (await uiUtils.listAllIterator(client.subscriptions.listLocations(subscription.subscriptionId))).map(l => l.name);
const locations = (await uiUtils.listAllIterator(client.subscriptions.listLocations(subscription.subscriptionId))).map(l => nonNullProp(l, "name"));
locations.sort();

const picks = locations.map((l) => <IAzureQuickPickItem<string>>{
label: l,
data: l
Expand All @@ -213,23 +228,25 @@ export class AzurePickers extends Disposable {
await this.EnsureSignedIn();

const managementGroupsAPI = new ManagementGroupsAPI(new DefaultAzureCredential());
let managementGroupInfos: ManagementGroupInfo[];
let managementGroups: ManagementGroupInfo[];
try {
managementGroupInfos = await uiUtils.listAllIterator(managementGroupsAPI.managementGroups.list());
managementGroups = await uiUtils.listAllIterator(managementGroupsAPI.managementGroups.list());
} catch (err) {
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}`,
);
}

const picks = managementGroupInfos.map((mg) => <IAzureQuickPickItem<ManagementGroupInfo>>{
managementGroups.sort((a, b) => nonNullProp(a, "name").localeCompare(nonNullProp(b, "name")));

const picks = managementGroups.map((mg) => <IAzureQuickPickItem<ManagementGroupInfo>>{
label: mg.name,
data: mg,
});

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

private async promptAndCreateResourceGroup(context: IActionContext, subscription: AzureSubscription): Promise<ResourceGroup> {
private async promptCreateResourceGroup(context: IActionContext, subscription: AzureSubscription): Promise<ResourceGroup> {
const subscriptionContext = createSubscriptionContext(subscription);
const wizardContext: IResourceGroupWizardContext = {
...context,
Expand Down

0 comments on commit 8af39a4

Please sign in to comment.