AzureAccountProvider & AzureAccountProviderService strict nulls (#20543)

This commit is contained in:
Charles Gagnon
2022-09-06 10:48:32 -07:00
committed by GitHub
parent 7ec3506f5f
commit 8319f89b84
3 changed files with 26 additions and 24 deletions

View File

@@ -25,7 +25,7 @@ const localize = nls.loadMessageBundle();
export class AzureAccountProvider implements azdata.AccountProvider, vscode.Disposable {
private static readonly CONFIGURATION_SECTION = 'accounts.azure.auth';
private readonly authMappings = new Map<AzureAuthType, AzureAuth>();
private initComplete: Deferred<void, Error>;
private initComplete!: Deferred<void, Error>;
private initCompletePromise: Promise<void> = new Promise<void>((resolve, reject) => this.initComplete = { resolve, reject });
constructor(
@@ -58,14 +58,15 @@ export class AzureAccountProvider implements azdata.AccountProvider, vscode.Disp
this.authMappings.clear();
const configuration = vscode.workspace.getConfiguration(AzureAccountProvider.CONFIGURATION_SECTION);
const codeGrantMethod: boolean = configuration.get('codeGrant');
const deviceCodeMethod: boolean = configuration.get('deviceCode');
const codeGrantMethod: boolean = configuration.get<boolean>('codeGrant', false);
const deviceCodeMethod: boolean = configuration.get<boolean>('deviceCode', false);
if (codeGrantMethod === true && !this.forceDeviceCode) {
this.authMappings.set(AzureAuthType.AuthCodeGrant, new AzureAuthCodeGrant(metadata, tokenCache, context, uriEventHandler));
}
if (deviceCodeMethod === true || this.forceDeviceCode) {
} else if (deviceCodeMethod === true || this.forceDeviceCode) {
this.authMappings.set(AzureAuthType.DeviceCode, new AzureDeviceCode(metadata, tokenCache, context, uriEventHandler));
} else {
console.error('No authentication methods selected');
}
}
@@ -74,12 +75,17 @@ export class AzureAccountProvider implements azdata.AccountProvider, vscode.Disp
return this.authMappings.values().next().value;
}
const authType: AzureAuthType = account?.properties?.azureAuthType;
const authType: AzureAuthType | undefined = account?.properties?.azureAuthType;
if (authType) {
return this.authMappings.get(authType);
} else {
return this.authMappings.values().next().value;
const authMapping = this.authMappings.get(authType);
if (authMapping) {
return authMapping;
}
}
if (this.authMappings.size === 0) {
throw new Error('No authentication mappings selected');
}
return this.authMappings.values().next().value;
}
initialize(storedAccounts: AzureAccount[]): Thenable<AzureAccount[]> {