物理机密码加密传输

iida
yuemian 2024-09-03 17:30:45 +08:00
parent ed94a2bca6
commit 37b7a682fe
1 changed files with 13 additions and 0 deletions

View File

@ -15,6 +15,8 @@ import com.bocloud.ctstack.plugin.repository.VolumeRepository;
import com.bocloud.ctstack.plugin.repository.VpcRepository;
import com.bocloud.ctstack.plugin.service.PhysicalServerService;
import com.google.common.collect.Maps;
import com.megatron.common.encrypt.AESEncryptor;
import com.megatron.common.encrypt.Encryptor;
import com.megatron.common.model.GeneralResult;
import com.megatron.common.model.GridBean;
import com.megatron.common.model.Pager;
@ -24,6 +26,7 @@ import com.megatron.common.utils.GridHelper;
import com.megatron.framework.lock.AutoCloseLock;
import com.megatron.framework.lock.LockFactory;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -91,6 +94,16 @@ public class PhysicalServerServiceImpl implements PhysicalServerService {
public GeneralResult<PhysicalServer> create(PhysicalServer physicalServer, RequestContext context) {
// 云平台ID
Long vendorId = physicalServer.getVendorId();
if (!StringUtils.isEmpty(physicalServer.getPassword())) {
Encryptor encryptor = new AESEncryptor();
try {
String password = encryptor.decrypt(physicalServer.getPassword().trim(), null);
physicalServer.setPassword(password);
} catch (Exception e) {
log.error("Get error message:{}", e);
return new GeneralResult(false, e.getMessage());
}
}
String path = CloudVendor.class.getSimpleName() + "_" + vendorId + "_SYNC";
try (AutoCloseLock lock = lockFactory.getACLock(path)) {
if (!lock.acquire(10, TimeUnit.SECONDS)) {