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

Merged
merged 24 commits into from
Dec 6, 2024
Merged

Add Tenants view #869

merged 24 commits into from
Dec 6, 2024

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 Outdated 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
src/utils/getResourceContributions.ts Outdated Show resolved Hide resolved
src/tree/tenants/registerTenantTree.ts Show resolved Hide resolved
src/api/ResourceGroupsExtensionManager.ts Outdated Show resolved Hide resolved
src/commands/accounts/selectSubscriptions.ts Outdated Show resolved Hide resolved
src/commands/accounts/selectSubscriptions.ts Show resolved Hide resolved
@@ -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 Outdated 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.

Copy link
Member

Choose a reason for hiding this comment

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

Bump

@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.

alexweininger and others added 7 commits December 2, 2024 11:26
* Fixes for multi account

* Random fixes and changes

* Fixup

* Fixup unselected tenant logic (#963)

* Install latest version of auth package
@motm32
Copy link
Contributor Author

motm32 commented Dec 3, 2024

Hi @slavizh. Here is the custom vsix you can use to test Lighthouse!
ResourceGroupsArtifacts.zip

On VS Code you can open the command prompt (ctrl + shift + P) and use the command Extensions: Install from VSIX... to install this version of the Resource Groups extension. You may need to reload your window for the view to appear. If you run into any issues please file them on this repo and if you have any questions please let us know!

package.json Outdated
@@ -272,6 +290,11 @@
"name": "Workspace",
"visibility": "visible"
},
{
"id": "azureTenant",
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be clearer if we changed the id to "azureTenantsView". Along with the prefixes for the associated commands.

src/extension.ts Outdated
@@ -154,7 +173,7 @@ export async function activate(context: vscode.ExtensionContext, perfStats: { lo
azureResourceTreeDataProvider,
workspaceResourceProviderManager,
workspaceResourceBranchDataProviderManager,
workspaceResourceTreeDataProvider,
workspaceResourceTreeDataProvider
Copy link
Member

Choose a reason for hiding this comment

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

Nit: add back the comma

Comment on lines 38 to 44
children.push(new GenericItem(
localize('createAccountLabel', 'Create an Azure Account...'),
{
commandId: 'azureResourceGroups.openUrl',
commandArgs: ['https://aka.ms/VSCodeCreateAzureAccount'],
iconPath: new vscode.ThemeIcon('add')
}));
Copy link
Member

Choose a reason for hiding this comment

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

These blocks could be cleaned up.

                children.push(
                    new GenericItem(
                        localize('createAccountLabel', 'Create an Azure Account...'),
                        {
                            commandId: 'azureResourceGroups.openUrl',
                            commandArgs: ['https://aka.ms/VSCodeCreateAzureAccount'],
                            iconPath: new vscode.ThemeIcon('add')
                        }   
                    )
                );

or this could work.

                children.push(
                    new GenericItem(localize('createAccountLabel', 'Create an Azure Account...'),
                        {
                            commandId: 'azureResourceGroups.openUrl',
                            commandArgs: ['https://aka.ms/VSCodeCreateAzureAccount'],
                            iconPath: new vscode.ThemeIcon('add')
                        }
                    )
                );

@@ -32,6 +33,8 @@ export namespace ext {
// TODO: do we need this? only used by load more command
export let workspaceTree: AzExtTreeDataProvider;
export let workspaceTreeView: TreeView<unknown>;
export let tenantTree: AzExtTreeDataProvider;
Copy link
Member

Choose a reason for hiding this comment

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

We can remove this since it's for v1 backwards compatibility and we should never need that for the tenants view.

ext.actions.refreshTenantTree(node);
});

registerCommand('azureTenant.signInToTenant', async (_context, node: TenantTreeItem, account?: AuthenticationSessionAccountInformation) => {
Copy link
Member

Choose a reason for hiding this comment

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

Just following up on previous comment... here is where I think it'd be better if the command was azureTenantView.signInToTenant

import { AzureResourceTreeDataProviderBase } from "./azure/AzureResourceTreeDataProviderBase";
import { TenantResourceTreeDataProvider } from "./tenants/TenantResourceTreeDataProvider";

export async function OnGetChildrenBase(subscriptionProvider: AzureSubscriptionProvider, tdp?: AzureResourceTreeDataProvider): Promise<ResourceGroupsItem[]> {
Copy link
Member

Choose a reason for hiding this comment

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

Btw, I really like this shared approach.

return removeDuplicates(value);
}

export function isTenantFilteredOut(tenantId: string, accountId: string): boolean {
Copy link
Member

Choose a reason for hiding this comment

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

Non blocker, but we should plan to convert this to use a setting

export class TenantTreeItem implements ResourceGroupsItem {
constructor(public readonly label: string, public tenantId: string, public readonly account: vscode.AuthenticationSessionAccountInformation, private readonly options?: TenantItemOptions) {
}

Copy link
Member

Choose a reason for hiding this comment

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

Nit: maybe this was a design choice, but you could pass the whole tenant object here instead of requesting the label and tenantId here. Then you can set tenantId and label based on the tenant object in the contructor.

@@ -67,6 +67,7 @@ export class AzureResourceTreeDataProvider extends AzureResourceTreeDataProvider
return await element.getChildren();
} else {
const subscriptionProvider = await getAzureSubscriptionProvider(this);
// When a user is signed in 'OnGetChildrenBase' will return the no children
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// When a user is signed in 'OnGetChildrenBase' will return the no children
// When a user is signed in 'OnGetChildrenBase' will return no children

alexweininger
alexweininger previously approved these changes Dec 5, 2024
@slavizh
Copy link

slavizh commented Dec 5, 2024

@motm32 I did not spot any major issues but I would like to suggest some improvements:

  • When you select subscription it takes some time to display. Seems to me if that experience is faster will be better.
  • When you click on F1 select subscriptions the subscriptions takes some time to load when you have a lot of subscriptions. It will be better if this can be faster.
  • When I do F1 select tenant I have to sign in every time I choose a different tenant for the same account. Would be better if I can just sign in once and being able to switch tenants without having to sing in all over again.
  • When I do F1 select tenant and after that F1 select subscriptions regardless of the tenant chosen I see the same subscriptions. Either select tenant does not work properly or somehow it is useless as you see all subscriptions from all tenants. I cannot verify the latter with my account as I do not have subscriptions that are seen only in one of the tenants my account logs.
  • Specific to Lighthouse: The subscriptions I have access via directly on the tenant and via Lighthouse with the same account are visible only once when you do F1 select subscriptions. It is unclear to me from which access (RBAC or Lighthouse) I am viewing the subscriptions. I cannot verify as well which as from RBAC I have Owner and via Lighthouse I have contributor. May be this is related to the above issue if somehow select tenant is broken or all subscriptions are listed regarding of the tenant selected. I think it is useful to be able to see such subscriptions twice and being able to see which access you are using. For example may be there could be some grouping that shows available subscriptions per tenant in F1 select subscriptions.
  • Via Lighthouse I have access to multiple subscriptions from multiple tenants. When doing F1 select subscriptions I can see all these subscriptions but would be nice if I can somehow group the subscriptions by their tenant owner so I can easily select all subscriptions that belong to certain tenant. There is similar experience in Azure portal for Lighthouse. May be even can be done via some command like Select Subscriptions by Tenant Owner or something where you first choose the tenant owner and after that the subscriptions. Would be nice if also allows selecting multiple tenant owners before being able to select the subscriptions.

I hope this will be helpful.

@slavizh
Copy link

slavizh commented Dec 5, 2024

@motm32 ignore the last reply. I did not saw the new pane so will come back with new feedback after testing that.

@slavizh
Copy link

slavizh commented Dec 5, 2024

@motm32 My feedback after testing the accounts and tenant view:

  • Confirming that doing things like select subscriptions, selecting/deselecting tenants is slow. I have a lot of subscriptions but at the same time it feels like like I have to wait more than 15 seconds for resources pane to load after selecting/deselecting tenant. Same for subscriptions selection. Sometimes even shows loading for minutes.
  • For subscriptions for which I have access via Lighthouse and RBAC I can see them listed once when F1 select subscriptions. So I do not know which access I use to select them. From what I have tested the tenant where I am guest account and have direct access to the subscriptions via RBAC these subscriptions are missing, I can only see them via the tenant where the subscriptions are projected via Lighthouse. To verify that I have selected both tenants, selected those subscriptions, after deselecting the tenant where I have access to the subscriptions via RBAC the subscriptions disappear from Resources pane. While writing this and continue testing I noticed that sometimes also the same subscriptions appear no matter which tenant is selected. There is some inconstancy here which prevents identifying the correct behavior that is implemented.
  • When I deselect a tenant do F1 select subscriptions I see the subscriptions of the deselected tenant. That I think should not happen. Especially because when the tenant is deselected the subscriptions will not appear in Resources pane even when selected.
  • When you do F1 select subscriptions I think it is better to show the tenant name rather the tenant ID. In most cases the tenant ID does not meany anything to you but the tenant name/domain is something that is recognized.
  • I am seeing a lot of issues with selecting/deselecting tenants I deselect tenant in one account and in Resources pane the subscriptions of other account and tenant appear along the subscription of the deselected tenant stays. It is very strange.

This feedback that was from previous reply stays:

  • Specific to Lighthouse: The subscriptions I have access via directly on the tenant and via Lighthouse with the same account are visible only once when you do F1 select subscriptions. It is unclear to me from which access (RBAC or Lighthouse) I am viewing the subscriptions. I cannot verify as well which as from RBAC I have Owner and via Lighthouse I have contributor. May be this is related to the above issue if somehow select tenant is broken or all subscriptions are listed regarding of the tenant selected. I think it is useful to be able to see such subscriptions twice and being able to see which access you are using. For example may be there could be some grouping that shows available subscriptions per tenant in F1 select subscriptions.
  • Via Lighthouse I have access to multiple subscriptions from multiple tenants. When doing F1 select subscriptions I can see all these subscriptions but would be nice if I can somehow group the subscriptions by their tenant owner so I can easily select all subscriptions that belong to certain tenant. There is similar experience in Azure portal for Lighthouse. May be even can be done via some command like Select Subscriptions by Tenant Owner or something where you first choose the tenant owner and after that the subscriptions. Would be nice if also allows selecting multiple tenant owners before being able to select the subscriptions.

FYI I have over 700 subscriptions.

I hope this helps.

@motm32
Copy link
Contributor Author

motm32 commented Dec 5, 2024

@slavizh Thank you so much for your feedback it is very helpful 😊

@motm32
Copy link
Contributor Author

motm32 commented Dec 5, 2024

If possible @slavizh could you provide a number of how many tenants you had in the view? For instance were the 700 subscriptions you mentioned were belonging to one tenant or spread across multiple?

@alexweininger alexweininger merged commit 2ba8f3a into main Dec 6, 2024
3 checks passed
@alexweininger alexweininger deleted the meganmott/tenantView branch December 6, 2024 01:11
@slavizh
Copy link

slavizh commented Dec 6, 2024

@motm32 the subscriptions belong to multiple tenants because they are project via Lighthouse but I think in this case you are asking mostly if the subscriptions are seen from multiple tenants or from single one. In my case I have tenant where I have over 700 subscriptions, another tenant with 8 subscriptions. Those 8 are also seen on the other tenant via Lighthouse. These two tenants are under the same account. I also have my personal account where I have 2 subscriptions under one tenant. Over my personal account I also have 3 other tenants visible but there are no subscriptions for those.

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