in manager/general/src/main/java/org/apache/doris/stack/service/config/EmailService.java [65:139]
public void updateEmailInfo(EmailInfo emailInfo) throws Exception {
log.debug("update email config.");
checkRequestBody(emailInfo.hasEmptyField());
// Check whether the current email address meets the requirements
utilService.emailCheck(emailInfo.getFromAddress());
// Check whether the current cluster has been configured
boolean configured = mailComponent.checkConfigExist();
// Store cache information
Map<String, String> configCache = new HashMap<>();
if (!configured) {
log.debug("Add new mail config.");
// Mail has not been configured before. Add mail directly
// Store in database and cache
settingComponent.addNewSetting(ConfigConstant.EMAIL_CONFIGURED_KEY, "true", configCache);
settingComponent.addNewSetting(ConfigConstant.EMAIL_HOST_KEY, emailInfo.getSmtpHost(), configCache);
settingComponent.addNewSetting(ConfigConstant.EMAIL_PORT_KEY, emailInfo.getSmtpPort(), configCache);
settingComponent.addNewSetting(ConfigConstant.EMAIL_SECURITY_KEY, emailInfo.getSmtpSecurity(), configCache);
settingComponent.addNewSetting(ConfigConstant.EMAIL_ADDRESS_KEY, emailInfo.getFromAddress(), configCache);
if (!emailInfo.getSmtpSecurity().equals(EmailInfo.SmtpSecurity.none.name())) {
settingComponent.addNewSetting(ConfigConstant.EMAIL_USER_NAME_KEY, emailInfo.getSmtpUsername(), configCache);
settingComponent.addNewSetting(ConfigConstant.EMAIL_PASSWORD_KEY, emailInfo.getSmtpPassword(), configCache);
}
} else {
log.debug("update mail config.");
// Mail has been configured before, and mail information has been modified
settingComponent.addNewSetting(ConfigConstant.EMAIL_HOST_KEY, emailInfo.getSmtpHost(), configCache);
settingComponent.addNewSetting(ConfigConstant.EMAIL_PORT_KEY, emailInfo.getSmtpPort(), configCache);
SettingEntity oldSecurity = settingComponent.readSetting(ConfigConstant.EMAIL_SECURITY_KEY);
settingComponent.addNewSetting(ConfigConstant.EMAIL_SECURITY_KEY, emailInfo.getSmtpSecurity(), configCache);
settingComponent.addNewSetting(ConfigConstant.EMAIL_ADDRESS_KEY, emailInfo.getFromAddress(), configCache);
// The two security protocols are different
if (oldSecurity != null && oldSecurity.getValue() != null
&& !oldSecurity.getValue().equals(emailInfo.getSmtpSecurity())) {
log.debug("security protocol changed.");
// If the new SMTP security protocol is none, delete the original user name and password
if (emailInfo.getSmtpSecurity().equals(EmailInfo.SmtpSecurity.none.name())) {
log.debug("delete user name and password.");
settingComponent.deleteSetting(ConfigConstant.EMAIL_USER_NAME_KEY);
settingComponent.deleteSetting(ConfigConstant.EMAIL_PASSWORD_KEY);
ConfigCache.writeConfigs(configCache);
return;
}
} else {
log.debug("security protocol not changed.");
if (oldSecurity.getValue().equals(EmailInfo.SmtpSecurity.none.name())) {
log.debug("security protocol is none, no need update user and password.");
ConfigCache.writeConfigs(configCache);
return;
}
}
// If the previous SMTP security protocol is none, add a user name and password.
// If the security protocol has not been changed and is not none, modify the user name and password
log.debug("update user and password");
settingComponent.addNewSetting(ConfigConstant.EMAIL_USER_NAME_KEY, emailInfo.getSmtpUsername(), configCache);
settingComponent.addNewSetting(ConfigConstant.EMAIL_PASSWORD_KEY, emailInfo.getSmtpPassword(), configCache);
ConfigCache.writeConfigs(configCache);
}
}