protected static async getRequiredCredentialValuesQuestions()

in src/models/connectionCredentials.ts [163:253]


	protected static async getRequiredCredentialValuesQuestions(
		credentials: IConnectionInfo,
		promptForDbName: boolean,
		isPasswordRequired: boolean,
		connectionStore: ConnectionStore,
		defaultProfileValues?: IConnectionInfo): Promise<IQuestion[]> {

		let authenticationChoices: INameValueChoice[] = ConnectionCredentials.getAuthenticationTypesChoice();

		let connectionStringSet: () => boolean = () => Boolean(credentials.connectionString);

		let questions: IQuestion[] = [
			// Server or connection string must be present
			{
				type: QuestionTypes.input,
				name: LocalizedConstants.serverPrompt,
				message: LocalizedConstants.serverPrompt,
				placeHolder: LocalizedConstants.serverPlaceholder,
				default: defaultProfileValues ? defaultProfileValues.server : undefined,
				shouldPrompt: (answers) => utils.isEmpty(credentials.server),
				validate: (value) => ConnectionCredentials.validateRequiredString(LocalizedConstants.serverPrompt, value),
				onAnswered: (value) => ConnectionCredentials.processServerOrConnectionString(value, credentials)
			},
			// Database name is not required, prompt is optional
			{
				type: QuestionTypes.input,
				name: LocalizedConstants.databasePrompt,
				message: LocalizedConstants.databasePrompt,
				placeHolder: LocalizedConstants.databasePlaceholder,
				default: defaultProfileValues ? defaultProfileValues.database : undefined,
				shouldPrompt: (answers) => !connectionStringSet() && promptForDbName,
				onAnswered: (value) => credentials.database = value
			},
			// AuthenticationType is required if there is more than 1 option on this platform
			{
				type: QuestionTypes.expand,
				name: LocalizedConstants.authTypeName,
				message: LocalizedConstants.authTypePrompt,
				choices: authenticationChoices,
				shouldPrompt: (answers) => !connectionStringSet() && utils.isEmpty(credentials.authenticationType) && authenticationChoices.length > 1,
				validate: (value) => {
					if (value === utils.authTypeToString(AuthenticationTypes.Integrated)
						&& SqlToolsServerClient.instance.getServiceVersion() === 1
					) {
						return LocalizedConstants.macSierraRequiredErrorMessage;
					} else if (value === utils.authTypeToString(AuthenticationTypes.AzureMFA)) {
						return undefined;
					}
					return undefined;
				},
				onAnswered: (value) => {
					credentials.authenticationType = value;
				}
			},
			// Username must be present
			{
				type: QuestionTypes.input,
				name: LocalizedConstants.usernamePrompt,
				message: LocalizedConstants.usernamePrompt,
				placeHolder: LocalizedConstants.usernamePlaceholder,
				default: defaultProfileValues ? defaultProfileValues.user : undefined,
				shouldPrompt: (answers) => !connectionStringSet() && ConnectionCredentials.shouldPromptForUser(credentials),
				validate: (value) => ConnectionCredentials.validateRequiredString(LocalizedConstants.usernamePrompt, value),
				onAnswered: (value) => credentials.user = value
			},
			// Password may or may not be necessary
			{
				type: QuestionTypes.password,
				name: LocalizedConstants.passwordPrompt,
				message: LocalizedConstants.passwordPrompt,
				placeHolder: LocalizedConstants.passwordPlaceholder,
				shouldPrompt: (answers) => !connectionStringSet() && ConnectionCredentials.shouldPromptForPassword(credentials),
				validate: (value) => {
					if (isPasswordRequired) {
						return ConnectionCredentials.validateRequiredString(LocalizedConstants.passwordPrompt, value);
					}
					return undefined;
				},
				onAnswered: (value) => {
					if (credentials) {
						credentials.password = value;
						if (typeof ((<IConnectionProfile>credentials)) !== 'undefined') {
							(<IConnectionProfile>credentials).emptyPasswordInput = utils.isEmpty(credentials.password);
						}
					}
				},
				default: defaultProfileValues ? await connectionStore.lookupPassword(defaultProfileValues) : undefined
			}
		];
		return questions;
	}