mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Use a unique key for the accounts (#11380)
* Use a unique key for the accounts * Fix some tests * Simplify display name * Change to a random UUID
This commit is contained in:
@@ -400,7 +400,7 @@ export abstract class AzureAuth implements vscode.Disposable {
|
|||||||
|
|
||||||
const accessToken: AccessToken = {
|
const accessToken: AccessToken = {
|
||||||
token: tokenResponse.data.access_token,
|
token: tokenResponse.data.access_token,
|
||||||
key: tokenClaims.email || tokenClaims.unique_name || tokenClaims.name,
|
key: tokenClaims.oid ?? tokenClaims.email ?? tokenClaims.unique_name ?? tokenClaims.name,
|
||||||
};
|
};
|
||||||
|
|
||||||
const refreshToken: RefreshToken = {
|
const refreshToken: RefreshToken = {
|
||||||
@@ -614,7 +614,13 @@ export abstract class AzureAuth implements vscode.Disposable {
|
|||||||
accountIssuer = 'msft';
|
accountIssuer = 'msft';
|
||||||
}
|
}
|
||||||
|
|
||||||
const displayName = tokenClaims.name ?? tokenClaims.email ?? tokenClaims.unique_name;
|
const name = tokenClaims.name ?? tokenClaims.email ?? tokenClaims.unique_name;
|
||||||
|
const email = tokenClaims.email ?? tokenClaims.unique_name;
|
||||||
|
|
||||||
|
let displayName = name;
|
||||||
|
if (email) {
|
||||||
|
displayName = `${displayName} - ${email}`;
|
||||||
|
}
|
||||||
|
|
||||||
let contextualDisplayName: string;
|
let contextualDisplayName: string;
|
||||||
switch (accountIssuer) {
|
switch (accountIssuer) {
|
||||||
@@ -637,12 +643,14 @@ export abstract class AzureAuth implements vscode.Disposable {
|
|||||||
providerId: this.metadata.id,
|
providerId: this.metadata.id,
|
||||||
accountId: key
|
accountId: key
|
||||||
},
|
},
|
||||||
name: key,
|
name: displayName,
|
||||||
displayInfo: {
|
displayInfo: {
|
||||||
accountType: accountType,
|
accountType: accountType,
|
||||||
userId: key,
|
userId: key,
|
||||||
contextualDisplayName: contextualDisplayName,
|
contextualDisplayName: contextualDisplayName,
|
||||||
displayName
|
displayName,
|
||||||
|
email,
|
||||||
|
name,
|
||||||
},
|
},
|
||||||
properties: {
|
properties: {
|
||||||
providerSettings: this.metadata,
|
providerSettings: this.metadata,
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ export function registerAzureResourceCommands(appContext: AppContext, tree: Azur
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
account.isStale = true;
|
account.isStale = true;
|
||||||
throw new AzureResourceCredentialError(localize('azure.resource.selectsubscriptions.credentialError', "Failed to get credential for account {0}. Please refresh the account.", account.key.accountId), error);
|
throw new AzureResourceCredentialError(localize('azure.resource.selectsubscriptions.credentialError', "Failed to get credential for account {0}. Please refresh the account.", account.displayInfo.displayName), error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ export class AzureResourceAccountTreeNode extends AzureResourceContainerTreeNode
|
|||||||
}
|
}
|
||||||
|
|
||||||
private generateLabel(): string {
|
private generateLabel(): string {
|
||||||
let label = `${this.account.displayInfo.displayName} (${this.account.key.accountId})`;
|
let label = this.account.displayInfo.displayName;
|
||||||
|
|
||||||
if (this._totalSubscriptionCount !== 0) {
|
if (this._totalSubscriptionCount !== 0) {
|
||||||
label += ` (${this._selectedSubscriptionCount} / ${this._totalSubscriptionCount} subscriptions)`;
|
label += ` (${this._selectedSubscriptionCount} / ${this._totalSubscriptionCount} subscriptions)`;
|
||||||
|
|||||||
@@ -41,14 +41,15 @@ const mockTenantId = 'mock_tenant_id';
|
|||||||
|
|
||||||
const mockAccount: azdata.Account = {
|
const mockAccount: azdata.Account = {
|
||||||
key: {
|
key: {
|
||||||
accountId: 'mock_account',
|
accountId: '97915f6d-84fa-4926-b60c-38db64327ad7',
|
||||||
providerId: 'mock_provider'
|
providerId: 'mock_provider'
|
||||||
},
|
},
|
||||||
displayInfo: {
|
displayInfo: {
|
||||||
displayName: 'mock_account@test.com',
|
displayName: 'mock_account@test.com',
|
||||||
accountType: 'Microsoft',
|
accountType: 'Microsoft',
|
||||||
contextualDisplayName: 'test',
|
contextualDisplayName: 'test',
|
||||||
userId: 'test@email.com'
|
userId: 'test@email.com',
|
||||||
|
email: '97915f6d-84fa-4926-b60c-38db64327ad7'
|
||||||
},
|
},
|
||||||
properties: {
|
properties: {
|
||||||
tenants: [
|
tenants: [
|
||||||
@@ -120,18 +121,17 @@ describe('AzureResourceAccountTreeNode.info', function (): void {
|
|||||||
const accountTreeNode = new AzureResourceAccountTreeNode(mockAccount, mockAppContext, mockTreeChangeHandler.object);
|
const accountTreeNode = new AzureResourceAccountTreeNode(mockAccount, mockAppContext, mockTreeChangeHandler.object);
|
||||||
|
|
||||||
const accountTreeNodeId = `account_${mockAccount.key.accountId}`;
|
const accountTreeNodeId = `account_${mockAccount.key.accountId}`;
|
||||||
const accountTreeNodeLabel = `${mockAccount.displayInfo.displayName} (${mockAccount.key.accountId})`;
|
|
||||||
|
|
||||||
should(accountTreeNode.nodePathValue).equal(accountTreeNodeId);
|
should(accountTreeNode.nodePathValue).equal(accountTreeNodeId);
|
||||||
|
|
||||||
const treeItem = await accountTreeNode.getTreeItem();
|
const treeItem = await accountTreeNode.getTreeItem();
|
||||||
should(treeItem.id).equal(accountTreeNodeId);
|
should(treeItem.id).equal(accountTreeNodeId);
|
||||||
should(treeItem.label).equal(accountTreeNodeLabel);
|
should(treeItem.label).equal(mockAccount.displayInfo.displayName);
|
||||||
should(treeItem.contextValue).equal(AzureResourceItemType.account);
|
should(treeItem.contextValue).equal(AzureResourceItemType.account);
|
||||||
should(treeItem.collapsibleState).equal(vscode.TreeItemCollapsibleState.Collapsed);
|
should(treeItem.collapsibleState).equal(vscode.TreeItemCollapsibleState.Collapsed);
|
||||||
|
|
||||||
const nodeInfo = accountTreeNode.getNodeInfo();
|
const nodeInfo = accountTreeNode.getNodeInfo();
|
||||||
should(nodeInfo.label).equal(accountTreeNodeLabel);
|
should(nodeInfo.label).equal(mockAccount.displayInfo.displayName);
|
||||||
should(nodeInfo.isLeaf).false();
|
should(nodeInfo.isLeaf).false();
|
||||||
should(nodeInfo.nodeType).equal(AzureResourceItemType.account);
|
should(nodeInfo.nodeType).equal(AzureResourceItemType.account);
|
||||||
should(nodeInfo.iconType).equal(AzureResourceItemType.account);
|
should(nodeInfo.iconType).equal(AzureResourceItemType.account);
|
||||||
@@ -141,7 +141,7 @@ describe('AzureResourceAccountTreeNode.info', function (): void {
|
|||||||
mockSubscriptionService.setup((o) => o.getSubscriptions(mockAccount, mockCredential)).returns(() => Promise.resolve(mockSubscriptions));
|
mockSubscriptionService.setup((o) => o.getSubscriptions(mockAccount, mockCredential)).returns(() => Promise.resolve(mockSubscriptions));
|
||||||
mockSubscriptionFilterService.setup((o) => o.getSelectedSubscriptions(mockAccount)).returns(() => Promise.resolve(undefined));
|
mockSubscriptionFilterService.setup((o) => o.getSelectedSubscriptions(mockAccount)).returns(() => Promise.resolve(undefined));
|
||||||
|
|
||||||
const accountTreeNodeLabel = `${mockAccount.displayInfo.displayName} (${mockAccount.key.accountId}) (${mockSubscriptions.length} / ${mockSubscriptions.length} subscriptions)`;
|
const accountTreeNodeLabel = `${mockAccount.displayInfo.displayName} (${mockSubscriptions.length} / ${mockSubscriptions.length} subscriptions)`;
|
||||||
|
|
||||||
const accountTreeNode = new AzureResourceAccountTreeNode(mockAccount, mockAppContext, mockTreeChangeHandler.object);
|
const accountTreeNode = new AzureResourceAccountTreeNode(mockAccount, mockAppContext, mockTreeChangeHandler.object);
|
||||||
|
|
||||||
@@ -161,7 +161,7 @@ describe('AzureResourceAccountTreeNode.info', function (): void {
|
|||||||
mockSubscriptionService.setup((o) => o.getSubscriptions(mockAccount, mockCredential)).returns(() => Promise.resolve(mockSubscriptions));
|
mockSubscriptionService.setup((o) => o.getSubscriptions(mockAccount, mockCredential)).returns(() => Promise.resolve(mockSubscriptions));
|
||||||
mockSubscriptionFilterService.setup((o) => o.getSelectedSubscriptions(mockAccount)).returns(() => Promise.resolve(mockFilteredSubscriptions));
|
mockSubscriptionFilterService.setup((o) => o.getSelectedSubscriptions(mockAccount)).returns(() => Promise.resolve(mockFilteredSubscriptions));
|
||||||
|
|
||||||
const accountTreeNodeLabel = `${mockAccount.displayInfo.displayName} (${mockAccount.key.accountId}) (${mockFilteredSubscriptions.length} / ${mockSubscriptions.length} subscriptions)`;
|
const accountTreeNodeLabel = `${mockAccount.displayInfo.displayName} (${mockFilteredSubscriptions.length} / ${mockSubscriptions.length} subscriptions)`;
|
||||||
|
|
||||||
const accountTreeNode = new AzureResourceAccountTreeNode(mockAccount, mockAppContext, mockTreeChangeHandler.object);
|
const accountTreeNode = new AzureResourceAccountTreeNode(mockAccount, mockAppContext, mockTreeChangeHandler.object);
|
||||||
|
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ export class AccountFeature implements StaticFeature {
|
|||||||
|
|
||||||
constructor(account: azdata.Account) {
|
constructor(account: azdata.Account) {
|
||||||
this.account = account;
|
this.account = account;
|
||||||
this.label = account.key.accountId;
|
this.label = account.displayInfo.displayName;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
2
src/sql/azdata.d.ts
vendored
2
src/sql/azdata.d.ts
vendored
@@ -2160,7 +2160,7 @@ declare module 'azdata' {
|
|||||||
displayName: string;
|
displayName: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User id that identifies the account, such as "user@contoso.com".
|
* Unique user id that identifies the account.
|
||||||
*/
|
*/
|
||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
|
|||||||
6
src/sql/azdata.proposed.d.ts
vendored
6
src/sql/azdata.proposed.d.ts
vendored
@@ -484,4 +484,10 @@ declare module 'azdata' {
|
|||||||
childProvider?: string;
|
childProvider?: string;
|
||||||
type?: ExtensionNodeType;
|
type?: ExtensionNodeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AccountDisplayInfo {
|
||||||
|
email?: string;
|
||||||
|
name?: string;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,13 +71,7 @@ export class AccountPickerListRenderer implements IListRenderer<azdata.Account,
|
|||||||
templateData.icon.classList.add('account-logo', account.displayInfo.accountType);
|
templateData.icon.classList.add('account-logo', account.displayInfo.accountType);
|
||||||
|
|
||||||
templateData.contextualDisplayName.innerText = account.displayInfo.contextualDisplayName;
|
templateData.contextualDisplayName.innerText = account.displayInfo.contextualDisplayName;
|
||||||
|
|
||||||
// show the account display name text, something like "User Name (user@email.com)"
|
|
||||||
if (account.displayInfo.userId && account.displayInfo.displayName) {
|
|
||||||
templateData.displayName.innerText = account.displayInfo.displayName + ' (' + account.displayInfo.userId + ')';
|
|
||||||
} else {
|
|
||||||
templateData.displayName.innerText = account.displayInfo.displayName;
|
templateData.displayName.innerText = account.displayInfo.displayName;
|
||||||
}
|
|
||||||
|
|
||||||
if (account.isStale) {
|
if (account.isStale) {
|
||||||
templateData.badgeContent.className = 'badge-content codicon warning-badge';
|
templateData.badgeContent.className = 'badge-content codicon warning-badge';
|
||||||
|
|||||||
@@ -520,7 +520,7 @@ export class ConnectionWidget extends lifecycle.Disposable {
|
|||||||
let oldSelection = this._azureAccountDropdown.value;
|
let oldSelection = this._azureAccountDropdown.value;
|
||||||
const accounts = await this._accountManagementService.getAccounts();
|
const accounts = await this._accountManagementService.getAccounts();
|
||||||
this._azureAccountList = accounts.filter(a => a.key.providerId.startsWith('azure'));
|
this._azureAccountList = accounts.filter(a => a.key.providerId.startsWith('azure'));
|
||||||
let accountDropdownOptions = this._azureAccountList.map(account => account.key.accountId);
|
let accountDropdownOptions = this._azureAccountList.map(account => account.displayInfo.displayName);
|
||||||
if (accountDropdownOptions.length === 0) {
|
if (accountDropdownOptions.length === 0) {
|
||||||
// If there are no accounts add a blank option so that add account isn't automatically selected
|
// If there are no accounts add a blank option so that add account isn't automatically selected
|
||||||
accountDropdownOptions.unshift('');
|
accountDropdownOptions.unshift('');
|
||||||
|
|||||||
Reference in New Issue
Block a user