in src/models/connectionProfile.ts [53:124]
public static async createProfile(
prompter: IPrompter,
connectionStore: ConnectionStore,
context: vscode.ExtensionContext,
azureController: AzureController,
accountStore?: AccountStore,
defaultProfileValues?: IConnectionProfile
): Promise<IConnectionProfile> {
let profile: ConnectionProfile = new ConnectionProfile();
// Ensure all core properties are entered
let authOptions: INameValueChoice[] = ConnectionCredentials.getAuthenticationTypesChoice();
if (authOptions.length === 1) {
// Set default value as there is only 1 option
profile.authenticationType = authOptions[0].value;
}
let azureAccountChoices: INameValueChoice[] = ConnectionProfile.getAccountChoices(accountStore);
let accountAnswer: IAccount;
azureAccountChoices.unshift({ name: LocalizedConstants.azureAddAccount, value: 'addAccount' });
let questions: IQuestion[] = await ConnectionCredentials.getRequiredCredentialValuesQuestions(profile, true,
false, connectionStore, defaultProfileValues);
// Check if password needs to be saved
questions.push(
{
type: QuestionTypes.confirm,
name: LocalizedConstants.msgSavePassword,
message: LocalizedConstants.msgSavePassword,
shouldPrompt: (answers) => !profile.connectionString && ConnectionCredentials.isPasswordBasedCredential(profile),
onAnswered: (value) => profile.savePassword = value
},
{
type: QuestionTypes.expand,
name: LocalizedConstants.aad,
message: LocalizedConstants.azureChooseAccount,
choices: azureAccountChoices,
shouldPrompt: (answers) => profile.isAzureActiveDirectory(),
onAnswered: (value: IAccount) => accountAnswer = value
},
{
type: QuestionTypes.input,
name: LocalizedConstants.profileNamePrompt,
message: LocalizedConstants.profileNamePrompt,
placeHolder: LocalizedConstants.profileNamePlaceholder,
default: defaultProfileValues ? defaultProfileValues.profileName : undefined,
onAnswered: (value) => {
// Fall back to a default name if none specified
profile.profileName = value ? value : undefined;
}
});
return prompter.prompt(questions, true).then(async answers => {
if (answers.authenticationType === 'AzureMFA') {
if (answers.AAD === 'addAccount') {
profile = await azureController.getTokens(profile, accountStore, providerSettings.resources.databaseResource);
} else {
try {
profile = await azureController.refreshTokenWrapper(profile, accountStore, accountAnswer, providerSettings.resources.databaseResource);
} catch (error) {
console.log(`Refreshing tokens failed: ${error}`);
}
}
}
if (answers && profile.isValidProfile()) {
return profile;
}
// returning undefined to indicate failure to create the profile
return undefined;
});
}