Skip to content
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

Add Tenants view #869

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Add Tenants view #869

wants to merge 12 commits into from

Conversation

motm32
Copy link
Contributor

@motm32 motm32 commented Jun 3, 2024

Completes #849

Here is how the view will look:
image

Detailed changes

Related to accounts:

  • This view will contain information related to accounts and tenants associated with those accounts. With this we also allow support users being signed into multiple accounts
  • If the user is not signed into any azure account the Tenants view will include a "Sign in" button similar to the Resources view.
  • With Multi-Account support there is the possibility that duplicate subscriptions can show up if the same subscription belongs to multiple tenants. In this case we will add in the description of the subscription item in the resources view the associated tenant so users know which tenant they are making changes under. This will look like this
    image

Related to tenants:

  • Checking and unchecking tenants within the view will update the subscriptions shown in the Resources view and the subscription filter. Along with this if the checked tenants or if no tenants match any subscriptions then by default all subscriptions will be shown.
  • If a tenant needs further authentication the tenant will default to being unchecked and a button will appear if a user hovers over the unauthenticated tenants which users can press to authenticate the tenant. Users can also right click on the unauthenticated tenant and click Sign in to Tenant. Finally if users check an unauthenticated tenant they will automatically be prompted to sign into that tenant. image

To do:

  • Changes to the Sign out of Azure code so the tenants view also gets refreshed
  • Integrate VSCode api changes to getsessions() once they are released
  • Add multi-account support

package.json Show resolved Hide resolved
src/commands/registerCommands.ts Show resolved Hide resolved
src/tree/tenants/TenantResourceTreeDataProvider.ts Outdated Show resolved Hide resolved
@alexweininger
Copy link
Member

Note for later: lets update the people in this issue once this is merged - microsoft/vscode-azure-account#901

@motm32 motm32 marked this pull request as ready for review August 29, 2024 20:51
@motm32 motm32 requested a review from a team as a code owner August 29, 2024 20:51
@motm32
Copy link
Contributor Author

motm32 commented Sep 3, 2024

Also just a note for reviewing. This includes a lot of code at the moment that is from the auth tools package for testing purposes. I will remove that code once we are closer to being done.

api/src/index.ts Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment on this file: if we don't want to expose the tenants view on the api, I don't think we need this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're not using them and it's easy to remove, I think we should remove the branch data item cache and tree item state store from the tenants tree.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove it because I don't think I am using it but createTreeView requires an itemCache. I could maybe modify that or use something else but that makes that a little tricky to remove.

The item state store should be easy to remove so I will go ahead and do that.

Comment on lines 59 to 77

async activateTenantResourceBranchDataProvider(type: string): Promise<void> {
const extensionAndContributions =
getInactiveExtensions()
.map(extension => ({ extension, contributions: getResourceContributions(extension)?.tenant?.branches?.map(resources => resources.type) ?? [] }))
.find(extensionAndContributions => extensionAndContributions.contributions.find(contribution => contribution === type) !== undefined);
if (extensionAndContributions) {
await extensionAndContributions.extension.activate();
}
}

async activateTenantResourceProviders(): Promise<void> {
const inactiveResourceContributors =
getInactiveExtensions()
.filter(extension => getResourceContributions(extension)?.tenant?.resources);

await Promise.all(inactiveResourceContributors.map(extension => extension.activate()));
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again I really hope this isn't needed if we don't include the tenants view in the API

@@ -19,6 +19,17 @@ export async function selectSubscriptions(context: IActionContext): Promise<void

const allSubscriptions = await provider.getSubscriptions(false);

const tenantFiltedSubcriptions = getTenantFilteredSubscriptions(allSubscriptions);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spellcheck :)

@@ -19,6 +19,17 @@ export async function selectSubscriptions(context: IActionContext): Promise<void

const allSubscriptions = await provider.getSubscriptions(false);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a comment explaining what the intended behavior is here?

In what cases do we fall back and display all subscriptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intended behavior is that if no tenants are selected we would default to showing all subscriptions regardless of the tenant. At first I had it so that no subs would show but that seemed very weird to me. Not sure if you have a different opinion on that.

I'll add a comment explaining that otherwise.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I didn't want it changed, just clarify it with a comment.

@@ -73,3 +84,15 @@ export async function getSelectedTenantAndSubscriptionIds(): Promise<string[]> {
async function setSelectedTenantAndSubscriptionIds(tenantAndSubscriptionIds: string[]): Promise<void> {
await settingUtils.updateGlobalSetting('selectedSubscriptions', tenantAndSubscriptionIds);
}

export function getTenantFilteredSubscriptions(allSubscriptions: AzureSubscription[]): AzureSubscription[] | undefined {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand what this function is doing, and why it returns undefined instead an empty array. I would either refactor or make it more clear that this actually matters later on in the UI logic.

I wouldn't want someone to refactor this based on the function name and then mess things up.

package.json Show resolved Hide resolved
@@ -56,7 +56,7 @@ export class GroupingItem implements ResourceGroupsItem {
} : undefined;

if (this.context?.subscription) {
this.id = `/subscriptions/${this.context?.subscriptionContext.subscriptionId}/groupings/${this.label}`;
this.id = `/subscriptions/${this.context?.subscriptionContext.subscriptionId}/account/${this.context?.subscription.account?.id}/groupings/${this.label}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we tested reveal to make sure it still works with this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not tested it but I am pretty sure based on discussions with Nathan it would break things. I'll test it out and see.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, we'll need to sort that out before merging. I can help with that too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tested it out by creating a storage account and clicking "click to view resource" in the activity log and nothing happened so seems to be broken. Before releasing this we definitely want to fix that.

Comment on lines 57 to 60
const accounts = await vscode.authentication.getAccounts(getConfiguredAuthProviderId());
for (const account of accounts) {
const session = await vscode.authentication.getSession(getConfiguredAuthProviderId(), getScopes(undefined), { account: account });
const tenants = await this.getTenants(session);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slavizh
Copy link

slavizh commented Nov 26, 2024

One comment. Make sure it supports Lighthouse. With Lighthouse you can view the same subscriptions under different tenants. Currently it works the halfway as you can see the subscriptions twice but you can only select the same subscription once to be displayed otherwise you will get error. Also currently of course you do not know which subscription selected is under which tenant.

@motm32
Copy link
Contributor Author

motm32 commented Nov 26, 2024

One comment. Make sure it supports Lighthouse. With Lighthouse you can view the same subscriptions under different tenants. Currently it works the halfway as you can see the subscriptions twice but you can only select the same subscription once to be displayed otherwise you will get error. Also currently of course you do not know which subscription selected is under which tenant.

Hi @slavizh thanks for pointing this out! Most of these issues should be resolved by some updates we have made recently. Before we plan to release if you would like we could send you a custom build so you can try the tenants view with Lighthouse 😊


// This function is also used to filter subscription tree items in AzureResourceTreeDataProvider
export function getTenantFilteredSubscriptions(allSubscriptions: AzureSubscription[]): AzureSubscription[] | undefined {
const tenants = ext.context.globalState.get<string[]>('unselectedTenants');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhere we should store this string as a constant.

@slavizh
Copy link

slavizh commented Nov 27, 2024

@motm32 Yeah, no problem I will do some tests to verify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants