in src/models/connectionCredentials.ts [94:160]
public static async ensureRequiredPropertiesSet(
credentials: IConnectionInfo,
isProfile: boolean,
isPasswordRequired: boolean,
wasPasswordEmptyInConfigFile: boolean,
prompter: IPrompter,
connectionStore: ConnectionStore,
defaultProfileValues?: IConnectionInfo): Promise<IConnectionInfo> {
let questions: IQuestion[] = await ConnectionCredentials.getRequiredCredentialValuesQuestions(credentials, false,
isPasswordRequired, connectionStore, defaultProfileValues);
let unprocessedCredentials: IConnectionInfo = Object.assign({}, credentials);
// Potentially ask to save password
questions.push({
type: QuestionTypes.confirm,
name: LocalizedConstants.msgSavePassword,
message: LocalizedConstants.msgSavePassword,
shouldPrompt: (answers) => {
if (credentials.connectionString) {
return false;
}
if (isProfile) {
// For profiles, ask to save password if we are using SQL authentication and the user just entered their password for the first time
return ConnectionCredentials.isPasswordBasedCredential(credentials) &&
typeof ((<IConnectionProfile>credentials).savePassword) === 'undefined' &&
wasPasswordEmptyInConfigFile;
} else {
// For MRU list items, ask to save password if we are using SQL authentication and the user has not been asked before
return ConnectionCredentials.isPasswordBasedCredential(credentials) &&
typeof ((<IConnectionProfile>credentials).savePassword) === 'undefined';
}
},
onAnswered: (value) => {
(<IConnectionProfile>credentials).savePassword = value;
}
});
return prompter.prompt(questions).then(answers => {
if (answers) {
if (isProfile) {
let profile: IConnectionProfile = <IConnectionProfile>credentials;
// If this is a profile, and the user has set save password to true and either
// stored the password in the config file or purposefully set an empty password,
// then transfer the password to the credential store
if (profile.savePassword && (!wasPasswordEmptyInConfigFile || profile.emptyPasswordInput)) {
// Remove profile, then save profile without plain text password
connectionStore.removeProfile(profile).then(() => {
connectionStore.saveProfile(profile);
});
// Or, if the user answered any additional questions for the profile, be sure to save it
} else if (profile.authenticationType !== unprocessedCredentials.authenticationType ||
profile.savePassword !== (<IConnectionProfile>unprocessedCredentials).savePassword ||
profile.password !== unprocessedCredentials.password) {
connectionStore.removeProfile(profile).then(() => {
connectionStore.saveProfile(profile);
});
}
}
return credentials;
} else {
return undefined;
}
});
}