mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Add more debug logging to fillInOrClearAzureToken (#10336)
* Add more debug logging to fillInOrClearAzureToken * Use toErrorMessage
This commit is contained in:
@@ -51,6 +51,7 @@ import { values } from 'vs/base/common/collections';
|
|||||||
import { assign } from 'vs/base/common/objects';
|
import { assign } from 'vs/base/common/objects';
|
||||||
import { IAdsTelemetryService } from 'sql/platform/telemetry/common/telemetry';
|
import { IAdsTelemetryService } from 'sql/platform/telemetry/common/telemetry';
|
||||||
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
|
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
|
||||||
|
import { toErrorMessage } from 'vs/base/common/errorMessage';
|
||||||
|
|
||||||
export class ConnectionManagementService extends Disposable implements IConnectionManagementService {
|
export class ConnectionManagementService extends Disposable implements IConnectionManagementService {
|
||||||
|
|
||||||
@@ -808,35 +809,46 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
let azureResource = this.getAzureResourceForConnection(connection);
|
let azureResource = this.getAzureResourceForConnection(connection);
|
||||||
let accounts = (await this._accountManagementService.getAccounts()).filter(a => a.key.providerId.startsWith('azure'));
|
const accounts = await this._accountManagementService.getAccounts();
|
||||||
if (accounts && accounts.length > 0) {
|
const azureAccounts = accounts.filter(a => a.key.providerId.startsWith('azure'));
|
||||||
|
if (azureAccounts && azureAccounts.length > 0) {
|
||||||
let accountName = (connection.authenticationType === Constants.azureMFA) ? connection.azureAccount : connection.userName;
|
let accountName = (connection.authenticationType === Constants.azureMFA) ? connection.azureAccount : connection.userName;
|
||||||
let account = find(accounts, account => account.key.accountId === accountName);
|
let account = find(azureAccounts, account => account.key.accountId === accountName);
|
||||||
if (account) {
|
if (account) {
|
||||||
|
this._logService.debug(`Getting security token for Azure account ${account.key.accountId}`);
|
||||||
if (account.isStale) {
|
if (account.isStale) {
|
||||||
|
this._logService.debug(`Account is stale - refreshing`);
|
||||||
try {
|
try {
|
||||||
account = await this._accountManagementService.refreshAccount(account);
|
account = await this._accountManagementService.refreshAccount(account);
|
||||||
} catch {
|
} catch (err) {
|
||||||
|
this._logService.info(`Exception refreshing stale account : ${toErrorMessage(err, true)}`);
|
||||||
// refreshAccount throws an error if the user cancels the dialog
|
// refreshAccount throws an error if the user cancels the dialog
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let tokensByTenant = await this._accountManagementService.getSecurityToken(account, azureResource);
|
const tokensByTenant = await this._accountManagementService.getSecurityToken(account, azureResource);
|
||||||
|
this._logService.debug(`Got tokens for tenants [${Object.keys(tokensByTenant).join(',')}]`);
|
||||||
let token: string;
|
let token: string;
|
||||||
let tenantId = connection.azureTenantId;
|
const tenantId = connection.azureTenantId;
|
||||||
if (tenantId && tokensByTenant[tenantId]) {
|
if (tenantId && tokensByTenant[tenantId]) {
|
||||||
token = tokensByTenant[tenantId].token;
|
token = tokensByTenant[tenantId].token;
|
||||||
} else {
|
} else {
|
||||||
let tokens = values(tokensByTenant);
|
this._logService.debug(`No security token found for specific tenant ${tenantId} - falling back to first one`);
|
||||||
|
const tokens = values(tokensByTenant);
|
||||||
if (tokens.length === 0) {
|
if (tokens.length === 0) {
|
||||||
|
this._logService.info(`No security tokens found for account`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
token = values(tokensByTenant)[0].token;
|
token = tokens[0].token;
|
||||||
}
|
}
|
||||||
connection.options['azureAccountToken'] = token;
|
connection.options['azureAccountToken'] = token;
|
||||||
connection.options['password'] = '';
|
connection.options['password'] = '';
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
this._logService.info(`Could not find Azure account with name ${accountName}`);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this._logService.info(`Could not find any Azure accounts from accounts : [${accounts.map(a => `${a.key.accountId} (${a.key.providerId})`).join(',')}]`);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user