-
Notifications
You must be signed in to change notification settings - Fork 29
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
base: main
Are you sure you want to change the base?
Add Tenants view #869
Conversation
Note for later: lets update the people in this issue once this is merged - microsoft/vscode-azure-account#901 |
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
||
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())); | ||
} | ||
} |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); | |||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
@@ -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}`; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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'); |
There was a problem hiding this comment.
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.
@motm32 Yeah, no problem I will do some tests to verify. |
Completes #849
Here is how the view will look:
Detailed changes
Related to accounts:
Related to tenants:
Sign in to Tenant
. Finally if users check an unauthenticated tenant they will automatically be prompted to sign into that tenant.To do:
Sign out of Azure
code so the tenants view also gets refreshed