机器管理密钥解绑接口

This commit is contained in:
zyj 2025-06-16 09:08:12 +08:00
parent 8189a825d3
commit 6b8165028e
7 changed files with 21 additions and 21 deletions

View File

@ -44,13 +44,20 @@ public class SecretKeyController {
}
@PutMapping("/bindingMachine")
@Operation(summary = "绑定机器") //todo解绑机器
@Operation(summary = "绑定机器")
// @PreAuthorize("@ss.hasPermission('ci:secretKey:binding')")
public CommonResult<Boolean> bindingMachine(@Valid @RequestBody SecretKeyVO secretKeyVO) {
secretKeyService.bindingMachine(secretKeyVO);
return success(true);
}
@PutMapping("unbindMachine")
@Operation(summary = "解绑机器")
public CommonResult<Boolean> unbindMachine(@Valid @RequestBody SecretKeyVO secretKeyVO) {
secretKeyService.unbindMachine(secretKeyVO);
return success(true);
}
@GetMapping("/getSecretKey")
@Operation(summary = "获取机器的环境变量")
public CommonResult<SecretKeyVO> getSecretKey(@RequestParam("id") Long id) {
@ -76,6 +83,4 @@ public class SecretKeyController {
}
return success(BeanUtils.toBean(pageResult, SecretKeyVO.class));
}
}

View File

@ -35,13 +35,6 @@ public interface MachineInfoMapper extends BaseMapperX<MachineInfoDO> {
this.update(null, wrapper);
}
default void unBindingSecretKey(List<Long> secretKeyId) {
LambdaUpdateWrapper<MachineInfoDO> wrapper = new LambdaUpdateWrapper<MachineInfoDO>()
.set(MachineInfoDO::getSecretKeyId, null)
.in(MachineInfoDO::getSecretKeyId, secretKeyId);
this.update(null, wrapper);
}
default PageResult<MachineInfoDO> selectPage(MachineInfoVO machineInfoVO) {
LambdaQueryWrapperX<MachineInfoDO> machineInfoDOLambdaQueryWrapperX = new LambdaQueryWrapperX<MachineInfoDO>()
.likeIfPresent(MachineInfoDO::getName, machineInfoVO.getName())

View File

@ -17,6 +17,8 @@ import java.util.Objects;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
import static cd.casic.framework.commons.exception.util.ServiceExceptionUtil.exception;
import static cd.casic.module.machine.contants.MachineErrorCodeConstants.*;
/**
* 优化后的SSH连接会话类
*/
@ -57,7 +59,7 @@ public class ConnectionSession implements AutoCloseable {
*/
public synchronized void connect() throws JSchException {
if (status == ConnectionStatus.CONNECTED) {
log.debug("Already connected to {}", machineInfo.getHostIp());
log.debug("已经连接到 {}", machineInfo.getHostIp());
return;
}
@ -131,7 +133,7 @@ public class ConnectionSession implements AutoCloseable {
if (machineInfo.getAuthenticationType() == AuthenticationType.SECRET_KEY.getCode()) {
// 密钥认证
if (machineInfo.getSecretKeyId() == null) {
throw new JSchException("Secret key ID is required for key-based authentication");
throw exception(SECRET_KEY_NULL);
}
String privateKeyContent = getPrivateKeyContent(machineInfo.getSecretKeyId());

View File

@ -94,6 +94,4 @@ public interface MachineInfoService {
* @return 操作结果
*/
boolean downloadFile(String sessionId, String remoteFilePath, String localFilePath);
void unBindingSecretKey(List<Long> SecretKeyIds);
}

View File

@ -19,5 +19,7 @@ public interface SecretKeyService {
void deleteSecretKeyList(List<Long> ids);
SecretKeyVO getSecretKey(Long id);
void unbindMachine(@Valid SecretKeyVO secretKeyVO);
}

View File

@ -31,7 +31,7 @@ import static cd.casic.module.machine.contants.MachineErrorCodeConstants.*;
*/
@Slf4j
@Service("machineInfoService")
public class MachineinfoServiceImpl implements MachineInfoService {
public class MachineInfoServiceImpl implements MachineInfoService {
@Resource
private SecretKeyService secretKeyService;
@ -281,11 +281,6 @@ public class MachineinfoServiceImpl implements MachineInfoService {
}
}
@Override
public void unBindingSecretKey(List<Long> SecretKeyIds) {
machineInfoMapper.unBindingSecretKey(SecretKeyIds);
}
@VisibleForTesting
void validateMachineEnvAdd(MachineInfoVO machineInfoVO) {
if (machineInfoVO.getHostIp().isEmpty()) {

View File

@ -42,6 +42,11 @@ public class SecretKeyServiceImpl implements SecretKeyService {
return BeanUtils.toBean(secretKeyDO, SecretKeyVO.class);
}
@Override
public void unbindMachine(SecretKeyVO secretKeyVO) {
machineInfoService.bindingSecretKey(secretKeyVO.getMachineInfoIds(),null);
}
@Override
public Long createSecretKey(SecretKeyVO secretKeyVO) {
validateSecretKeyAdd(secretKeyVO);
@ -99,7 +104,7 @@ public class SecretKeyServiceImpl implements SecretKeyService {
);
//绑定的机器全部设置为空
machineInfoService.unBindingSecretKey(ids);
machineInfoService.bindingSecretKey(ids,null);
secretKeyMapper.deleteBatchIds(ids);
}