use of com.orion.ops.entity.domain.MachineSecretKeyDO in project orion-ops by lijiahangmax.
the class MachineKeyServiceImpl method updateSecretKey.
@Override
@Transactional(rollbackFor = Exception.class)
public Integer updateSecretKey(MachineKeyRequest request) {
// 查询key
Long id = request.getId();
MachineSecretKeyDO beforeKey = machineSecretKeyDAO.selectById(id);
// 设置修改信息
MachineSecretKeyDO updateKey = new MachineSecretKeyDO();
updateKey.setId(id);
updateKey.setKeyName(request.getName());
updateKey.setDescription(request.getDescription());
updateKey.setUpdateTime(new Date());
String password = request.getPassword();
String fileBase64 = request.getFile();
final boolean updateKeyFile = !Strings.isBlank(fileBase64) || !Strings.isBlank(password);
if (updateKeyFile) {
// 移除原先的key
String keyPath = MachineKeyService.getKeyPath(beforeKey.getSecretKeyPath());
SessionHolder.removeIdentity(keyPath);
// 修改秘钥文件 将新秘钥保存到本地
if (!Strings.isBlank(fileBase64)) {
Files1.delete(keyPath);
String afterKeyFile = PathBuilders.getSecretKeyPath();
keyPath = MachineKeyService.getKeyPath(afterKeyFile);
Files1.touch(keyPath);
byte[] keyFileData = Base64s.decode(Strings.bytes(fileBase64));
FileWriters.writeFast(keyPath, keyFileData);
updateKey.setSecretKeyPath(afterKeyFile);
}
// 修改密码
if (!Strings.isBlank(password)) {
updateKey.setPassword(ValueMix.encrypt(password));
SessionHolder.addIdentity(keyPath, password);
}
}
// 更新
int effect = machineSecretKeyDAO.updateById(updateKey);
// 设置日志参数
EventParamsHolder.addParam(EventKeys.NAME, beforeKey.getKeyName());
EventParamsHolder.addParams(updateKey);
return effect;
}
use of com.orion.ops.entity.domain.MachineSecretKeyDO in project orion-ops by lijiahangmax.
the class MachineKeyServiceImpl method getKeyDetail.
@Override
public MachineSecretKeyVO getKeyDetail(Long id) {
MachineSecretKeyDO key = machineSecretKeyDAO.selectById(id);
Valid.notNull(key, MessageConst.UNKNOWN_DATA);
MachineSecretKeyVO vo = Converts.to(key, MachineSecretKeyVO.class);
// 设置挂载状态
String path = vo.getPath();
boolean isFile = Files1.isFile(new File(MachineKeyService.getKeyPath(path)));
if (isFile) {
vo.setMountStatus(this.getMountStatus(path));
} else {
vo.setMountStatus(MountKeyStatus.NOT_FOUND.getStatus());
}
return vo;
}
Aggregations